Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@opentelemetry/exporter-metrics-otlp-http
Advanced tools
OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector
@opentelemetry/exporter-metrics-otlp-http is an npm package that allows you to export OpenTelemetry metrics data using the OTLP (OpenTelemetry Protocol) over HTTP. This package is part of the OpenTelemetry project, which provides a set of APIs, libraries, agents, and instrumentation to enable observability in your applications.
Export Metrics
This feature allows you to export metrics data to an OTLP endpoint over HTTP. The code sample demonstrates how to set up a MeterProvider with an OTLPMetricExporter and create a counter metric that is incremented every second.
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http');
const exporter = new OTLPMetricExporter({
url: 'http://localhost:4318/v1/metrics',
});
const meterProvider = new MeterProvider({
exporter,
interval: 2000,
});
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('example_counter');
setInterval(() => {
counter.add(1, { key: 'value' });
}, 1000);
@opentelemetry/exporter-collector is a more general exporter that can send both traces and metrics to the OpenTelemetry Collector using the OTLP protocol. It supports both gRPC and HTTP transports, making it more versatile compared to @opentelemetry/exporter-metrics-otlp-http, which is focused solely on metrics over HTTP.
@opentelemetry/exporter-zipkin is an exporter that sends OpenTelemetry trace data to a Zipkin backend. While it focuses on trace data rather than metrics, it provides a similar function of exporting observability data to a backend system. It uses the Zipkin format over HTTP.
This module provides exporter for web and node to be used with opentelemetry-collector.
Compatible with opentelemetry-collector versions >=0.48 <=0.50
.
npm install --save @opentelemetry/exporter-metrics-otlp-http
The OpenTelemetry Collector Metrics 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 sample code and documentation for the traces exporter, visit the Collector Trace Exporter for web and node.
The OTLPMetricExporter in Web expects the endpoint to end in /v1/metrics
.
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics-base';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
const collectorOptions = {
url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics
headers: {}, // an optional object containing custom headers to be sent with each request
concurrencyLimit: 1, // an optional limit on pending requests
};
const exporter = new OTLPMetricExporter(collectorOptions);
const meterProvider = new MeterProvider({});
meterProvider.addMetricReader(new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 1000,
}));
// Now, start recording data
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('metric_name');
counter.add(10, { 'key': 'value' });
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics-base');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http');
const collectorOptions = {
url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/metrics
concurrencyLimit: 1, // an optional limit on pending requests
};
const exporter = new OTLPMetricExporter(collectorOptions);
const meterProvider = new MeterProvider({});
meterProvider.addMetricReader(new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 1000,
}));
// Now, start recording data
const meter = meterProvider.getMeter('example-meter');
const counter = meter.createCounter('metric_name');
counter.add(10, { 'key': 'value' });
For exporting metrics with GRPC please check exporter-metrics-otlp-grpc
For exporting metrics with PROTOBUF please check exporter-metrics-otlp-proto
Instead of providing options to OTLPMetricExporter
and OTLPTraceExporter
explicitly, environment variables may be provided instead.
OTEL_EXPORTER_OTLP_ENDPOINT=https://localhost:4318
# this will automatically append the version and signal path
# e.g. https://localhost:4318/v1/traces for `OTLPTraceExporter` and https://localhost:4318/v1/metrics for `OTLPMetricExporter`
If the trace and metric exporter endpoints have different providers, the env var for per-signal endpoints are available to use
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://trace-service:4318/v1/traces
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://metric-service:4318/v1/metrics
# version and signal needs to be explicit
The per-signal endpoints take precedence and overrides
OTEL_EXPORTER_OTLP_ENDPOINT
For more details, see OpenTelemetry Specification on Protocol Exporter.
examples/otlp-exporter-node
Apache 2.0 - See LICENSE for more information.
FAQs
OpenTelemetry Collector Metrics Exporter allows user to send collected metrics to the OpenTelemetry Collector
The npm package @opentelemetry/exporter-metrics-otlp-http receives a total of 741,627 weekly downloads. As such, @opentelemetry/exporter-metrics-otlp-http popularity was classified as popular.
We found that @opentelemetry/exporter-metrics-otlp-http demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.