Split tracing into vendor-neutral observability + OTel adapter#861
Open
KirillKurdyukov wants to merge 2 commits into
Open
Split tracing into vendor-neutral observability + OTel adapter#861KirillKurdyukov wants to merge 2 commits into
KirillKurdyukov wants to merge 2 commits into
Conversation
Move all non-OTel tracing plumbing (Span/TracingProvider protocols, Noop implementation, SpanName, registry, YDB attribute helpers) into a new ydb.observability package. The OTel bridge in ydb.opentelemetry becomes a concrete provider (OtelTracingProvider) that plugs into the same interface. Users can now enable tracing without any OpenTelemetry dependency by supplying a custom TracingProvider to ydb.observability.enable_tracing. A second enable call always replaces the previously installed provider. ydb.opentelemetry.tracing is kept as a thin re-export shim for backward compatibility. All SDK internal imports (retries, connection, pool, session, transaction — sync + aio) now go through ydb.observability.tracing. Added tests/tracing/test_observability_enable.py covering: default Noop state, custom provider wiring, reset semantics on double enable, disable reverting to Noop, OTel enable replacing a custom provider, and duck-typed providers satisfying the protocol. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #861 +/- ##
==========================================
+ Coverage 81.38% 81.55% +0.17%
==========================================
Files 94 96 +2
Lines 12197 12209 +12
Branches 1204 1201 -3
==========================================
+ Hits 9926 9957 +31
+ Misses 1807 1799 -8
+ Partials 464 453 -11
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- TestSplitEndpoint — parametric test covering every branch of _split_endpoint (grpcs://, grpc://, bare host:port, valid/malformed IPv6, missing colon, non-numeric port, None). - TestBuildYdbAttrsPeerOptionals — peer tuples with only address / only port / only location / empty location, hitting the three if x is not None branches in _build_ydb_attrs. - TestSetPeerAttributes — direct unit test for the set_peer_attributes helper (previously only reached through session flows that never had a non-None peer). - TestSpanFinishCallback — success and exception paths of the streaming _finish callback. - TestOpentelemetryTracingShimReexports — proves the ydb.opentelemetry.tracing back-compat shim re-exports the exact same objects as ydb.observability.tracing. - TestOtelEntrypointHandlesMissingPackage — uses sys.modules["ydb.opentelemetry.plugin"] = None to force the ImportError branches in ydb.opentelemetry.__init__.enable_tracing / disable_tracing. - TestOtelTracingSpanBridge — direct tests for TracingSpan.set_attribute and the defensive "exit before enter" branch in _AttachContext. - TestNoopContextManager — smoke tests for the Noop context manager and NoopTracingProvider returning the shared span + empty metadata.
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
Fixes an architectural issue: tracing was tightly coupled to OpenTelemetry — the SDK forced users to have
opentelemetryinstalled just to enable tracing, and there was no way to plug in a custom backend.This PR splits the module in two:
ydb.observability(new) — vendor-neutral interfaces (Span,TracingProvider), Noop implementation,SpanName, registry, and all SDK-side helpers (create_ydb_span,set_peer_attributes,span_finish_callback,get_trace_metadata). The SDK core imports only from here and never touchesopentelemetry.ydb.opentelemetry— becomes a concreteOtelTracingProviderthat plugs into the same interface.ydb.opentelemetry.enable_tracing(tracer=None)is now a thin convenience that builds the provider and hands it toydb.observability.enable_tracing(...).New public API
enable_tracingcleanly resets the previously installed provider (works for OTel and custom providers alike — previouslyydb.opentelemetry.enable_tracingwas silently idempotent).ydb.opentelemetry.tracingremains as a re-export shim for backward compatibility.Tests
tests/tracing/test_observability_enable.py(12 tests) uses a hand-rolledRecordingProvider— no OTel involvement — to cover:enable_tracing,enable_tracing(None)==disable_tracing(),disable_tracingreverts to Noop,ydb.opentelemetry.enable_tracingreplacing a custom provider,TracingProviderprotocol.Test plan
tox -e black-format+tox -e blacktox -e styletox -e mypytox -e py -- ydb -v(174 passed)tox -e py -- tests/tracing -v(55 passed, including 12 new observability tests)🤖 Generated with Claude Code