Repository navigation
Description
Description
TracingSDK registers configured instrumentations before creating and registering its MeterProvider.This means instrumentation metrics can silently remain disabled even after SDK initialization completes.
Confirmed by a local reproduction using @trigger.dev/core 4.7.7. The same initialization order is present in the published 4.8.5 package and current main.
Root cause
In packages/core/src/v3/otel/tracingSDK.ts, initialization happens in this order:
registerInstrumentations({
instrumentations: config.instrumentations ?? [],
tracerProvider: traceProvider,
});
// Later:
const meterProvider = new MeterProvider(/* ... */);
metrics.setGlobalMeterProvider(meterProvider);When meterProvider is omitted, registerInstrumentations() obtains the current global provider and calls each instrumentation’s setMeterProvider() with it.
In a fresh process, that is still the no-op provider. Registering the real provider later does not upgrade existing no-op meters or instruments, and TracingSDK does not subsequently rebind the instrumentations.
Reproduction and observed behavior
In a fresh process:
- Supply an instrumentation whose
setMeterProvider()creates a counter. - Initialize
TracingSDKwith that instrumentation and an in-memory metric reader. - Increment the instrumentation’s counter after initialization.
- Create and increment another counter through
metrics.getMeter()after initialization. - Collect metrics.
- Explicitly call
instrumentation.setMeterProvider(metrics.getMeterProvider()), increment its recreated counter, and collect again.
Observed results:
| Counter | Result |
|---|---|
| Instrumentation counter bound during SDK initialization | No data |
| Counter created after SDK initialization | Records successfully |
| Instrumentation counter recreated after explicit rebinding | Records successfully |
The instrumentation receives NoopMeterProvider during registration, while the global provider after initialization is MeterProvider.
This reproduction verifies local metric collection, independently of network export.
Expected behavior
Configured instrumentations should receive the real meter provider during SDK initialization and record measurements made afterward without requiring application-level rebinding.
Suggested fix
Create the meter provider before registering instrumentations and pass it explicitly:
registerInstrumentations({
instrumentations: config.instrumentations ?? [],
tracerProvider: traceProvider,
meterProvider,
});Alternatively, rebind configured instrumentations after creating the real provider.
A regression test should construct the instrumentation before SDK initialization, record a measurement afterward, and verify that a metric reader collects it.
Workaround and scope
We currently rebind affected instrumentations from the config’s init hook:
instrumentation.setMeterProvider(metrics.getMeterProvider());This report concerns configured instrumentations that support provider rebinding. Arbitrary module-level counters created before SDK initialization also remain no-ops, but cannot be repaired through this instrumentation hook.
Counters first created after SDK initialization successfully record measurements. Task-only modules loaded after telemetry setup therefore avoid this particular initialization problem.
Activity