What is @opentelemetry/otlp-grpc-exporter-base?
@opentelemetry/otlp-grpc-exporter-base is a base package for OpenTelemetry that provides functionality to export telemetry data (traces and metrics) using the gRPC protocol. It is designed to be extended by other packages to provide specific implementations for different telemetry data types.
What are @opentelemetry/otlp-grpc-exporter-base's main functionalities?
Exporting Traces
This code demonstrates how to set up a trace exporter using the OTLP gRPC protocol. It initializes a NodeTracerProvider, sets up an OTLPTraceExporter with a specified URL, and registers a SimpleSpanProcessor to handle the spans.
const { OTLPTraceExporter } = require('@opentelemetry/otlp-grpc-exporter-base');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const provider = new NodeTracerProvider();
const exporter = new OTLPTraceExporter({
url: 'http://localhost:4317',
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();
const tracer = provider.getTracer('example-tracer');
const span = tracer.startSpan('example-span');
span.end();
Exporting Metrics
This code demonstrates how to set up a metric exporter using the OTLP gRPC protocol. It initializes a MeterProvider, sets up an OTLPMetricExporter with a specified URL, and creates a counter metric to be exported.
const { OTLPMetricExporter } = require('@opentelemetry/otlp-grpc-exporter-base');
const { MeterProvider } = require('@opentelemetry/metrics');
const meterProvider = new MeterProvider();
const exporter = new OTLPMetricExporter({
url: 'http://localhost:4317',
});
meterProvider.addMetricReader(exporter);
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('example_counter');
counter.add(10, { key: 'value' });
Other packages similar to @opentelemetry/otlp-grpc-exporter-base
@opentelemetry/exporter-collector-grpc
This package provides an exporter for sending telemetry data to the OpenTelemetry Collector using the gRPC protocol. It is similar to @opentelemetry/otlp-grpc-exporter-base but is more specific to the OpenTelemetry Collector.
@opentelemetry/exporter-zipkin
This package provides an exporter for sending trace data to Zipkin. While it also deals with exporting telemetry data, it uses the Zipkin format and HTTP protocol instead of OTLP and gRPC.
@opentelemetry/exporter-prometheus
This package provides an exporter for exposing metrics in a format that can be scraped by Prometheus. It is focused on metrics and uses the Prometheus exposition format, differing from the gRPC-based OTLP exporter.
OpenTelemetry Collector Exporter for node with grpc
This module provides a gRPC exporter base for Node.js (browsers not supported) to be used with opentelemetry-collector.
Installation
npm install --save @opentelemetry/otlp-grpc-exporter-base
Useful links
License
Apache 2.0 - See LICENSE for more information.