OpenTelemetry Collector Metrics Exporter that sends collected metrics to the OpenTelemetry Collector using protobuf over HTTP
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
OpenTelemetry Collector Metrics Exporter that sends collected metrics to the OpenTelemetry Collector using protobuf over HTTP. This exporter provides platform-specific implementations for both Node.js and browser environments, extending the base OTLP HTTP metrics functionality with protobuf serialization.
Note: This is an experimental package under active development. New releases may include breaking changes.
npm install @opentelemetry/exporter-metrics-otlp-protoimport { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto";For CommonJS:
const { OTLPMetricExporter } = require("@opentelemetry/exporter-metrics-otlp-proto");import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto";
import { MeterProvider, PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
// Create exporter with configuration
const metricExporter = new OTLPMetricExporter({
url: "http://localhost:4318/v1/metrics", // Optional - defaults to localhost:4318
});
// Set up meter provider with exporter
const meterProvider = new MeterProvider({
readers: [
new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 1000,
}),
],
});
// Start recording data
const meter = meterProvider.getMeter("example-meter");
const counter = meter.createCounter("metric_name");
counter.add(10, { key: "value" });Export collected metrics to an OpenTelemetry Collector using protobuf serialization over HTTP.
class OTLPMetricExporter extends OTLPMetricExporterBase implements PushMetricExporter {
// Platform-specific constructor signatures:
// Node.js: config is optional
constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions);
// Inherited from OTLPMetricExporterBase and PushMetricExporter
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
selectAggregation(instrumentType: InstrumentType): AggregationOption;
shutdown(): Promise<void>;
forceFlush(): Promise<void>;
}The exporter accepts configuration options that combine base OTLP settings with metrics-specific options.
interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {
keepAlive?: boolean;
compression?: CompressionAlgorithm;
httpAgentOptions?: http.AgentOptions | https.AgentOptions | HttpAgentFactory;
}
interface OTLPExporterConfigBase {
headers?: Record<string, string>;
url?: string;
concurrencyLimit?: number;
timeoutMillis?: number;
}
interface OTLPMetricExporterOptions extends OTLPExporterConfigBase {
temporalityPreference?: AggregationTemporalityPreference | AggregationTemporality;
aggregationPreference?: AggregationSelector;
}
enum AggregationTemporality {
DELTA,
CUMULATIVE,
}
enum AggregationTemporalityPreference {
DELTA,
CUMULATIVE,
LOWMEMORY,
}
enum CompressionAlgorithm {
NONE = 'none',
GZIP = 'gzip',
}The exporter provides methods for selecting aggregation strategies and temporality preferences for different instrument types.
type AggregationSelector = (instrumentType: InstrumentType) => AggregationOption;
type AggregationTemporalitySelector = (instrumentType: InstrumentType) => AggregationTemporality;
enum InstrumentType {
COUNTER = 'COUNTER',
GAUGE = 'GAUGE',
HISTOGRAM = 'HISTOGRAM',
UP_DOWN_COUNTER = 'UP_DOWN_COUNTER',
OBSERVABLE_COUNTER = 'OBSERVABLE_COUNTER',
OBSERVABLE_GAUGE = 'OBSERVABLE_GAUGE',
OBSERVABLE_UP_DOWN_COUNTER = 'OBSERVABLE_UP_DOWN_COUNTER',
}
type AggregationOption =
| ExponentialHistogramAggregationOption
| HistogramAggregationOption
| SumAggregationOption
| DropAggregationOption
| DefaultAggregationOption
| LastValueAggregationOption;interface PushMetricExporter {
export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void;
forceFlush(): Promise<void>;
selectAggregationTemporality?(instrumentType: InstrumentType): AggregationTemporality;
selectAggregation?(instrumentType: InstrumentType): AggregationOption;
shutdown(): Promise<void>;
}
interface ExportResult {
code: ExportResultCode;
error?: Error;
}
enum ExportResultCode {
SUCCESS,
FAILED,
}
interface ResourceMetrics {
resource: Resource;
scopeMetrics: ScopeMetrics[];
}
interface ScopeMetrics {
scope: InstrumentationScope;
metrics: MetricData[];
}
interface Resource {
attributes: Record<string, any>;
}
interface InstrumentationScope {
name: string;
version?: string;
}
interface MetricData {
descriptor: InstrumentDescriptor;
aggregationTemporality: AggregationTemporality;
dataPointType: DataPointType;
dataPoints: DataPoint[];
}
interface InstrumentDescriptor {
readonly name: string;
readonly description?: string;
readonly unit?: string;
readonly type: InstrumentType;
readonly valueType: ValueType;
}
enum DataPointType {
SUM,
GAUGE,
HISTOGRAM,
EXPONENTIAL_HISTOGRAM,
}
enum ValueType {
INT,
DOUBLE,
}
type DataPoint = NumberDataPoint | HistogramDataPoint | ExponentialHistogramDataPoint;
interface NumberDataPoint {
attributes: MetricAttributes;
startTime: HrTime;
endTime: HrTime;
value: number;
}
interface HistogramDataPoint {
attributes: MetricAttributes;
startTime: HrTime;
endTime: HrTime;
count: number;
sum?: number;
min?: number;
max?: number;
buckets: HistogramBucket[];
}
interface ExponentialHistogramDataPoint {
attributes: MetricAttributes;
startTime: HrTime;
endTime: HrTime;
count: number;
sum?: number;
min?: number;
max?: number;
scale: number;
zeroCount: number;
positive: ExponentialHistogramBuckets;
negative: ExponentialHistogramBuckets;
}
type MetricAttributes = Record<string, any>;
type HrTime = [number, number];OTel-OTLP-Exporter-JavaScript/{VERSION}application/x-protobufapplication/x-protobufThe package provides three built-in temporality selectors:
const CumulativeTemporalitySelector: AggregationTemporalitySelector;
const DeltaTemporalitySelector: AggregationTemporalitySelector;
const LowMemoryTemporalitySelector: AggregationTemporalitySelector;Export operations may fail with various error conditions:
Failed exports are reported through the result callback with appropriate error codes and messages.
The exporter supports standard OpenTelemetry environment variables for configuration:
| Variable | Description | Default |
|---|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT | Base endpoint URL | http://localhost:4318 |
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | Metrics-specific endpoint | http://localhost:4318/v1/metrics |
The exporter extends functionality from these OpenTelemetry packages:
@opentelemetry/exporter-metrics-otlp-http: Base HTTP metrics exporter@opentelemetry/otlp-exporter-base: Common OTLP functionality@opentelemetry/otlp-transformer: Protobuf serialization@opentelemetry/sdk-metrics: Metrics SDK integrationInstall with Tessl CLI
npx tessl i tessl/npm-opentelemetry--exporter-metrics-otlp-proto