Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
package io.opentelemetry.javaagent.instrumentation.zio.v2_0;

import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import zio.Fiber;

public final class FiberContext {
@SuppressWarnings("rawtypes")
public static final VirtualField<Fiber.Runtime, FiberContext> RUNTIME_FIBER_CONTEXT =
VirtualField.find(Fiber.Runtime.class, FiberContext.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the only usage is within TracingSupervisor, we should be able to move the virtual field there as constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I've just moved it.


private Context context;

private FiberContext(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class ZioInstrumentationModule extends InstrumentationModule {
public class ZioInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public ZioInstrumentationModule() {
super("zio", "zio-2.0");
Expand All @@ -23,4 +25,9 @@ public ZioInstrumentationModule() {
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new ZioRuntimeInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

package io.opentelemetry.javaagent.instrumentation.zio.v2_0;

import static io.opentelemetry.javaagent.instrumentation.zio.v2_0.FiberContext.RUNTIME_FIBER_CONTEXT;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;

import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import zio.Fiber;
import zio.Supervisor;

public class ZioRuntimeInstrumentation implements TypeInstrumentation {
Expand All @@ -36,11 +35,9 @@ public static final class DefaultSupervisor {
private DefaultSupervisor() {}

@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(@Advice.Return(readOnly = false) Supervisor<?> supervisor) {
@SuppressWarnings("rawtypes")
VirtualField<Fiber.Runtime, FiberContext> virtualField =
VirtualField.find(Fiber.Runtime.class, FiberContext.class);
supervisor = supervisor.$plus$plus(new TracingSupervisor(virtualField));
@Advice.AssignReturned.ToReturned
public static Object onExit(@Advice.Return Supervisor<?> supervisor) {
return supervisor.$plus$plus(new TracingSupervisor(RUNTIME_FIBER_CONTEXT));
}
}
}