OpenTelemetry Collector Exporter for web and node
This module provides exporter for web and node to be used with opentelemetry-collector - last tested with version 0.6.0.
Installation
npm install --save @opentelemetry/exporter-collector
Traces in Web
The CollectorTraceExporter in Web expects the endpoint to end in /v1/trace
.
import { SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracerProvider } from '@opentelemetry/web';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
const collectorOptions = {
url: '<opentelemetry-collector-url>',
headers: {},
};
const provider = new WebTracerProvider();
const exporter = new CollectorTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();
Metrics in Web
The CollectorMetricExporter in Web expects the endpoint to end in /v1/metrics
.
import { MetricProvider } from '@opentelemetry/metrics';
import { CollectorMetricExporter } from '@opentelemetry/exporter-collector';
const collectorOptions = {
url: '<opentelemetry-collector-url>',
headers: {},
};
const exporter = new CollectorMetricExporter(collectorOptions);
const meter = new MeterProvider({
exporter,
interval: 60000,
}).getMeter('example-meter');
const counter = meter.createCounter('metric_name');
counter.add(10, { 'key': 'value' });
Traces in Node - JSON over http
const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const collectorOptions = {
serviceName: 'basic-service',
url: '<opentelemetry-collector-url>',
headers: {
foo: 'bar'
},
};
const provider = new BasicTracerProvider();
const exporter = new CollectorTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();
Metrics in Node
const { MeterProvider } = require('@opentelemetry/metrics');
const { CollectorMetricExporter } = require('@opentelemetry/exporter-collector');
const collectorOptions = {
serviceName: 'basic-service',
url: '<opentelemetry-collector-url>',
};
const exporter = new CollectorMetricExporter(collectorOptions);
const meter = new MeterProvider({
exporter,
interval: 60000,
}).getMeter('example-meter');
const counter = meter.createCounter('metric_name');
counter.add(10, { 'key': 'value' });
GRPC
For GRPC please check npm-url-grpc
PROTOBUF
For PROTOBUF please check npm-url-proto
Running opentelemetry-collector locally to see the traces
- Go to examples/collector-exporter-node
- run
npm run docker:start
- Open page at
http://localhost:9411/zipkin/
to observe the traces
Useful links
License
Apache 2.0 - See LICENSE for more information.