Skip to content

OTel metrics adapter

OpenTelemetry is the vendor-neutral standard for observability data. The OtelMetricsAdapter mirrors framework metrics into an OTel Meter — pipe through OTel’s exporters (OTLP, Datadog, Grafana Cloud, Honeycomb, New Relic, etc.) without touching the framework’s metrics API.

import { metrics as otelMetrics } from '@opentelemetry/api';
import { MeterProvider } from '@opentelemetry/sdk-metrics';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { ActorSystem, MetricsExtensionId, OtelMetricsAdapter } from 'actor-ts';
// 1. Set up OTel SDK
const meterProvider = new MeterProvider({
readers: [new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({
url: 'https://otel-collector.example.com/v1/metrics',
}),
exportIntervalMillis: 10_000,
})],
});
otelMetrics.setGlobalMeterProvider(meterProvider);
// 2. Wire the adapter
const system = ActorSystem.create('my-app');
const metrics = system.extension(MetricsExtensionId);
const adapter = new OtelMetricsAdapter({
source: metrics.registry,
meter: otelMetrics.getMeter('actor-ts'),
});
adapter.start();

The OTel SDK handles exporting; the framework just emits to its registry as usual.

interface OtelMetricsAdapterSettings {
source: MetricsRegistry;
meter: Meter; // from @opentelemetry/api
syncIntervalMs?: number; // default 5000
prefix?: string;
}

Same shape as the prom-client adapter — a source registry, a target SDK component, configurable sync interval.

Framework typeOTel instrument
CounterCounter
GaugeObservableGauge
HistogramHistogram
TimerHistogram

Labels become OTel attributes. Bucket boundaries propagate for histograms.

Terminal window
npm install @opentelemetry/api @opentelemetry/sdk-metrics
# Plus an exporter:
npm install @opentelemetry/exporter-metrics-otlp-http
# or @opentelemetry/exporter-prometheus, etc.

The framework doesn’t bundle OTel packages — bring your own SDK + exporter combo.

Use OTel when…Use Prometheus exporter when…
Targeting Datadog / New Relic / Grafana Cloud / HoneycombTargeting self-hosted Prometheus
Mixing metrics, traces, logs into one OTel pipelineMetrics-only setups
Pushing metrics out (no scrape)Pull-based scraping

OTel is the flexible path — your backend can change without rewiring instrumentation. Prometheus exporter is the simpler path when your backend is just Prometheus.

const tracer = otelMetrics.getMeter('actor-ts');
// + the tracing adapter:
const tracerAdapter = new OtelTracerAdapter({
tracer: otelTrace.getTracer('actor-ts'),
});

Both adapters share the OTel SDK setup — metrics and traces flow through the same OTel exporter pipeline, correlated by the OTel context.

See OTel tracing adapter.