feat(event-bus): restore event-bus plugin with W3C OTel traceparent propagation#5
Closed
sumitjha-arch wants to merge 1 commit into
Closed
feat(event-bus): restore event-bus plugin with W3C OTel traceparent propagation#5sumitjha-arch wants to merge 1 commit into
sumitjha-arch wants to merge 1 commit into
Conversation
…ropagation Re-introduces the event-bus plugin (removed in 2.14.0) with a critical fix: W3C traceparent is now propagated across the GCP Pub/Sub async boundary so distributed traces remain connected end-to-end. ### What was broken `publishToPubSub()` never called `propagation.inject()`, so Pub/Sub message attributes contained no traceparent. The push/pull consumer never called `propagation.extract()`, so every incoming message started a new root span — completely disconnected from the originating HTTP request's trace tree. ### What is fixed (gcp-pubsub.ts) - PUBLISH: `otel.propagation.inject(otel.context.active(), attrs)` injects the active span context as `traceparent`/`tracestate` into Pub/Sub message attributes before every `topic.publishMessage()` call. - CONSUME (push): `otel.propagation.extract(attrs)` reconstructs the parent context from the incoming message, starts a `pubsub.consume.<event>` CONSUMER span as a child, and runs all handlers inside `otel.context.with()` so every DB query and further publish is linked to the original trace. - Logs `EVENT_TRACEPARENT_INJECT` on publish and `traceparent_extracted` field on consume for observability. ### What is fixed (event-consumer/gcp-pubsub.ts) - Pull consumer extracts the traceparent from message attributes, starts a `pubsub.pull.process` CONSUMER span, and re-injects the context as HTTP headers into the internal `instance.inject()` call so the push handler receives the correct trace context. ### OTel API resolution Both files use a lazy `getOtelApi()` helper that tries `@opentelemetry/api` first (available via NODE_PATH when using the OTel Kubernetes operator) and falls back to the pnpm content-addressed path. Returns null if neither is available, so no error is thrown in environments without OTel. ### TypeScript 6 compatibility fixes Fixed implicit-any and unknown-err errors in azure-servicebus.ts, rabbitmq.ts, and commons.ts introduced by the TypeScript 6.0 upgrade. Verified end-to-end in a kind cluster with a Pub/Sub emulator: - NO-FIX: traceparent ABSENT in message attributes → broken trace tree - FIX: traceparent present → same traceID from HTTP request through pg-boss outbox publish through Pub/Sub consumer handler Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
Closing — will be handled differently |
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
fp-plugins@2.12.0which includes itazure-servicebus.ts,rabbitmq.ts, andcommons.tsintroduced by the TS 6.0 upgrade that removed this codeRoot cause
publishToPubSub()setattrs = { event }and calledtopic.publishMessage()with notraceparentattribute. The push handler at/gcp-pubsub/process-messageread the message but never calledpropagation.extract(). Result: every Pub/Sub-triggered handler was a new root span — invisible in Jaeger alongside the originating HTTP request.What changed
src/event-bus/gcp-pubsub.tsOn publish:
On consume (push handler):
src/event-bus/event-consumer/gcp-pubsub.tsPull consumer now extracts traceparent from message attributes, starts a
pubsub.pull.processCONSUMER span, and re-injects the context as HTTP headers into the internalinstance.inject()call so the push handler receives the correct trace context.OTel API loading
Both files use a lazy
getOtelApi()helper — tries@opentelemetry/apivia NODE_PATH first (Kubernetes OTel operator), falls back to the pnpm content-addressed path, returnsnull(no error) if unavailable. Safe to deploy without OTel.Test evidence
Verified in a kind cluster with a GCP Pub/Sub emulator, comparing side-by-side deployments:
message.attributes.traceparentABSENT00-89adb2d60dd4fd1e8c2d1bafd228e468-9f94e3df4a135bc3-01The traceID is preserved end-to-end from the original HTTP request through the pg-boss outbox worker through the Pub/Sub consumer handler.
Test plan
pnpm run buildpasses (TypeScript compilation clean)pnpm testpasses (unit tests)pubsub.consume.<event>span as child of the originating HTTP span🤖 Generated with Claude Code