elastic / elastic/apm-agent-java

Provide general context key/value store with OTel bridge

Open
#2,761 0 comments 0 reactions 0 assignees View on GitHub
agent-java
Dominant language
Java
Stars
594
Forks
338
Avg merge
1d 13h
Merged PRs (30d)
25

Description

Currently, when using the OTel bridge, the `Context` storage only works as expected to access the "current active span" when there is such.

The general contract of `Context` is to provide a general key-value store, and our implementation does not support that.

For example, any application that relies on storing an entry in the active context, for example using `Context.current().with(key, "value").makeCurrent()` will either directly fail or won´t provide the expected value when calling `Context.current().get(key)`.

However, the most common usage to retrieve the "active span" with `Span.current()` will work as expected as the bridged context will retrieve the active span from the `Tracer` state.

There are a few extra complications to making this rather simple storage challenging in practice:
- most entries are stored with keys that are `Class`, which will definitely be a challenge thanks to isolated classloading as identified in #2735,
- The implementation provided by OTel API is [`ArrayBasedContext`](https://github.com/open-telemetry/opentelemetry-java/blob/50408d499f85d5761d0a5ed9bf9d77d5ff01fff5/context/src/main/java/io/opentelemetry/context/ArrayBasedContext.java) which is package-private thus iterating over entries or copying the context might require extra efforts.
- re-creating (or wrapping) the `Context` object when accessed from another CL could be possible if we can map the entries purpose in the original context: for example, an entry with `Span` class as key would always be the "active span" which we can re-create from the `Tracer` state.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.