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

Tracing: fix flaky test and add scope checks before closing #8934

Merged
merged 4 commits into from
Dec 21, 2022

Conversation

lmolkova
Copy link
Contributor

@lmolkova lmolkova commented Dec 20, 2022

Follow up for #8713 and #8911.

Fixes flaky CurrentSpanTest.testContextDoesNotLeak test.
I was able to repro failures locally and with this change, they are no longer reproducible (tried on 1000 iterations).

There are several problems:

  1. We can't guarantee that ExchangeAsyncProcessingStartedEvent is fired once and only if a span was created previously
  2. We can't guarantee that span ends on the same thread it was started, i.e. scope is closed on the same thread
  3. Due to concurrency in async scenarios we can call close on scope two times

As a result, we're closing scopes multiple times and from the wrong threads. Changing these on Camel side, AFAIK would be quite difficult.

Unfortunately, OTel scope closing works differently than I thought - open-telemetry/opentelemetry-java#5055. If called multiple times and on a different thread than the scope was started, it restores the wrong context on the other thread.

While the solution on OTel side is evaluated, I suggest guarding scope closing with thread check and making it idempotent.

This PR also adds logging in case there is more flakiness.

@github-actions
Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟

⚠️ Please note that the changes on this PR may be tested automatically.

If necessary Apache Camel Committers may access logs and test results in the job summaries!

@lmolkova lmolkova changed the title Tracing: fix flaky test and add scope schecks Tracing: fix flaky test and add scope checks before closing Dec 20, 2022
@github-actions
Copy link
Contributor

Components tested:

Total Tested Failed ❌ Passed ✅
2 2 0 2

@github-actions
Copy link
Contributor

Components tested:

Total Tested Failed ❌ Passed ✅
8 8 1 8

@github-actions
Copy link
Contributor

Components tested:

Total Tested Failed ❌ Passed ✅
8 8 0 9

@davsclaus davsclaus merged commit 2e1cc4f into apache:main Dec 21, 2022
jamesnetherton pushed a commit to jamesnetherton/camel that referenced this pull request Apr 24, 2023
)

* Tracing: make scope closing idempotent

* cleanup

* more cleanups

* oops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants