Distributed tracing with open telemetry#100
Merged
elizabetheonoja-art merged 3 commits intoJul 18, 2026
Merged
Conversation
…h-opentelemetry Add OpenTelemetry trace context propagation
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.
Motivation
Add end-to-end, OpenTelemetry-compatible W3C Trace Context propagation for off-chain services to improve observability and enable correlation across MQTT publishes, ingestion, and dashboard traces.
Ensure trace creation is safe and performant by validating incoming traceparent, rejecting all-zero ids, and generating local ids without depending on external collectors.
Surface simple health indicators in the dashboard (P99 latency, invalid contexts, exporter health) to meet the critical-path latency target and support canary/blue-green rollout decisions.
Description
Add meter-simulator/src/trace-context.js which provides parseTraceparent, createTraceContext, formatTraceparent, injectTraceContext, createBaggage, and calculateLatencyMs for W3C trace propagation and latency measurement.
Inject trace metadata into MQTT payloads by updating meter-simulator/src/mqtt-publisher.js to call injectTraceContext for usage, heartbeat, status, and to log publish-path latency; make service name configurable via observability.serviceName.
Expose observability configuration in meter-simulator/src/config.js and wire the service name into simulator entry points (simulate and send-reading) in meter-simulator/src/index.js.
Add Jest tests at meter-simulator/tests/trace-context.test.js covering traceparent creation/validation, parent-preservation, baggage encoding, and latency calculation, plus documentation docs/DISTRIBUTED_TRACING.md and a README observability section; update dashboard types/mock UI to show trace P99 and health signals.
Testing
Ran focused unit tests with npm test -- trace-context.test.js --runInBand, which passed (5/5 tests passed).
Performed syntax checks with node -c meter-simulator/src/mqtt-publisher.js and node -c meter-simulator/src/trace-context.js, which succeeded, and ran npx tsc --noEmit for dashboard type checks which succeeded.
Ran the full meter-simulator Jest suite (npm test -- --runInBand) and observed pre-existing unrelated failures in meter-device.test.js (fixture key size and timestamp/message-length expectations), which are not introduced by this change.
Attempted dashboard production build (npm run build) and it failed in this environment due to an external Google Fonts fetch error (network/font fetching issue), not code correctness.
Closes #63