Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
The implementation relies on this unreleased PR in otel4s.
Hence, the CI will fail.
Hey folks.
otel4s is an OpenTelemetry library for Typelevel ecosystem. It offers Scala-friendly API and uses opentelemetry-java as a backend.
otel4s uses IOLocal under the hood to propagate context within fibers.
An instance of
IOLocalcan be represented as aThreadLocal.Unfortunately, due to various complications, we cannot use
Context.currentandContext.attachas a complete replacement forIOLocal.How the instrumentation works
IOLocalContextStorage.registerFiberThreadContextand captures the providedThreadLocalrepresentation ofIOLocalFiberLocalContextHelper)ContextStoragewrapper (for the agent context storage). This wrapper usesFiberLocalContextHelperto retrieve the fiber's current context (if available)How the context bridge works
The bridge works in the following way:
current- returns fiber context if available, return agent context otherwiseattach- sets the given context to both fiber's and agent contextsWhile things look chaotic, the demo proves the instrumentation works.