-
Notifications
You must be signed in to change notification settings - Fork 679
feat(spanner): optimize RequestId propagation and minimize OpenTelemetry active tracing overhead #8329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+251
−55
Merged
feat(spanner): optimize RequestId propagation and minimize OpenTelemetry active tracing overhead #8329
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
652517b
feat(spanner): optimize RequestId propagation and minimize OpenTeleme…
surbhigarg92 1d6552e
Merge branch 'main' into performance_optimization
surbhigarg92 85e4b52
Merge branch 'main' into performance_optimization
surbhigarg92 728a980
review_comments
surbhigarg92 ee3ed0d
Merge branch 'main' into performance_optimization
surbhigarg92 1346786
Merge branch 'main' into performance_optimization
surbhigarg92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,67 @@ function ensureInitialContextManagerSet() { | |
|
|
||
| export {ensureInitialContextManagerSet}; | ||
|
|
||
| let globalTracingEnabled: boolean | undefined = undefined; | ||
| let lastCheckTime = 0; | ||
| const CACHE_TTL_MS = 10000; // 10 seconds TTL | ||
|
|
||
| /** | ||
| * isGlobalTracingEnabled returns true if tracing is enabled globally, | ||
| * respecting cached status and active recording spans. | ||
| * | ||
| * @returns {boolean} True if global tracing is enabled. | ||
| */ | ||
| function isGlobalTracingEnabled(): boolean { | ||
| const now = Date.now(); | ||
| if ( | ||
| globalTracingEnabled !== undefined && | ||
| (globalTracingEnabled || now - lastCheckTime < CACHE_TTL_MS) | ||
| ) { | ||
| return globalTracingEnabled; | ||
|
surbhigarg92 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| lastCheckTime = now; | ||
| const globalProvider = trace.getTracerProvider(); | ||
| if (globalProvider) { | ||
| let delegate = globalProvider; | ||
| if (typeof (globalProvider as any).getDelegate === 'function') { | ||
| delegate = (globalProvider as any).getDelegate(); | ||
| } | ||
| if (delegate) { | ||
| const name = delegate.constructor.name; | ||
| // Exclude the dummy NoopTracerProvider and uninitialized ProxyTracerProvider | ||
| if (name !== 'NoopTracerProvider' && name !== 'ProxyTracerProvider') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this check depends on the stability of these class names. That has two problems:
An alternative could be to do the check like this: const probeSpan = globalProvider
.getTracer(TRACER_NAME, TRACER_VERSION)
.startSpan('probe');
// isSpanContextValid returns false for NoopSpan, as it does not have a traceID.
const isValid = trace.isSpanContextValid(probeSpan.spanContext());
probeSpan.end();
if (isValid) {
globalTracingEnabled = true;
ensureInitialContextManagerSet();
return true;
} |
||
| globalTracingEnabled = true; | ||
| ensureInitialContextManagerSet(); | ||
| return true; | ||
| } | ||
| } | ||
|
surbhigarg92 marked this conversation as resolved.
|
||
| } | ||
| globalTracingEnabled = false; | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * isTracingEnabled returns true if tracing is enabled for the given options | ||
| * or globally. | ||
| * | ||
| * @param {ObservabilityOptions} [opts] The observability options. | ||
| * @returns {boolean} True if tracing is enabled. | ||
| */ | ||
| export function isTracingEnabled(opts?: ObservabilityOptions): boolean { | ||
| if (opts?.tracerProvider) { | ||
| return true; | ||
| } | ||
|
|
||
| return isGlobalTracingEnabled(); | ||
| } | ||
|
|
||
| /** Only exported for resetting state in unit tests. */ | ||
| export function _resetTracingEnabledForTest(): void { | ||
| globalTracingEnabled = undefined; | ||
| lastCheckTime = 0; | ||
| } | ||
|
|
||
| /** | ||
| * startTrace begins an active span in the current active context | ||
| * and passes it back to the set callback function. Each span will | ||
|
|
@@ -132,6 +193,10 @@ export function startTrace<T>( | |
| config: traceConfig | undefined, | ||
| cb: (span: Span) => T, | ||
| ): T { | ||
| if (!isTracingEnabled(config?.opts)) { | ||
| return cb(new noopSpan()); | ||
| } | ||
|
|
||
| if (!config) { | ||
| config = {} as traceConfig; | ||
| } | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.