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 SDKconst 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 adapterconst 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.
Configuration
Section titled “Configuration”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.
Type mapping
Section titled “Type mapping”| Framework type | OTel instrument |
|---|---|
| Counter | Counter |
| Gauge | ObservableGauge |
| Histogram | Histogram |
| Timer | Histogram |
Labels become OTel attributes. Bucket boundaries propagate for histograms.
Peer dependencies
Section titled “Peer dependencies”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.
When to use OTel vs Prometheus exporter
Section titled “When to use OTel vs Prometheus exporter”| Use OTel when… | Use Prometheus exporter when… |
|---|---|
| Targeting Datadog / New Relic / Grafana Cloud / Honeycomb | Targeting self-hosted Prometheus |
| Mixing metrics, traces, logs into one OTel pipeline | Metrics-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.
Combining with tracing
Section titled “Combining with tracing”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.
Where to next
Section titled “Where to next”- Observability overview — the bigger picture.
- Core metrics — what gets mirrored.
- OTel tracing adapter — the companion for traces.
- Prometheus exporter — the simpler alternative when you only need Prometheus.