FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

perf(spanner): short-circuit trace_call when tracing is inactive by olavloite · Pull Request #18356 · googleapis/google-cloud-python · GitHub

Repository navigation

perf(spanner): short-circuit trace_call when tracing is inactive - #18356

Merged
olavloite merged 1 commit into
mainfrom
spanner-short-circuit-tracing
Sep 28, 2026
Merged

olavloite merged 1 commit into
mainfrom
spanner-short-circuit-tracing

Conversation

olavloite commented Sep 12, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

Skip building the trace attribute dictionary and creating spans in
trace_call when OpenTelemetry is not configured or uses a no-op tracer.
This reduces overhead by ~4.8 µs per call (~10 µs per query).

If a valid ambient span is present in the caller's context, a child span
is still started on the no-op tracer to prevent Spanner-internal attributes
and events from attaching to the parent span.

Also update observability_options validation to check Mapping.

olavloite requested a review from a team as a code owner September 12, 2026 16:07

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request introduces a fast-path optimization in OpenTelemetry tracing for Google Cloud Spanner, bypassing attribute dictionary construction and span creation when a no-op tracer is active. It also expands type checking for observability options to support general mappings and adds comprehensive unit tests. The review feedback suggests further simplifying the fast-path implementation to eliminate nested context manager overhead when tracing is inactive, and recommends streamlining type checks by using isinstance(observability_options, Mapping) instead of checking for both dict and Mapping.

olavloite force-pushed the spanner-short-circuit-tracing branch from de84a9d to ab4c846 Compare September 13, 2026 09:50

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request introduces a fast-path optimization in trace_call to bypass attribute dictionary construction and span creation when a no-op tracer is active or no TracerProvider is registered. Feedback on the changes highlights two critical issues: first, the helper _is_tracer_noop should check _real_tracer instead of _tracer on ProxyTracer to correctly handle lazy initialization; second, the unit tests should assign to the private _tracer attribute instead of the read-only _real_tracer property to avoid raising an AttributeError at runtime.

Skip building the trace attribute dictionary and creating spans in
`trace_call` when OpenTelemetry is not configured or uses a no-op tracer.
This reduces overhead by ~4.8 µs per call (~10 µs per query).

If a valid ambient span is present in the caller's context, a child span
is still started on the no-op tracer to prevent Spanner-internal attributes
and events from attaching to the parent span.

Also update `observability_options` validation to check `Mapping`.
olavloite force-pushed the spanner-short-circuit-tracing branch from ab4c846 to 2b5821a Compare September 13, 2026 10:08

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request introduces a fast-path optimization in the OpenTelemetry tracing implementation for Google Cloud Spanner. When no TracerProvider is registered or a no-op tracer is active, the code now skips attribute dictionary construction and span creation entirely, yielding a non-recording span or an invalid span instead. Additionally, observability_options type checking was updated to support any Mapping subclass. Comprehensive unit tests were added to verify these changes under various tracing configurations. There are no review comments, and I have no feedback to provide.

olavloite added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Sep 13, 2026
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 13, 2026

Copy link
Copy Markdown
Contributor

Could you please share the benchmark? The code path I see is one trace_call per single-use query, so I'm curious what makes up the ~10 µs.

Copy link
Copy Markdown
Contributor Author

Could you please share the benchmark? The code path I see is one trace_call per single-use query, so I'm curious what makes up the ~10 µs.

Many of these changes are so small that we do not run separate benchmarks for them (this is one such example). Instead, this is more about shaving away a few microseconds everywhere you can find them, as in a single-threaded language like Python, that makes a much bigger difference for overall throughput than in multi-threaded languages. The 10us in this case purely an estimate. The overall picture is clearer when you take all of these together and compare with what the performance was before (see screenshots shared separately).

olavloite merged commit 58031be into main Sep 28, 2026
47 checks passed
olavloite deleted the spanner-short-circuit-tracing branch September 28, 2026 17:22
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL