Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/plugin-grpc

Package Overview
Dependencies
Maintainers
4
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/plugin-grpc - npm Package Compare versions

Comparing version 0.10.3-canary.0 to 0.11.1-alpha.48

4

build/src/grpc.d.ts

@@ -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;

47

build/src/grpc.js

@@ -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-canary.0+f4f2f84";
export declare const VERSION = "0.11.1-alpha.48+15174c6";
//# 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-canary.0+f4f2f84';
exports.VERSION = '0.11.1-alpha.48+15174c6';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/plugin-grpc",
"version": "0.10.3-canary.0+f4f2f84",
"version": "0.11.1-alpha.48+15174c6",
"description": "OpenTelemetry grpc automatic instrumentation package.",

@@ -45,10 +45,10 @@ "main": "build/src/index.js",

"devDependencies": {
"@opentelemetry/context-async-hooks": "^0.10.3-canary.0+f4f2f84",
"@opentelemetry/context-base": "^0.10.3-canary.0+f4f2f84",
"@opentelemetry/grpc-utils": "^0.10.2",
"@opentelemetry/node": "^0.10.3-canary.0+f4f2f84",
"@opentelemetry/tracing": "^0.10.3-canary.0+f4f2f84",
"@types/mocha": "8.0.0",
"@opentelemetry/context-async-hooks": "^0.11.1-alpha.48+15174c6",
"@opentelemetry/context-base": "^0.11.1-alpha.48+15174c6",
"@opentelemetry/grpc-utils": "^0.11.0",
"@opentelemetry/node": "^0.11.1-alpha.48+15174c6",
"@opentelemetry/tracing": "^0.11.1-alpha.48+15174c6",
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",
"@types/semver": "7.3.1",
"@types/semver": "7.3.2",
"@types/shimmer": "1.0.1",

@@ -64,3 +64,3 @@ "@types/sinon": "9.0.4",

"semver": "7.3.2",
"sinon": "9.0.2",
"sinon": "9.0.3",
"ts-mocha": "7.0.0",

@@ -71,8 +71,8 @@ "ts-node": "8.10.2",

"dependencies": {
"@opentelemetry/api": "^0.10.3-canary.0+f4f2f84",
"@opentelemetry/core": "^0.10.3-canary.0+f4f2f84",
"@opentelemetry/semantic-conventions": "^0.10.3-canary.0+f4f2f84",
"@opentelemetry/api": "^0.11.1-alpha.48+15174c6",
"@opentelemetry/core": "^0.11.1-alpha.48+15174c6",
"@opentelemetry/semantic-conventions": "^0.11.1-alpha.48+15174c6",
"shimmer": "^1.2.1"
},
"gitHead": "f4f2f84bc087389b3206a2e17837b7b0b95fb2f2"
"gitHead": "15174c6647ab9863dfc1424412fa60f2fddb3351"
}

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc