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 @@ -20,7 +20,10 @@
import io.opentelemetry.context.Scope;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import okhttp3.Call;
Expand Down Expand Up @@ -55,19 +58,21 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class BuildRequestAdvice {

@AssignReturned.ToReturned
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(@Advice.Return(readOnly = false) Request request) {
public static Request onExit(@Advice.Return Request originalReturnValue) {
Context parentContext = currentContext();
if (!instrumenter().shouldStart(parentContext, request)) {
return;
if (!instrumenter().shouldStart(parentContext, originalReturnValue)) {
return originalReturnValue;
}

Context context = instrumenter().start(parentContext, request);
Context context = instrumenter().start(parentContext, originalReturnValue);
Scope scope = context.makeCurrent();
Request.Builder requestWithPropagation = request.newBuilder();
Request.Builder requestWithPropagation = originalReturnValue.newBuilder();
inject(context, requestWithPropagation);
request = requestWithPropagation.build();
Request request = requestWithPropagation.build();
CurrentState.set(parentContext, context, scope, request);
return request;
}
}

Expand Down Expand Up @@ -96,39 +101,34 @@ public static void onExit(
@SuppressWarnings("unused")
public static class ExecuteAsyncAdvice {

@AssignReturned.ToArguments(@ToArgument(value = 2, index = 1))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.Argument(0) Call httpCall,
@Advice.Argument(value = 2, readOnly = false) ApiCallback<?> callback,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope,
@Advice.Local("otelRequest") Request request) {
public static Object[] onEnter(
@Advice.Argument(0) Call httpCall, @Advice.Argument(2) ApiCallback<?> originalCallback) {
CurrentState current = CurrentState.remove();
if (current == null) {
return;
return new Object[] {null, originalCallback};
}

context = current.getContext();
scope = current.getScope();
request = current.getRequest();
callback = new TracingApiCallback<>(callback, current.getParentContext(), context, request);
ApiCallback<?> callback =
new TracingApiCallback<>(
originalCallback,
current.getParentContext(),
current.getContext(),
current.getRequest());
return new Object[] {current, callback};
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void onExit(
@Advice.Thrown Throwable throwable,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope,
@Advice.Local("otelRequest") Request request) {
if (scope == null) {
return;
}
scope.close();

if (throwable != null) {
instrumenter().end(context, request, null, throwable);
@Advice.Thrown @Nullable Throwable throwable, @Advice.Enter Object[] enterResult) {
CurrentState current = (CurrentState) enterResult[0];
if (current != null) {
current.getScope().close();
if (throwable != null) {
instrumenter().end(current.getContext(), current.getRequest(), null, throwable);
}
// else span will be ended in the TracingApiCallback
}
// else span will be ended in the TracingApiCallback
}
}
}
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 KubernetesClientInstrumentationModule extends InstrumentationModule {
public class KubernetesClientInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public KubernetesClientInstrumentationModule() {
super("kubernetes-client", "kubernetes-client-7.0");
Expand All @@ -23,4 +25,9 @@ public KubernetesClientInstrumentationModule() {
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new ApiClientInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Loading