fix(diagnostics-otel): share listeners/transports across module bundles#16865
Closed
leonnardo wants to merge 2 commits intoopenclaw:mainfrom
Closed
fix(diagnostics-otel): share listeners/transports across module bundles#16865leonnardo wants to merge 2 commits intoopenclaw:mainfrom
leonnardo wants to merge 2 commits intoopenclaw:mainfrom
Conversation
bfc1ccb to
f92900f
Compare
81c03c0 to
160e710
Compare
Open
16 tasks
16 tasks
18 tasks
Member
|
Appreciate the effort here. I’m closing this as a duplicate of #28166, which consolidates the shared log transport fix with the related trace-context work into a single, clean PR. If that’s not the right call, point me to the missing piece and I’ll reopen review quickly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
diagnostics-otelcould miss diagnostic events and/or logs when OpenClaw had multiple module instances loaded (bundle/module isolation), because state was module-local.globalThisinsrc/infra/diagnostic-events.tsglobalThisinsrc/logging/logger.tsregisterLogTransport(...)now attaches to all active logger instances with idempotent attach trackingsrc/logger.test.tsfor multi-logger transport attach + unsubscribeChange Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Security Impact (required)
No)No)No)No)No)Repro + Verification
Environment
gpt-5.3-codex) for traffic generationdiagnostics-otelwith logs/metrics enabled, OTLP endpoint configuredSteps
diagnostics-otelwith OTLP logs + metrics.Expected
Actual
service_name="openclaw-gateway-dev"returns gateway logs.Evidence
Human Verification (required)
What I personally verified:
pnpm buildpnpm checkpnpm vitest run src/logger.test.ts src/infra/infra-store.test.ts src/logging/diagnostic.test.ts extensions/diagnostics-otel/src/service.test.tsopenclaw-gateway-devlogsEdge cases checked:
What I did not verify:
Compatibility / Migration
Yes)No)No)Failure Recovery (if this breaks)
Risks and Mitigations
WeakMap).AI-assisted: Yes
Testing level: fully tested for touched scope (targeted tests + runtime validation)
Greptile Summary
Moves diagnostic events and log transport state to
globalThisto fix module/bundle isolation issues preventing OTEL export.Key changes:
globalThis.__openclaw_diagnostic_events_state__globalThis.__openclaw_external_log_transports__with per-logger idempotent attachment tracking viaWeakMapregisterLogTransportnow attaches to all active logger instances, not just the cached oneThe implementation correctly addresses the stated problem (diagnostics-otel missing events across module boundaries) by sharing state globally while maintaining idempotency through
WeakMaptracking.Confidence Score: 4/5
globalThiswith typed keys). TheWeakMapapproach for idempotent attachment is sound. Test coverage includes the critical multi-logger scenario. One minor consideration: timestamp validation silently drops invalid timestamps rather than logging warnings, but the try-catch ensures no exceptions propagate.Last reviewed commit: 160e710