Native OpenTelemetry tracing — foundation + ADR (Phase 1a)#689
Draft
wbarnha wants to merge 2 commits into
Draft
Conversation
Groundwork for migrating Faust's built-in distributed tracing off the archived OpenTracing API to native OpenTelemetry, keeping the full span tree. This first increment adds the decision record and a self-contained, unit-tested tracing core; no existing call sites are rewired yet, so the running tracing layer is unaffected. - docs/adr/0001-native-opentelemetry-tracing.md: architecture decision record (options, why no opentelemetry-instrumentation-faust exists, semconv coexistence, re-expression of the two non-portable hacks, and the phased migration plan). - faust/utils/otel_tracing.py: api-only tracing primitives that degrade to no-ops when OpenTelemetry is absent -- tracer resolution against the global provider, contextvar current-span, deterministic rebalance parent context (native replacement for the immutable-context trace_id mutation), a deferred PendingSpan (native replacement for the finish monkeypatch), semconv-coexistence attribute helpers (legacy tags + messaging.*), and W3C header inject/extract. - tests/unit/utils/test_otel_tracing.py: 15 tests covering every primitive against an in-memory SDK exporter. - requirements/extras/opentelemetry.txt + setup.py: faust[opentelemetry] extra (opentelemetry-api/sdk). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #689 +/- ##
========================================
Coverage 94.14% 94.14%
========================================
Files 104 105 +1
Lines 11136 11242 +106
Branches 1201 1215 +14
========================================
+ Hits 10484 10584 +100
- Misses 551 553 +2
- Partials 101 105 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The Phase 1a tests guard on `pytest.importorskip("opentelemetry.sdk.trace")`,
so without OpenTelemetry installed in CI they were all skipped, leaving
faust/utils/otel_tracing.py at 29% patch coverage and failing the codecov
gate.
- requirements/test.txt: pull in extras/opentelemetry.txt so the test job
installs opentelemetry-api/sdk and the 15 tests actually execute
(matches the existing `-r extras/*.txt` pattern in test.txt).
- otel_tracing.py: mark the dependency-absent `if not HAS_OTEL:` fallbacks
with `# pragma: no cover` -- they only run when OpenTelemetry is not
installed, a config CI no longer exercises.
- test_otel_tracing.py: add tests for the real runtime guards (None span,
None tracer, non-bytes key, default carrier) instead of pragma-ing them.
Module coverage is now 96%.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
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.
Description
Groundwork for migrating Faust's built-in distributed tracing off the archived / EOL OpenTracing API to native OpenTelemetry, while keeping the full processing-pipeline span tree (agents, streams, table recovery, assignor, timers, Crontabs, rebalance).
This is Phase 1a — foundation only. It adds an architecture decision record and a self-contained, unit-tested native tracing core. No existing call sites are rewired yet, so the running OpenTracing layer is completely unaffected. Opening as a draft to get agreement on the approach before the larger Phase 1b rewire.
Why native OTel (and why not an instrumentor)
opentelemetry-instrumentation-faustpackage — not on PyPI, not inopentelemetry-python-contrib, nothing community-maintained. The transport-level instrumentors (opentelemetry-instrumentation-aiokafka/-confluent-kafka, both beta) only patch the raw Kafka clients and cannot reproduce Faust's agent/stream/recovery/rebalance spans — they complement, they can't replace.opentelemetry-api(no SDK); calls are cheap no-ops until the app registers aTracerProvider.opentelemetry.contextis contextvars-based, so Faust's current-span propagation maps 1:1, including acrossawait.What's in this PR
docs/adr/0001-native-opentelemetry-tracing.md— the decision record: options considered, semantic-convention coexistence, native re-expression of the two non-portable OpenTracing hacks, and the phased migration plan.faust/utils/otel_tracing.py— api-only tracing primitives that degrade to no-ops when OpenTelemetry is absent:deterministic_parent_context()— native replacement for the oldspan.context.trace_id = murmur2(...)mutation (OTel span contexts are immutable): aNonRecordingSpanparent carries the seeded trace id and the real rebalance span inherits it;PendingSpan— native replacement for the_transform_span_lazyspan.finishmonkeypatch: defer span creation until the Kafka generation is known, or cancel;kafka-*tags (deprecated) and the OpenTelemetrymessaging.*attributes +SpanKind;traceparentheader inject/extract.tests/unit/utils/test_otel_tracing.py— 15 tests covering every primitive against an in-memory SDK exporter (both hacks validated end-to-end); the no-OTel degradation path is also exercised.requirements/extras/opentelemetry.txt+setup.py— newfaust[opentelemetry]extra (opentelemetry-api/-sdk).Semantic-convention coexistence
Adopted additively: span names stay legacy by default (
consume-from-{topic},job-{topic},produce-to-{topic}) and are marked deprecated, whilemessaging.*attributes +SpanKindcoexist on the same span. A future opt-in flips names to semconv ({topic} process, …).Migration plan (see ADR)
TracerTin OTel terms; ship a legacy adapter wrapping existing OpenTracingapp.tracerimplementations via the shim for one major cycle. Targets a major version —app.tracer/TracerTis a breaking signature change.opentracingfrom core requirements and remove the adapter.Notes for reviewers
🤖 Generated with Claude Code
Generated by Claude Code