npm.io
0.26.0 • Published 5 years ago

@opentelemetry/exporter-otlp-proto

Licence
Apache-2.0
Version
0.26.0
Deps
7
Size
113 kB
Vulns
12
Weekly
0
Stars
3.5K
DeprecatedThis package is deprecated

OpenTelemetry Collector Exporter for node with protobuf

NPM Published Version dependencies devDependencies Apache License

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

Installation

npm install --save @opentelemetry/exporter-otlp-proto

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.

Traces in Node - PROTO over http

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

const collectorOptions = {
  url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55681/v1/traces
  headers: {
    foo: 'bar'
  }, //an optional object containing custom headers to be sent with each request will only work with http
};

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

provider.register();

Metrics in Node - PROTO over http

const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } =  require('@opentelemetry/exporter-otlp-proto');
const collectorOptions = {
  url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55681/v1/metrics
};
const exporter = new OTLPMetricExporter(collectorOptions);

// Register the exporter
const meter = new MeterProvider({
  exporter,
  interval: 60000,
}).getMeter('example-meter');

// Now, start recording data
const counter = meter.createCounter('metric_name');
counter.add(10, { 'key': 'value' });

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

License

Apache 2.0 - See LICENSE for more information.

Keywords