make azure-core indy-ready (#14681)
This commit is contained in:
parent
7b00732fa8
commit
2caff625dd
|
|
@ -15,6 +15,7 @@ import com.azure.core.http.HttpResponse;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
import net.bytebuddy.asm.Advice.AssignReturned;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
@ -39,9 +40,10 @@ public class AzureHttpClientInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class SuppressNestedClientAdvice {
|
public static class SuppressNestedClientAdvice {
|
||||||
|
|
||||||
|
@AssignReturned.ToReturned
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void methodExit(@Advice.Return(readOnly = false) Mono<HttpResponse> mono) {
|
public static Mono<HttpResponse> methodExit(@Advice.Return Mono<HttpResponse> mono) {
|
||||||
mono = new SuppressNestedClientMono<>(mono);
|
return new SuppressNestedClientMono<>(mono);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,9 @@ public class AzureSdkInstrumentationModule extends InstrumentationModule
|
||||||
// Nothing to instrument, no methods to match
|
// Nothing to instrument, no methods to match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndyReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import com.azure.core.http.HttpResponse;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
import net.bytebuddy.asm.Advice.AssignReturned;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
@ -39,9 +40,10 @@ public class AzureHttpClientInstrumentation implements TypeInstrumentation {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class SuppressNestedClientAdvice {
|
public static class SuppressNestedClientAdvice {
|
||||||
|
|
||||||
|
@AssignReturned.ToReturned
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void methodExit(@Advice.Return(readOnly = false) Mono<HttpResponse> mono) {
|
public static Mono<HttpResponse> methodExit(@Advice.Return Mono<HttpResponse> mono) {
|
||||||
mono = new SuppressNestedClientMono<>(mono);
|
return new SuppressNestedClientMono<>(mono);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,9 @@ public class AzureSdkInstrumentationModule extends InstrumentationModule
|
||||||
// Nothing to instrument, no methods to match
|
// Nothing to instrument, no methods to match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndyReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@ import com.azure.core.http.HttpResponse;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
import net.bytebuddy.asm.Advice.AssignReturned;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
@ -50,27 +52,26 @@ public class AzureHttpClientInstrumentation implements TypeInstrumentation {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class SuppressNestedClientMonoAdvice {
|
public static class SuppressNestedClientMonoAdvice {
|
||||||
|
@AssignReturned.ToReturned
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void asyncSendExit(
|
public static Mono<HttpResponse> asyncSendExit(
|
||||||
@Advice.Argument(1) com.azure.core.util.Context azContext,
|
@Advice.Argument(1) com.azure.core.util.Context azContext,
|
||||||
@Advice.Return(readOnly = false) Mono<HttpResponse> mono) {
|
@Advice.Return Mono<HttpResponse> mono) {
|
||||||
mono = disallowNestedClientSpanMono(mono, azContext);
|
return disallowNestedClientSpanMono(mono, azContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static class SuppressNestedClientSyncAdvice {
|
public static class SuppressNestedClientSyncAdvice {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
public static void syncSendEnter(
|
public static Scope syncSendEnter(@Advice.Argument(1) com.azure.core.util.Context azContext) {
|
||||||
@Advice.Argument(1) com.azure.core.util.Context azContext,
|
return disallowNestedClientSpanSync(azContext);
|
||||||
@Advice.Local("otelScope") Scope scope) {
|
|
||||||
scope = disallowNestedClientSpanSync(azContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void syncSendExit(
|
public static void syncSendExit(@Advice.Enter @Nullable Scope scope) {
|
||||||
@Advice.Return HttpResponse response, @Advice.Local("otelScope") Scope scope) {
|
|
||||||
if (scope != null) {
|
if (scope != null) {
|
||||||
scope.close();
|
scope.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,9 @@ public class AzureSdkInstrumentationModule extends InstrumentationModule
|
||||||
// Nothing to instrument, no methods to match
|
// Nothing to instrument, no methods to match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIndyReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@ import io.opentelemetry.api.trace.Span;
|
||||||
import io.opentelemetry.context.Context;
|
import io.opentelemetry.context.Context;
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import io.opentelemetry.instrumentation.api.internal.SpanKey;
|
import io.opentelemetry.instrumentation.api.internal.SpanKey;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import reactor.core.CoreSubscriber;
|
import reactor.core.CoreSubscriber;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public class SuppressNestedClientHelper {
|
public class SuppressNestedClientHelper {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Scope disallowNestedClientSpanSync(com.azure.core.util.Context azContext) {
|
public static Scope disallowNestedClientSpanSync(com.azure.core.util.Context azContext) {
|
||||||
Context parentContext = currentContext();
|
Context parentContext = currentContext();
|
||||||
boolean hasAzureClientSpan = azContext.getData("client-method-call-flag").isPresent();
|
boolean hasAzureClientSpan = azContext.getData("client-method-call-flag").isPresent();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue