Repository navigation
fix(diagnostics-otel): own the tracer and meter providers instead of the global ones - #237
Conversation
…the global ones
A gateway that also loads an SDK which registers a global OpenTelemetry
tracer provider silences this plugin entirely. Global registration is
first-writer-wins, so when @sentry/node gets there first — sentry-monitor
calls Sentry.init(), which sets up its own OpenTelemetry layer — the
plugin's trace.getTracer("openclaw") returns Sentry's tracer, every span
is dropped at its tracesSampleRate of 0, and nothing is ever exported. No
error is logged on either side.
The plugin now builds its own BasicTracerProvider and MeterProvider and
reads the tracer/meter off them. It still falls back to the global API
under OPENCLAW_OTEL_PRELOADED=1, where a host process deliberately owns
the SDK.
Dropping NodeSDK also removes its env-driven fallbacks: with metrics
disabled the plugin no longer creates a metric reader from
OTEL_METRICS_EXPORTER defaults, which had it POSTing to
localhost:4318/v1/metrics on a traces-only collector. Resource detectors
(env/host/os/process) are now wired explicitly so spans keep host.name
and process.* attributes NodeSDK used to add.
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…dependency The plugin builds its own tracer and meter providers, so NodeSDK is gone from the source. The extension-runtime-dependencies contract fails on a declared dependency no runtime file mentions, and it is right to: the package pulled 173 transitive entries into npm-shrinkwrap.json, including the gRPC, Zipkin and Prometheus exporters this plugin never used.
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
…detected resource Review follow-ups on #237: - The meter still fell back to the global MeterProvider whenever metrics were disabled, and the event handlers record instruments unconditionally, so a co-running SDK's provider would have collected them. The plugin now always builds its own MeterProvider (readerless when metrics are off) unless OPENCLAW_OTEL_PRELOADED says a host process owns the SDK. - The resources module was mocked to empty objects, so nothing tested the guarantee that host.name and process.* still reach spans now that NodeSDK no longer runs the detectors. The mocks return detector attributes and a new test asserts the provider gets them alongside service.name. - Trimmed the tracer-ownership comment to the invariant.
augusteo
left a comment
There was a problem hiding this comment.
Reviewed the complete three-dot range f0e3a1f..e8b4fb7. The provider ownership fix is correct: the plugin owns tracer and meter providers, preserves the preloaded global-provider exception, and restores the NodeSDK resource detectors needed for host/process identity. The sdk-node removal and regenerated lockfiles also pass the dependency and plugin-contract checks.
Exact-head verification is green: CI and OpenGrep passed, with build, lint, test types, shrinkwrap, dependency, security, and plugin-contract checks successful. Approving this head. This approval does not merge, release boon.46, or roll the fleet.
…238) Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated, CHANGELOG section for boon.46. Shipping: #237 (diagnostics-otel owns its tracer and meter providers instead of the global ones, so it stops handing spans to a co-running SDK), #235 (model.usage stays inside the turn trace), #233 (a plugin's scheduled turn is no longer rolled back by an unrelated registry becoming active), #229 (browser-handoff recheck scheduling failure is logged), #212 (dev-only vitest bump in ui). Base = 2026.6.11-boon.45. Gateway plus @openclaw/slack, @openclaw/msteams and @openclaw/diagnostics-prometheus bumped in lockstep; no separately published plugin source changed in this train, so a gateway roll delivers all of it.
What Problem This Solves
diagnostics-otelexports nothing on a gateway that also runs another OpenTelemetry SDK, and it fails silently.The plugin read its tracer off the global API (
trace.getTracer("openclaw")). Global provider registration is first-writer-wins: whoever registers first owns it, and a laterNodeSDK.start()cannot replace it. On our fleetsentry-monitorcallsSentry.init(), and@sentry/nodesets up its own OpenTelemetry layer, so the plugin's spans were created by Sentry's tracer and dropped at itstracesSampleRate: 0. Nothing was logged on either side — the plugin reported healthy,plugins inspectshowed the bundled copy loaded, and Tempo stayed empty.Measured on the Boon fleet after the exporter itself was repaired (all 65 running hosts on
boon.45, bundled origin, no capability warning):sentry-monitoris inactive for lack of a DSN.POST /v1/traces. The only OTLP traffic wasPOST /v1/metrics→404.otelcol.*components were healthy, so transport, credentials and the collector were never the problem.The stray
/v1/metricstraffic is the second half of the same root cause: withdiagnostics.otel.metrics: falsethe plugin passed nometricReader, andNodeSDKthen built one fromOTEL_METRICS_EXPORTERdefaults and shipped metrics tolocalhost:4318/v1/metricson a traces-only collector.Why This Change Was Made
The plugin now owns its providers rather than borrowing the process's:
BasicTracerProviderandMeterProviderare constructed with the plugin's resource, sampler and processors, and the tracer and meter come from them. Neither is registered globally, so the plugin and any other SDK coexist instead of overwriting each other.NodeSDKis gone, which removes its env-driven fallbacks — no metric reader is created when metrics are disabled.env,host,os,process) are wired explicitly, becauseNodeSDKused to supply them and spans needhost.nameandprocess.*to tell two gateways apart.OPENCLAW_OTEL_PRELOADED=1still reads the tracer and meter off the global API. That flag exists precisely to say a host process owns the SDK on purpose.User Impact
Traces start flowing on every gateway that runs both the Sentry plugin and the OTLP exporter, which on our fleet is 64 of 65 hosts. No configuration changes: same
diagnostics.otelkeys, same endpoints, same sampling. Spans gain nothing and lose nothing in shape; the resource attributes thatNodeSDKused to attach are preserved. Collectors that only accept traces stop receiving unrequested metric posts.Evidence
Live reproduction against the real service (unmocked OTel, fleet config:
traces: true,metrics: false,sampleRate: 0.5), with a local OTLP receiver and three synthetic turn events:POST /v1/traces 1225BPOST /v1/traces 1405BNONEPOST /v1/traces 1511BThe larger payload after the change is the explicitly detected host/process resource attributes.
Tests:
extensions/diagnostics-otel/src/service.test.ts, 98 passed. Two are new and encode the defect — one asserts the plugin builds its own provider and never calls the globalgetTracer, the other asserts it does use the global one underOPENCLAW_OTEL_PRELOADED=1.tsgo --noEmitreports two errors insrc/config/io.tsandsrc/secrets/config-io.ts. Both files are untouched by this PR and unmodified in the working tree, so they are pre-existing onboon(f0e3a1f).@opentelemetry/sdk-nodeis removed from the root and plugin manifests in the second commit. Theextension-runtime-dependenciescontract fails on a declared dependency no runtime file mentions, and the package was carrying 173 transitive entries innpm-shrinkwrap.json— the gRPC, Zipkin and Prometheus exporters among them — none of which this plugin ever used.pnpm-lock.yamlandnpm-shrinkwrap.jsonare regenerated; the plugin contract lane passes (43 files, 976 tests).