
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
@opentelemetry/instrumentation-grpc
Advanced tools
OpenTelemetry instrumentation for `@grpc/grpc-js` rpc client and server for gRPC framework
@opentelemetry/instrumentation-grpc is an npm package that provides automatic instrumentation for gRPC services and clients using OpenTelemetry. This allows you to collect and export telemetry data such as traces and metrics from your gRPC-based applications, which can be used for monitoring and observability purposes.
Automatic gRPC Server Instrumentation
This code sets up automatic instrumentation for a gRPC server. It initializes the OpenTelemetry tracer provider, adds a span processor to export spans to the console, and registers the gRPC instrumentation.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
const grpcInstrumentation = new GrpcInstrumentation();
grpcInstrumentation.setTracerProvider(provider);
Automatic gRPC Client Instrumentation
This code sets up automatic instrumentation for a gRPC client. Similar to the server instrumentation, it initializes the OpenTelemetry tracer provider, adds a span processor to export spans to the console, and registers the gRPC instrumentation.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
const grpcInstrumentation = new GrpcInstrumentation();
grpcInstrumentation.setTracerProvider(provider);
@opentelemetry/instrumentation-http provides automatic instrumentation for HTTP and HTTPS modules in Node.js. It is similar to @opentelemetry/instrumentation-grpc but focuses on HTTP-based communication instead of gRPC.
@opentelemetry/instrumentation-express provides automatic instrumentation for Express.js applications. It is similar to @opentelemetry/instrumentation-grpc but is specifically designed for the Express.js framework.
@opentelemetry/instrumentation-mongodb provides automatic instrumentation for MongoDB operations. It is similar to @opentelemetry/instrumentation-grpc but focuses on MongoDB database interactions.
Note: This is an experimental package under active development. New releases may include breaking changes.
This module provides automatic instrumentation for @grpc/grpc-js
. Currently, version 1.x
of @grpc/grpc-js
is supported.
For automatic instrumentation see the @opentelemetry/sdk-trace-node package.
npm install --save @opentelemetry/instrumentation-grpc
@grpc/grpc-js
versions ^1.0.0
OpenTelemetry gRPC Instrumentation allows the user to automatically collect trace data and export them to the backend of choice, to give observability to distributed systems when working with (grpc-js).
To load a specific instrumentation (gRPC in this case), specify it in the Node Tracer's configuration.
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new NodeTracerProvider({
spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
});
provider.register();
registerInstrumentations({
instrumentations: [new GrpcInstrumentation()]
});
See examples/grpc-js for examples.
gRPC instrumentation accepts the following configuration:
Options | Type | Description |
---|---|---|
ignoreGrpcMethods | IgnoreMatcher[] | gRPC instrumentation 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. |
metadataToSpanAttributes | object | List of case insensitive metadata to convert to span attributes. Client and server (outgoing requests, incoming responses) metadata attributes will be converted to span attributes in the form of rpc.{request\response}.metadata.metadata_key , e.g. rpc.response.metadata.date |
Up to and including v0.200.0, instrumentation-grpc
generates telemetry using Semantic Conventions v1.7.0.
HTTP semantic conventions (semconv) were stabilized in v1.23.0, and a migration process was defined.
instrumentation-grpc
versions 0.201.0 and later include support for migrating to stable HTTP semantic conventions, as described below.
The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new HTTP semconv, after which a new minor version will use the new semconv by default and drop support for the old semconv.
See the HTTP semconv migration plan for OpenTelemetry JS instrumentations.
To select which semconv version(s) is emitted from this instrumentation, use the OTEL_SEMCONV_STABILITY_OPT_IN
environment variable.
http
: emit the new (stable) v1.23.0 semanticshttp/dup
: emit both the old v1.7.0 and the new (stable) v1.23.0 semanticsOTEL_SEMCONV_STABILITY_OPT_IN
includes neither of the above tokens, the old v1.7.0 semconv is used.v1.7.0 semconv | v1.23.0 semconv | Short Description |
---|---|---|
net.peer.name | server.address | Server domain name if available without reverse DNS lookup |
net.peer.port | server.port | Server port number |
Attribute | Short Description |
---|---|
rpc.method | The name of the (logical) method being called, must be equal to the $method part in the span name. |
rpc.service | The full (logical) name of the service being called, including its package name, if applicable. |
rpc.system | A string identifying the remoting system. |
When upgrading to the new semantic conventions, it is recommended to do so in the following order:
@opentelemetry/instrumentation-grpc
to the latest versionOTEL_SEMCONV_STABILITY_OPT_IN=http/dup
to emit both old and new semantic conventionsOTEL_SEMCONV_STABILITY_OPT_IN=http
to emit only the new semantic conventionsThis will cause both the old and new semantic conventions to be emitted during the transition period.
Apache 2.0 - See LICENSE for more information.
FAQs
OpenTelemetry instrumentation for `@grpc/grpc-js` rpc client and server for gRPC framework
The npm package @opentelemetry/instrumentation-grpc receives a total of 2,530,328 weekly downloads. As such, @opentelemetry/instrumentation-grpc popularity was classified as popular.
We found that @opentelemetry/instrumentation-grpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.