-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix tracing context propagation during connector invocation #21575
Fix tracing context propagation during connector invocation #21575
Conversation
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
if (!context.maybeYield()) { | ||
processSpan = null; | ||
return; | ||
try (var ignored2 = processSpan.makeCurrent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this fix the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io.opentelemetry.api.trace.SpanBuilder#startSpan
doesn't propagate the context automatically in the current thread, it should be done manually (as mentioned in javadoc).
From what I've found, in the Trino codebase it's done in several ways:
try (var ignored = span.makeCurrent()) {}
or
try (var ignored = scopedSpan(span)) {}
BTW ignored2
is not the best naming. But I believe when Trino migrates to Java 22 at a source level all these usages will be rewritten to just
try (var _ = ...) {}
@BeforeAll | ||
public void setUp() | ||
{ | ||
queryRunner = new StandaloneQueryRunner(testSessionBuilder().build()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there's only one test case, move this into the test method and use a try (QueryRunner runner = ...) { ... }
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@Test | ||
public void testTracingContextCapture() | ||
{ | ||
AtomicReference<Context> capturedCtx = new AtomicReference<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid abbreviations. Call this capturedContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
decb7bf
to
13e5c51
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
Description
After migrating from Trino 435 to the current version, we noticed that the tracing context no longer propagated into our custom connectors. Connector spans are detached from the parent span and stored as separate traces.
Trino 435
Trino 444
This PR fixes span propagation. It also adds a test to cover any possible future regressions.
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: