-
Notifications
You must be signed in to change notification settings - Fork 870
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
ZIO 2.0 instrumentation #7980
ZIO 2.0 instrumentation #7980
Conversation
|
cefd1ff
to
dc24d4f
Compare
...avaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/zio/v2_0/FiberContext.java
Show resolved
Hide resolved
...ala/io/opentelemetry/javaagent/instrumentation/zio/v2_0/RelaxedInstrumentationExtension.java
Outdated
Show resolved
Hide resolved
...main/java/io/opentelemetry/javaagent/instrumentation/zio/v2_0/ZioRuntimeInstrumentation.java
Outdated
Show resolved
Hide resolved
.../main/java/io/opentelemetry/javaagent/instrumentation/zio/v2_0/ZioInstrumentationModule.java
Outdated
Show resolved
Hide resolved
...avaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/zio/v2_0/FiberContext.java
Outdated
Show resolved
Hide resolved
ZIO context handling
Hi @laurit, what do you think about the following change to this PR: dmytr#2? It seems to be more correct if we store thread's active context when fiber is resumed, and restore it when fiber is suspended. Instead of just restoring the root context. Tests pass, and I've tested this with my test harness - everything still seems to work. |
@dmytr I think it would work. But as the thread executing the fibers probably should not have a context outside of executing the fiber, and when it has, it is probably a context that was inadvertently leaked there, I'd keep the current approach just because it is a bit simpler. Unless you are suspecting that the thread could have a meaningful context outside of executing fibers that must be preserved I wouldn't change it. |
Hi @laurit 👋 Seems like I'm a bit late to the party 😅 I think that you are right and in most cases context outside of the fiber wouldn't matter. However I looked into the details of how
|
@dmytr Even with netty threads I would assume that the thread that is used for fiber doesn't have a meaningful scope. If it had a meaningful scope it would be in the middle of some other operation and getting borrowed to run the fiber would be strange. |
Summary
ZIO is a popular Scala library for asynchronous and concurrent programming. Its runtime uses green threads (fibers) which breaks instrumentation because context is stored in
ThreadLocal
variable. This PR takes care of synchronizing context between fibers and JVM threads on which they are executed.Notes about implementation
FiberContext
is the main piece which handles context synchronization. Implementation was tested on a non-trivial distributed application.