-
Notifications
You must be signed in to change notification settings - Fork 932
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
Add cats-effect instrumentation #13576
base: main
Are you sure you want to change the base?
Add cats-effect instrumentation #13576
Conversation
import cats.effect.IOLocal; | ||
import io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage; | ||
|
||
public class IoLocalContextSingleton { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be defined in a common
package so we can lately reuse it to instrument otel4s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a prototype: iRevive@b2f6501
Some tests have failed with the following error:
I assume some VMs aren't happy with the body modification of IO? |
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter() { | ||
FiberLocalContextHelper.initialize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you have deployed 2 wars on tomcat that use this library, won't this break? Messing with the context storage is unusual, my hunch is that this is not a good idea. Typically such instrumentations restore the otel context when fiber starts running on a thread and save the context when it stops using the thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a valid concern indeed.
deployed 2 wars on tomcat that use this library
If I understand correctly, each deployment (app) will have its own classloader, but the bootstrap will still be shared.
If that's the case, my implementation won't work, I'm afraid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppose I don't find a proper way to make the instrumentation work. Can I distribute the current implementation as a third-party extension? Can the extension have access to the bootstrap loader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the extension have access to the bootstrap loader?
Not directly, but you could try using byte-buddy to define the class you need in boot loader or you could experiment with Instrumentation.appendToBootstrapClassLoaderSearch
.
Closes #10599.
Hey folks.
Cats Effect is a high-performance, asynchronous, composable framework for building real-world applications in a purely functional style within the Typelevel ecosystem.
How the instrumentation works
Cats Effect has its context propagation mechanism known as IOLocal. 3.6.0 release provides a way to represent IOLocal as a
ThreadLocal
, which creates an opportunity to manipulate the context from the outside.IORuntime
and stores aThreadLocal
representation of theIOLocal[Context]
in the bootstrap classloader, so the agent and application both access the same instanceContextStorage
wrapper (for the agent context storage). This wrapper usesFiberLocalContextHelper
to retrieve the fiber's current context (if available)IOFiber
's constructor and starts the fiber with the currently available context