@opentelemetry/exporter-trace-otlp-grpc
OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector
Last updated 5 years ago by dyladan .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @opentelemetry/exporter-trace-otlp-grpc 
SYNC missed versions from official npm registry.

OpenTelemetry Collector Exporter for node with grpc

NPM Published Version Apache License

This module provides exporter for web and node to be used with opentelemetry-collector - last tested with version 0.25.0.

Installation

npm install --save @opentelemetry/exporter-trace-otlp-grpc

Service Name

The OpenTelemetry Collector Exporter does not have a service name configuration. In order to set the service name, use the service.name resource attribute as prescribed in the OpenTelemetry Resource Semantic Conventions. To see documentation and sample code for the metric exporter, see the exporter-metrics-otlp-grpc package

Traces in Node - GRPC

The OTLPTraceExporter in Node expects the URL to only be the hostname. It will not work with /v1/traces.

const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { OTLPTraceExporter } =  require('@opentelemetry/exporter-trace-otlp-grpc');

const collectorOptions = {
  // url is optional and can be omitted - default is localhost:4317
  url: '<collector-hostname>:<port>',
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

provider.register();
['SIGINT', 'SIGTERM'].forEach(signal => {
  process.on(signal, () => provider.shutdown().catch(console.error));
});

By default, plaintext connection is used. In order to use TLS in Node.js, provide credentials option like so:

const fs = require('fs');
const grpc = require('@grpc/grpc-js');

const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { OTLPTraceExporter } =  require('@opentelemetry/exporter-trace-otlp-grpc');

const collectorOptions = {
  // url is optional and can be omitted - default is localhost:4317
  url: '<collector-hostname>:<port>',
  credentials: grpc.credentials.createSsl(),
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

provider.register();
['SIGINT', 'SIGTERM'].forEach(signal => {
  process.on(signal, () => provider.shutdown().catch(console.error));
});

To use mutual authentication, pass to the createSsl() constructor:

  credentials: grpc.credentials.createSsl(
    fs.readFileSync('./ca.crt'),
    fs.readFileSync('./client.key'),
    fs.readFileSync('./client.crt')
  ),

To generate credentials for mutual authentication, you can refer to the script used to generate certificates for tests here

The exporter can be configured to send custom metadata with each request as in the example below:

const grpc = require('@grpc/grpc-js');

const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { OTLPTraceExporter } =  require('@opentelemetry/exporter-trace-otlp-grpc');

const metadata = new grpc.Metadata();
// For instance, an API key or access token might go here.
metadata.set('k', 'v');

const collectorOptions = {
  // url is optional and can be omitted - default is localhost:4317
  url: '<collector-hostname>:<port>',
  metadata, // // an optional grpc.Metadata object to be sent with each request
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

provider.register();
['SIGINT', 'SIGTERM'].forEach(signal => {
  process.on(signal, () => provider.shutdown().catch(console.error));
});

Note, that this will only work if TLS is also configured on the server.

By default no compression will be used. To use compression, set it programmatically in collectorOptions or with environment variables. Supported compression options: gzip and none.

const { CompressionAlgorithm } = require('@opentelemetry/exporter-trace-otlp-grpc');

const collectorOptions = {
  // url is optional and can be omitted - default is localhost:4317
  url: '<collector-hostname>:<port>',
  metadata, // // an optional grpc.Metadata object to be sent with each request
  compression: CompressionAlgorithm.GZIP,
};
const exporter = new OTLPTraceExporter(collectorOptions);

Providing compression with collectorOptions takes precedence and overrides compression set with environment variables.

Environment Variable Configuration

Set compression with environment variables.

OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip

Compression set programatically in collectorOptions takes precedence over compression set with environment variables. OTEL_EXPORTER_OTLP_TRACES_COMPRESSION takes precedence and overrides OTEL_EXPORTER_OTLP_COMPRESSION.

Running opentelemetry-collector locally to see the traces

  1. Go to examples/otlp-exporter-node
  2. run npm run docker:start
  3. Open page at http://localhost:9411/zipkin/ to observe the traces

Useful links

License

Apache 2.0 - See LICENSE for more information.

Current Tags

  • 0.300.0-rc.0                                ...           canary (2 months ago)
  • 0.301.0                                ...           latest (24 days ago)
  • 0.34.0                                ...           next (4 years ago)

80 Versions

  • 0.301.0                                ...           24 days ago
  • 0.300.0                                ...           a month ago
  • 0.300.0-rc.0                                ...           2 months ago
  • 0.223.0                                ...           2 months ago
  • 0.300.0-development.1                                ...           2 months ago
  • 0.300.0-development.0                                ...           2 months ago
  • 0.222.0                                ...           3 months ago
  • 0.222.0-development.0                                ...           3 months ago
  • 0.221.0                                ...           4 months ago
  • 0.220.0                                ...           5 months ago
  • 0.219.0                                ...           6 months ago
  • 0.218.0                                ...           7 months ago
  • 0.217.0                                ...           7 months ago
  • 0.216.0                                ...           7 months ago
  • 0.215.0                                ...           7 months ago
  • 0.214.0                                ...           8 months ago
  • 0.213.0                                ...           9 months ago
  • 0.212.0                                ...           10 months ago
  • 0.211.0                                ...           10 months ago
  • 0.210.0                                ...           10 months ago
  • 0.209.0                                ...           a year ago
  • 0.208.0                                ...           a year ago
  • 0.207.0                                ...           a year ago
  • 0.206.0                                ...           a year ago
  • 0.205.0                                ...           a year ago
  • 0.204.0                                ...           a year ago
  • 0.203.0                                ...           a year ago
  • 0.202.0                                ...           a year ago
  • 0.201.1                                ...           2 years ago
  • 0.201.0                                ...           2 years ago
  • 0.200.0                                ...           2 years ago
  • 0.200.0-rc.1                                ...           2 years ago
  • 0.200.0-dev.1                                ...           2 years ago
  • 0.200.0-dev.0                                ...           2 years ago
  • 0.57.2                                ...           2 years ago
  • 0.57.1                                ...           2 years ago
  • 0.57.0                                ...           2 years ago
  • 0.56.0                                ...           2 years ago
  • 0.55.0                                ...           2 years ago
  • 0.54.2                                ...           2 years ago
  • 0.54.1                                ...           2 years ago
  • 0.54.0                                ...           2 years ago
  • 0.53.0                                ...           2 years ago
  • 0.52.1                                ...           2 years ago
  • 0.52.0                                ...           2 years ago
  • 0.51.1                                ...           3 years ago
  • 0.51.0                                ...           3 years ago
  • 0.50.0                                ...           3 years ago
  • 0.49.1                                ...           3 years ago
  • 0.49.0                                ...           3 years ago
  • 0.48.0                                ...           3 years ago
  • 0.47.0                                ...           3 years ago
  • 0.46.0                                ...           3 years ago
  • 0.45.1                                ...           3 years ago
  • 0.45.0                                ...           3 years ago
  • 0.44.0                                ...           3 years ago
  • 0.43.0                                ...           3 years ago
  • 0.42.0                                ...           3 years ago
  • 0.41.2                                ...           3 years ago
  • 0.41.1                                ...           3 years ago
  • 0.41.0                                ...           3 years ago
  • 0.40.0                                ...           3 years ago
  • 0.39.1                                ...           4 years ago
  • 0.39.0                                ...           4 years ago
  • 0.38.0                                ...           4 years ago
  • 0.37.0                                ...           4 years ago
  • 0.36.1                                ...           4 years ago
  • 0.36.0                                ...           4 years ago
  • 0.35.1                                ...           4 years ago
  • 0.35.0                                ...           4 years ago
  • 0.34.0                                ...           4 years ago
  • 0.33.0                                ...           4 years ago
  • 0.32.0                                ...           4 years ago
  • 0.31.0                                ...           4 years ago
  • 0.30.0                                ...           4 years ago
  • 0.29.2                                ...           4 years ago
  • 0.29.1                                ...           4 years ago
  • 0.29.0                                ...           5 years ago
  • 0.28.0                                ...           5 years ago
  • 0.27.0                                ...           5 years ago
Maintainers (2)
Downloads
Total 250
Today 0
This Week 6
This Month 214
Last Day 2
Last Week 4
Last Month 13
Dev Dependencies (15)

© 2010 - cnpmjs.org x YWFE | Home | YWFE