Skip to content
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

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

alekkol
Copy link
Contributor

@alekkol alekkol commented Apr 16, 2024

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
Screenshot 2024-04-12 at 13 35 10

Trino 444
Screenshot 2024-04-12 at 13 37 52

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:

# Section
* Fixed tracing context propagation in connector

Copy link

cla-bot bot commented Apr 16, 2024

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()) {
Copy link
Member

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?

Copy link
Contributor Author

@alekkol alekkol Apr 16, 2024

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 _ = ...) {}

Comment on lines 43 to 47
@BeforeAll
public void setUp()
{
queryRunner = new StandaloneQueryRunner(testSessionBuilder().build());
}
Copy link
Member

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

Copy link
Contributor Author

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<>();
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link

cla-bot bot commented Apr 17, 2024

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

@alekkol alekkol force-pushed the fix-connector-tracing-propagation branch from decb7bf to 13e5c51 Compare April 17, 2024 09:44
Copy link

cla-bot bot commented Apr 17, 2024

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

@alekkol alekkol requested a review from martint April 24, 2024 14:03
@alekkol
Copy link
Contributor Author

alekkol commented Apr 29, 2024

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Apr 29, 2024
Copy link

cla-bot bot commented Apr 29, 2024

The cla-bot has been summoned, and re-checked this pull request!

@martint martint merged commit a7b2e3b into trinodb:master Apr 29, 2024
95 checks passed
@github-actions github-actions bot added this to the 446 milestone Apr 29, 2024
@alekkol alekkol deleted the fix-connector-tracing-propagation branch May 28, 2024 21:31
@alekkol alekkol restored the fix-connector-tracing-propagation branch June 17, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants