Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -11,8 +11,6 @@
import akka.dispatch.Envelope;
import akka.dispatch.sysmsg.SystemMessage;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
import io.opentelemetry.javaagent.bootstrap.executors.TaskAdviceHelper;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
Expand Down Expand Up @@ -42,9 +40,8 @@ public static class InvokeAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static Scope enter(@Advice.Argument(0) Envelope envelope) {
VirtualField<Envelope, PropagatedContext> virtualField =
VirtualField.find(Envelope.class, PropagatedContext.class);
return TaskAdviceHelper.makePropagatedContextCurrent(virtualField, envelope);
return TaskAdviceHelper.makePropagatedContextCurrent(
VirtualFields.ENVELOPE_PROPAGATED_CONTEXT, envelope);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand All @@ -60,9 +57,8 @@ public static class SystemInvokeAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static Scope enter(@Advice.Argument(0) SystemMessage systemMessage) {
VirtualField<SystemMessage, PropagatedContext> virtualField =
VirtualField.find(SystemMessage.class, PropagatedContext.class);
return TaskAdviceHelper.makePropagatedContextCurrent(virtualField, systemMessage);
return TaskAdviceHelper.makePropagatedContextCurrent(
VirtualFields.SYSTEM_MESSAGE_PROPAGATED_CONTEXT, systemMessage);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import akka.dispatch.sysmsg.SystemMessage;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.bootstrap.executors.ExecutorAdviceHelper;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
Expand Down Expand Up @@ -49,9 +48,8 @@ public static class DispatchSystemAdvice {
public static PropagatedContext enter(@Advice.Argument(1) SystemMessage systemMessage) {
Context context = Java8BytecodeBridge.currentContext();
if (ExecutorAdviceHelper.shouldPropagateContext(context, systemMessage)) {
VirtualField<SystemMessage, PropagatedContext> virtualField =
VirtualField.find(SystemMessage.class, PropagatedContext.class);
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, systemMessage);
return ExecutorAdviceHelper.attachContextToTask(
context, VirtualFields.SYSTEM_MESSAGE_PROPAGATED_CONTEXT, systemMessage);
}
return null;
}
Expand All @@ -61,10 +59,11 @@ public static void exit(
@Advice.Argument(1) SystemMessage systemMessage,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<SystemMessage, PropagatedContext> virtualField =
VirtualField.find(SystemMessage.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(
propagatedContext, throwable, virtualField, systemMessage);
propagatedContext,
throwable,
VirtualFields.SYSTEM_MESSAGE_PROPAGATED_CONTEXT,
systemMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import akka.dispatch.Envelope;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.bootstrap.executors.ExecutorAdviceHelper;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
Expand Down Expand Up @@ -43,9 +42,8 @@ public static class DispatchEnvelopeAdvice {
public static PropagatedContext enterDispatch(@Advice.Argument(1) Envelope envelope) {
Context context = Java8BytecodeBridge.currentContext();
if (ExecutorAdviceHelper.shouldPropagateContext(context, envelope.message())) {
VirtualField<Envelope, PropagatedContext> virtualField =
VirtualField.find(Envelope.class, PropagatedContext.class);
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, envelope);
return ExecutorAdviceHelper.attachContextToTask(
context, VirtualFields.ENVELOPE_PROPAGATED_CONTEXT, envelope);
}
return null;
}
Expand All @@ -55,9 +53,8 @@ public static void exitDispatch(
@Advice.Argument(1) Envelope envelope,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<Envelope, PropagatedContext> virtualField =
VirtualField.find(Envelope.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, envelope);
ExecutorAdviceHelper.cleanUpAfterSubmit(
propagatedContext, throwable, VirtualFields.ENVELOPE_PROPAGATED_CONTEXT, envelope);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.akkaactor;

import akka.dispatch.Envelope;
import akka.dispatch.sysmsg.SystemMessage;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;

public class VirtualFields {

private VirtualFields() {}

public static final VirtualField<Envelope, PropagatedContext> ENVELOPE_PROPAGATED_CONTEXT =
VirtualField.find(Envelope.class, PropagatedContext.class);
public static final VirtualField<SystemMessage, PropagatedContext>
SYSTEM_MESSAGE_PROPAGATED_CONTEXT =
VirtualField.find(SystemMessage.class, PropagatedContext.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import akka.dispatch.forkjoin.ForkJoinTask;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.bootstrap.executors.ExecutorAdviceHelper;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
Expand Down Expand Up @@ -51,9 +50,8 @@ public static class SetAkkaForkJoinStateAdvice {
public static PropagatedContext enterJobSubmit(@Advice.Argument(0) ForkJoinTask<?> task) {
Context context = Java8BytecodeBridge.currentContext();
if (ExecutorAdviceHelper.shouldPropagateContext(context, task)) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
return ExecutorAdviceHelper.attachContextToTask(context, virtualField, task);
return ExecutorAdviceHelper.attachContextToTask(
context, VirtualFields.FORK_JOIN_TASK_PROPAGATED_CONTEXT, task);
}
return null;
}
Expand All @@ -63,9 +61,8 @@ public static void exitJobSubmit(
@Advice.Argument(0) ForkJoinTask<?> task,
@Advice.Enter PropagatedContext propagatedContext,
@Advice.Thrown Throwable throwable) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable, virtualField, task);
ExecutorAdviceHelper.cleanUpAfterSubmit(
propagatedContext, throwable, VirtualFields.FORK_JOIN_TASK_PROPAGATED_CONTEXT, task);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import akka.dispatch.forkjoin.ForkJoinPool;
import akka.dispatch.forkjoin.ForkJoinTask;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
import io.opentelemetry.javaagent.bootstrap.executors.TaskAdviceHelper;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
Expand Down Expand Up @@ -62,14 +60,13 @@ public static class ForkJoinTaskAdvice {
*/
@Advice.OnMethodEnter(suppress = Throwable.class)
public static Scope enter(@Advice.This ForkJoinTask<?> thiz) {
VirtualField<ForkJoinTask<?>, PropagatedContext> virtualField =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
Scope scope = TaskAdviceHelper.makePropagatedContextCurrent(virtualField, thiz);
Scope scope =
TaskAdviceHelper.makePropagatedContextCurrent(
VirtualFields.FORK_JOIN_TASK_PROPAGATED_CONTEXT, thiz);
if (thiz instanceof Runnable) {
VirtualField<Runnable, PropagatedContext> runnableVirtualField =
VirtualField.find(Runnable.class, PropagatedContext.class);
Scope newScope =
TaskAdviceHelper.makePropagatedContextCurrent(runnableVirtualField, (Runnable) thiz);
TaskAdviceHelper.makePropagatedContextCurrent(
VirtualFields.RUNNABLE_PROPAGATED_CONTEXT, (Runnable) thiz);
if (null != newScope) {
if (null != scope) {
newScope.close();
Expand All @@ -79,10 +76,9 @@ public static Scope enter(@Advice.This ForkJoinTask<?> thiz) {
}
}
if (thiz instanceof Callable) {
VirtualField<Callable<?>, PropagatedContext> callableVirtualField =
VirtualField.find(Callable.class, PropagatedContext.class);
Scope newScope =
TaskAdviceHelper.makePropagatedContextCurrent(callableVirtualField, (Callable<?>) thiz);
TaskAdviceHelper.makePropagatedContextCurrent(
VirtualFields.CALLABLE_PROPAGATED_CONTEXT, (Callable<?>) thiz);
if (null != newScope) {
if (null != scope) {
newScope.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.akkaactor;

import akka.dispatch.forkjoin.ForkJoinTask;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.executors.PropagatedContext;
import java.util.concurrent.Callable;

public class VirtualFields {

private VirtualFields() {}

public static final VirtualField<ForkJoinTask<?>, PropagatedContext>
FORK_JOIN_TASK_PROPAGATED_CONTEXT =
VirtualField.find(ForkJoinTask.class, PropagatedContext.class);
public static final VirtualField<Runnable, PropagatedContext> RUNNABLE_PROPAGATED_CONTEXT =
VirtualField.find(Runnable.class, PropagatedContext.class);
public static final VirtualField<Callable<?>, PropagatedContext> CALLABLE_PROPAGATED_CONTEXT =
VirtualField.find(Callable.class, PropagatedContext.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import akka.http.scaladsl.model.Uri;
import akka.http.scaladsl.server.PathMatcher;
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;
Expand Down Expand Up @@ -41,7 +40,7 @@ public static void onEnter(
@Advice.Argument(0) Uri.Path prefix, @Advice.Return PathMatcher<?> result) {
// store the path being matched inside a VirtualField on the given matcher, so it can be used
// for constructing the route
VirtualField.find(PathMatcher.class, String.class).set(result, prefix.toString());
PathMatcherUtil.setMatched(result, prefix.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import akka.http.scaladsl.model.Uri;
import akka.http.scaladsl.server.PathMatcher;
import akka.http.scaladsl.server.PathMatchers;
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;
Expand Down Expand Up @@ -48,7 +47,7 @@ public static void onExit(
}
// if present use the matched path that was remembered in PathMatcherInstrumentation,
// otherwise just use a *
String prefix = VirtualField.find(PathMatcher.class, String.class).get(pathMatcher);
String prefix = PathMatcherUtil.getMatched(pathMatcher);
if (prefix == null) {
if (PathMatchers.Slash$.class == pathMatcher.getClass()) {
prefix = "/";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.akkahttp.server.route;

import akka.http.scaladsl.server.PathMatcher;
import io.opentelemetry.instrumentation.api.util.VirtualField;

public class PathMatcherUtil {

private static final VirtualField<PathMatcher<?>, String> PATH_MATCHER_ROUTE =
VirtualField.find(PathMatcher.class, String.class);

public static void setMatched(PathMatcher<?> matcher, String route) {
PATH_MATCHER_ROUTE.set(matcher, route);
}

public static String getMatched(PathMatcher<?> matcher) {
return PATH_MATCHER_ROUTE.get(matcher);
}

private PathMatcherUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.linecorp.armeria.server.ServiceRequestContext;
import io.grpc.ServerCall;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.instrumentation.grpc.v1_6.GrpcAuthorityStorage;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
Expand Down Expand Up @@ -43,7 +43,7 @@ public static void onExit(
// ArmeriaServerCall does not implement getAuthority. We will store the value for authority
// header as virtual field, this field is read in grpc instrumentation in
// TracingServerInterceptor
VirtualField.find(ServerCall.class, String.class).set(serverCall, authority);
GrpcAuthorityStorage.setAuthority(serverCall, authority);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.grpc.v1_6;

import io.grpc.ServerCall;
import io.opentelemetry.instrumentation.api.util.VirtualField;

/**
* In case a {@link ServerCall} implementation does not implement {@link ServerCall#getAuthority()}
* like armeria, this utility class should be used to provide the authority instead
*/
public class GrpcAuthorityStorage {

private static final VirtualField<ServerCall<?, ?>, String> AUTHORITY_FIELD =
VirtualField.find(ServerCall.class, String.class);

private GrpcAuthorityStorage() {}

public static void setAuthority(ServerCall<?, ?> call, String authority) {
AUTHORITY_FIELD.set(call, authority);
}

static String getAuthority(ServerCall<?, ?> call) {
return AUTHORITY_FIELD.get(call);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;

final class TracingServerInterceptor implements ServerInterceptor {
Expand All @@ -46,9 +45,6 @@ final class TracingServerInterceptor implements ServerInterceptor {
private static final AtomicLongFieldUpdater<TracingServerCall> RECEIVED_MESSAGE_ID_UPDATER =
AtomicLongFieldUpdater.newUpdater(TracingServerCall.class, "receivedMessageId");

private static final VirtualField<ServerCall<?, ?>, String> AUTHORITY_FIELD =
VirtualField.find(ServerCall.class, String.class);

private final Instrumenter<GrpcRequest, Status> instrumenter;
private final boolean captureExperimentalSpanAttributes;
private final boolean emitMessageEvents;
Expand All @@ -72,7 +68,7 @@ public <REQUEST, RESPONSE> ServerCall.Listener<REQUEST> interceptCall(
// Armeria grpc server call does not implement getAuthority(). In
// ArmeriaServerCallInstrumentation we store the value for the authority header in a virtual
// field.
authority = AUTHORITY_FIELD.get(call);
authority = GrpcAuthorityStorage.getAuthority(call);
}
GrpcRequest request =
new GrpcRequest(
Expand Down
Loading