@opentelemetry/plugin-grpc
Advanced tools
Comparing version 0.10.3-alpha.28 to 0.10.3-alpha.34
@@ -19,2 +19,6 @@ import { BasePlugin } from '@opentelemetry/core'; | ||
private _patchServer; | ||
/** | ||
* Returns true if the server call should not be traced. | ||
*/ | ||
private _shouldNotTraceServerCall; | ||
private _clientStreamAndUnaryHandler; | ||
@@ -21,0 +25,0 @@ private _serverStreamAndBidiHandler; |
@@ -79,2 +79,14 @@ "use strict"; | ||
const self = this; | ||
if (plugin._shouldNotTraceServerCall(call, name)) { | ||
switch (type) { | ||
case 'unary': | ||
case 'client_stream': | ||
return originalFunc.call(self, call, callback); | ||
case 'server_stream': | ||
case 'bidi': | ||
return originalFunc.call(self, call); | ||
default: | ||
return originalResult; | ||
} | ||
} | ||
const spanName = `grpc.${name.replace('/', '')}`; | ||
@@ -110,2 +122,10 @@ const spanOptions = { | ||
} | ||
/** | ||
* Returns true if the server call should not be traced. | ||
*/ | ||
_shouldNotTraceServerCall(call, name) { | ||
const parsedName = name.split('/'); | ||
return (utils_1._containsOtelMetadata(call.metadata) || | ||
utils_1._methodIsIgnored(parsedName[parsedName.length - 1] || name, this._config.ignoreGrpcMethods)); | ||
} | ||
_clientStreamAndUnaryHandler(plugin, span, call, callback, original, self) { | ||
@@ -185,10 +205,12 @@ function patchedCallback(err, value, trailer, flags) { | ||
Object.entries(methods).forEach(([name, { originalName }]) => { | ||
methodList.push(name); // adds camel case method name: "unaryMethod" | ||
if (originalName && | ||
// eslint-disable-next-line no-prototype-builtins | ||
client.prototype.hasOwnProperty(originalName) && | ||
name !== originalName // do not add duplicates | ||
) { | ||
// adds original method name: "UnaryMethod", | ||
methodList.push(originalName); | ||
if (!utils_1._methodIsIgnored(name, this._config.ignoreGrpcMethods)) { | ||
methodList.push(name); // adds camel case method name: "unaryMethod" | ||
if (originalName && | ||
// eslint-disable-next-line no-prototype-builtins | ||
client.prototype.hasOwnProperty(originalName) && | ||
name !== originalName // do not add duplicates | ||
) { | ||
// adds original method name: "UnaryMethod", | ||
methodList.push(originalName); | ||
} | ||
} | ||
@@ -205,6 +227,10 @@ }); | ||
const args = Array.prototype.slice.call(arguments); | ||
const metadata = plugin._getMetadata(original, args); | ||
if (utils_1._containsOtelMetadata(metadata)) { | ||
return original.apply(this, args); | ||
} | ||
const span = plugin._tracer.startSpan(name, { | ||
kind: api_1.SpanKind.CLIENT, | ||
}); | ||
return plugin._tracer.withSpan(span, () => plugin._makeGrpcClientRemoteCall(original, args, this, plugin)(span)); | ||
return plugin._tracer.withSpan(span, () => plugin._makeGrpcClientRemoteCall(original, args, metadata, this, plugin)(span)); | ||
}; | ||
@@ -216,3 +242,3 @@ }; | ||
*/ | ||
_makeGrpcClientRemoteCall(original, args, self, plugin) { | ||
_makeGrpcClientRemoteCall(original, args, metadata, self, plugin) { | ||
/** | ||
@@ -247,3 +273,2 @@ * Patches a callback so that the current span for this trace is also ended | ||
} | ||
const metadata = this._getMetadata(original, args); | ||
// if unary or clientStream | ||
@@ -250,0 +275,0 @@ if (!original.responseStream) { |
/// <reference types="node" /> | ||
import * as grpcModule from 'grpc'; | ||
import * as events from 'events'; | ||
import { PluginConfig } from '@opentelemetry/api'; | ||
export declare type grpc = typeof grpcModule; | ||
export declare type IgnoreMatcher = string | RegExp | ((str: string) => boolean); | ||
export declare type SendUnaryDataCallback = (error: grpcModule.ServiceError | null, value?: any, trailer?: grpcModule.Metadata, flags?: grpcModule.writeFlags) => void; | ||
export interface GrpcPluginOptions { | ||
export interface GrpcPluginOptions extends PluginConfig { | ||
ignoreGrpcMethods?: IgnoreMatcher[]; | ||
} | ||
@@ -8,0 +11,0 @@ interface GrpcStatus { |
import { CanonicalCode, Status } from '@opentelemetry/api'; | ||
import * as grpcTypes from 'grpc'; | ||
import { IgnoreMatcher } from './types'; | ||
export declare const findIndex: <T>(args: T[], fn: (arg: T) => boolean) => number; | ||
@@ -10,2 +11,15 @@ /** | ||
export declare const _grpcStatusCodeToSpanStatus: (status: number) => Status; | ||
/** | ||
* Returns true if the metadata contains | ||
* the opentelemetry outgoing request header. | ||
*/ | ||
export declare const _containsOtelMetadata: (metadata: grpcTypes.Metadata) => boolean; | ||
/** | ||
* Returns true if the current plugin configuration | ||
* ignores the given method. | ||
* @param methodName the name of the method | ||
* @param ignoredMethods a list of matching patterns | ||
* @param onException an error handler for matching exceptions | ||
*/ | ||
export declare const _methodIsIgnored: (methodName: string, ignoredMethods?: IgnoreMatcher[] | undefined) => boolean; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -18,4 +18,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._grpcStatusCodeToSpanStatus = exports._grpcStatusCodeToCanonicalCode = exports.findIndex = void 0; | ||
exports._methodIsIgnored = exports._containsOtelMetadata = exports._grpcStatusCodeToSpanStatus = exports._grpcStatusCodeToCanonicalCode = exports.findIndex = void 0; | ||
const api_1 = require("@opentelemetry/api"); | ||
/** | ||
* Metadata key used to denote an outgoing opentelemetry request. | ||
*/ | ||
const _otRequestHeader = 'x-opentelemetry-outgoing-request'; | ||
// Equivalent to lodash _.findIndex | ||
@@ -45,2 +49,47 @@ exports.findIndex = (args, fn) => { | ||
}; | ||
/** | ||
* Returns true if the metadata contains | ||
* the opentelemetry outgoing request header. | ||
*/ | ||
exports._containsOtelMetadata = (metadata) => { | ||
return metadata.get(_otRequestHeader).length > 0; | ||
}; | ||
/** | ||
* Returns true if methodName matches pattern | ||
* @param methodName the name of the method | ||
* @param pattern Match pattern | ||
*/ | ||
const _satisfiesPattern = (methodName, pattern) => { | ||
if (typeof pattern === 'string') { | ||
return pattern.toLowerCase() === methodName.toLowerCase(); | ||
} | ||
else if (pattern instanceof RegExp) { | ||
return pattern.test(methodName); | ||
} | ||
else if (typeof pattern === 'function') { | ||
return pattern(methodName); | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Returns true if the current plugin configuration | ||
* ignores the given method. | ||
* @param methodName the name of the method | ||
* @param ignoredMethods a list of matching patterns | ||
* @param onException an error handler for matching exceptions | ||
*/ | ||
exports._methodIsIgnored = (methodName, ignoredMethods) => { | ||
if (!ignoredMethods) { | ||
// No ignored gRPC methods | ||
return false; | ||
} | ||
for (const pattern of ignoredMethods) { | ||
if (_satisfiesPattern(methodName, pattern)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
//# sourceMappingURL=utils.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.10.3-alpha.28+d68ff0f"; | ||
export declare const VERSION = "0.10.3-alpha.34+fb06b5b"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.10.3-alpha.28+d68ff0f'; | ||
exports.VERSION = '0.10.3-alpha.34+fb06b5b'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/plugin-grpc", | ||
"version": "0.10.3-alpha.28+d68ff0f", | ||
"version": "0.10.3-alpha.34+fb06b5b", | ||
"description": "OpenTelemetry grpc automatic instrumentation package.", | ||
@@ -48,4 +48,4 @@ "main": "build/src/index.js", | ||
"@opentelemetry/grpc-utils": "^0.10.2", | ||
"@opentelemetry/node": "^0.10.3-alpha.28+d68ff0f", | ||
"@opentelemetry/tracing": "^0.10.3-alpha.28+d68ff0f", | ||
"@opentelemetry/node": "^0.10.3-alpha.34+fb06b5b", | ||
"@opentelemetry/tracing": "^0.10.3-alpha.34+fb06b5b", | ||
"@types/mocha": "8.0.2", | ||
@@ -70,8 +70,8 @@ "@types/node": "14.0.27", | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.10.2", | ||
"@opentelemetry/core": "^0.10.2", | ||
"@opentelemetry/api": "^0.10.3-alpha.34+fb06b5b", | ||
"@opentelemetry/core": "^0.10.3-alpha.34+fb06b5b", | ||
"@opentelemetry/semantic-conventions": "^0.10.2", | ||
"shimmer": "^1.2.1" | ||
}, | ||
"gitHead": "d68ff0fb7594f6a367cb7a5057cfb2875e8c082f" | ||
"gitHead": "fb06b5bb1142286acf5b326925f3af3353aa9d90" | ||
} |
@@ -35,2 +35,3 @@ # OpenTelemetry gRPC Instrumentation for Node.js | ||
path: '@opentelemetry/plugin-grpc', | ||
// gRPC plugin options | ||
} | ||
@@ -51,2 +52,10 @@ } | ||
### gRPC Plugin Options | ||
gRPC plugin accepts the following configuration: | ||
| Options | Type | Description | | ||
| ------- | ---- | ----------- | | ||
| [`ignoreGrpcMethods`](https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-plugin-grpc/src/types.ts#L32) | `IgnoreMatcher[]` | gRPC plugin will not trace any methods that match anything in this list. You may pass a string (case-insensitive match), a `RegExp` object, or a filter function. | | ||
## Useful links | ||
@@ -53,0 +62,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
57295
618
79
+ Added@opentelemetry/api@0.10.3-canary.0(transitive)
+ Added@opentelemetry/context-base@0.10.3-canary.0(transitive)
+ Added@opentelemetry/core@0.10.3-canary.0(transitive)
- Removed@opentelemetry/api@0.10.2(transitive)
- Removed@opentelemetry/context-base@0.10.2(transitive)
- Removed@opentelemetry/core@0.10.2(transitive)