open-telemetry / open-telemetry/opentelemetry-java-instrumentation

Problem with Context propagation with Apache Camel auto-instrumentation when using camel-blueprint (or Karaf)

Open
#14,238 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

When running Apache Camel with camel-blueprint in something like Apache Karaf, there is an issue with context propagation. This leads to an extra span being created on the first request that is never ended and thus not exported, and which will become the parent span for not just this request, but all subsequent requests. Leading to one trace that can last tens of minutes and contains (orphaned) spans from many requests.

Image

The problem is https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/2f0d2320572b9e8da07834cf99898bad9c7666b0/instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ActiveContextManager.java#L53

The ClassLoader for ContextWithScope when the property is set is the camel-blueprint one: org.eclipse.osgi.internal.loader.EquinoxClassLoader@1901b0b7[org.apache.camel.camel-blueprint:2.24.2(id=230)], but when the property is retrieved later, that ClassLoader is the camel-core one: org.eclipse.osgi.internal.loader.EquinoxClassLoader@6cad635c[org.apache.camel.camel-core:2.24.2(id=49)]

That means that the exchange.getProperty(ACTIVE_CONTEXT_PROPERTY, ContextWithScope.class); invocation returns null, because even though the class is ContextWithScope in both cases, they are loaded by different ClassLoaders, and thus different.

The (one?) fix is to use the regular getProperty method to get an Object back that we cast to the ContextWithScope that is currently loaded.
I have this fix ready in my fork: https://github.com/open-telemetry/opentelemetry-java-instrumentation/compare/main...evanderkoogh:opentelemetry-java-instrumentation:talendESB-context-fix

Is it ok to open up a PR with this change? Or is there another preferred way of solving this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ActiveContextManager.java at the ACTIVE_CONTEXT_PROPERTY lookup around line 53. Compare the typed property access with the reported class-loader mismatch and verify that the active context is retrieved correctly, so the first request does not leave an orphaned span or parent later requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.