Repository navigation
Conversation
…butes Fix tracing.enabled so an explicit client value overrides the OTEL_PYTHON_INSTRUMENTATION_MONGODB_ENABLED environment variable, fix db.query.text truncation so budgets smaller than the "..." marker still honor the bound, and fix collection-name extraction so user and role management commands do not expose usernames as db.collection.name.
Benchmark tracing overhead per the OpenTelemetry spec's performance requirements with tools/otel_bench.py, and optimize the per-command hot path based on the results: - Defer expensive span attributes (db.query.summary, db.mongodb.lsid, db.mongodb.txn_number, db.query.text) until after the sampler's decision, so unsampled and no-op spans skip building them entirely. db.query.text is the big win: it serialized the command to extended JSON on every single command. - Cache connection-static span attributes on the connection (keyed by server connection id) instead of rebuilding them per command. - Resolve the client's tracing option against the environment once, at MongoClient construction, so no command consults the environment. - Skip building the duration timedelta when neither command logging nor APM events are enabled; a tracing-only client doesn't need it. Add PERF_CPU_TIME to the DriverBench performance tests to record per-operation CPU time, which otel_bench.py uses to report the fixed CPU cost of each tracing configuration (tracing off, api-only, SDK with TraceIdRatioBased sampling, SDK always-on).
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3 of 4 tasks
This branch has not been deployed
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.
PYTHON-6065
Changes in this PR
tools/otel_bench.py, a benchmark harness covering the tracing config variants for DRIVERS-3620, plus per-op CPU-time recording intest/performance/(PERF_CPU_TIME=1).tracingoption once at client construction, skip the durationtimedeltawhen logging/APM are off.Results
16-core x86_64, MongoDB 8.0.4 localhost, CPython 3.9, 5 interleaved repetitions with rotated config order, medians; no exporter or span processor installed.
Throughput (median MB/s, overhead vs untraced baseline in parens):
CPU time per operation (µs/op median, delta vs baseline in parens):
Tracing disabled vs pre-tracing commit (
d5934e6):Overhead barely depends on sampling rate: a span must be started to learn it won't record, so attribute collection and sampler machinery run on every command. Micro-benchmarks on ~160-460 µs ops magnify the fixed cost; real workloads amortize it.
Test Plan
test/asynchronous/test_otel.py(sync suite mirrored) cover the deferred attributes, the connection cache, and a hot-path regression test.python tools/otel_bench.py --verifychecks span wiring end-to-end; full run viapython tools/otel_bench.py --reps 5.Checklist
Checklist for Author
Checklist for Reviewer