-
Notifications
You must be signed in to change notification settings - Fork 1k
Support latest Azure SDK shim #15068
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
instrumentation/azure-core/azure-core-1.53/javaagent/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| muzzle { | ||
| pass { | ||
| group.set("com.azure") | ||
| module.set("azure-core") | ||
| versions.set("[1.53.0,)") | ||
| assertInverse.set(true) | ||
| } | ||
| } | ||
|
|
||
| sourceSets { | ||
| main { | ||
| val shadedDep = project(":instrumentation:azure-core:azure-core-1.53:library-instrumentation-shaded") | ||
| output.dir( | ||
| shadedDep.file("build/extracted/shadow"), | ||
| "builtBy" to ":instrumentation:azure-core:azure-core-1.53:library-instrumentation-shaded:extractShadowJar" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly(project(":instrumentation:azure-core:azure-core-1.53:library-instrumentation-shaded", configuration = "shadow")) | ||
|
|
||
| library("com.azure:azure-core:1.53.0") | ||
|
|
||
| // Ensure no cross interference | ||
| testInstrumentation(project(":instrumentation:azure-core:azure-core-1.14:javaagent")) | ||
| testInstrumentation(project(":instrumentation:azure-core:azure-core-1.19:javaagent")) | ||
| testInstrumentation(project(":instrumentation:azure-core:azure-core-1.36:javaagent")) | ||
| } | ||
|
|
||
| val latestDepTest = findProperty("testLatestDeps") as Boolean | ||
|
|
||
| tasks { | ||
| withType<Test>().configureEach { | ||
| systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) | ||
| } | ||
| } | ||
|
|
||
| testing { | ||
| suites { | ||
| // using a test suite to ensure that classes from library-instrumentation-shaded that were | ||
| // extracted to the output directory are not available during tests | ||
| val testAzure by registering(JvmTestSuite::class) { | ||
| dependencies { | ||
| if (latestDepTest) { | ||
| implementation("com.azure:azure-core:latest.release") | ||
| implementation("com.azure:azure-core-test:latest.release") | ||
| } else { | ||
| implementation("com.azure:azure-core:1.53.0") | ||
| implementation("com.azure:azure-core-test:1.26.2") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks { | ||
| check { | ||
| dependsOn(testing.suites) | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...entelemetry/javaagent/instrumentation/azurecore/v1_53/AzureHttpClientInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.azurecore.v1_53; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; | ||
| import static io.opentelemetry.javaagent.instrumentation.azurecore.v1_53.SuppressNestedClientHelper.disallowNestedClientSpanMono; | ||
| import static io.opentelemetry.javaagent.instrumentation.azurecore.v1_53.SuppressNestedClientHelper.disallowNestedClientSpanSync; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.returns; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
|
||
| import com.azure.core.http.HttpResponse; | ||
| 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.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| public class AzureHttpClientInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return implementsInterface(named("com.azure.core.http.HttpClient")); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| isMethod() | ||
| .and(isPublic()) | ||
| .and(named("send")) | ||
| .and(takesArgument(1, named("com.azure.core.util.Context"))) | ||
| .and(returns(named("reactor.core.publisher.Mono"))), | ||
| this.getClass().getName() + "$SuppressNestedClientMonoAdvice"); | ||
| transformer.applyAdviceToMethod( | ||
| isMethod() | ||
| .and(isPublic()) | ||
| .and(named("sendSync")) | ||
| .and(takesArgument(1, named("com.azure.core.util.Context"))) | ||
| .and(returns(named("com.azure.core.http.HttpResponse"))), | ||
| this.getClass().getName() + "$SuppressNestedClientSyncAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class SuppressNestedClientMonoAdvice { | ||
| @AssignReturned.ToReturned | ||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static Mono<HttpResponse> asyncSendExit( | ||
| @Advice.Argument(1) com.azure.core.util.Context azContext, | ||
| @Advice.Return Mono<HttpResponse> mono) { | ||
| return disallowNestedClientSpanMono(mono, azContext); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class SuppressNestedClientSyncAdvice { | ||
|
|
||
| @Nullable | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static Scope syncSendEnter(@Advice.Argument(1) com.azure.core.util.Context azContext) { | ||
| return disallowNestedClientSpanSync(azContext); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void syncSendExit(@Advice.Enter @Nullable Scope scope) { | ||
| if (scope != null) { | ||
| scope.close(); | ||
| } | ||
| } | ||
| } | ||
| } |
85 changes: 85 additions & 0 deletions
85
...pentelemetry/javaagent/instrumentation/azurecore/v1_53/AzureSdkInstrumentationModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.azurecore.v1_53; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
| import static java.util.Arrays.asList; | ||
| import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
| import static net.bytebuddy.matcher.ElementMatchers.not; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.internal.injection.ClassInjector; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.internal.injection.InjectionMode; | ||
| import java.util.List; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class AzureSdkInstrumentationModule extends InstrumentationModule | ||
| implements ExperimentalInstrumentationModule { | ||
| public AzureSdkInstrumentationModule() { | ||
| super("azure-core", "azure-core-1.53"); | ||
| } | ||
|
|
||
| @Override | ||
| public void registerHelperResources(HelperResourceBuilder helperResourceBuilder) { | ||
| helperResourceBuilder.register( | ||
| "META-INF/services/com.azure.core.util.tracing.TracerProvider", | ||
| "azure-core-1.53/META-INF/services/com.azure.core.util.tracing.TracerProvider"); | ||
| // some azure sdks (e.g. EventHubs) are still looking up Tracer via service loader | ||
| // and not yet using the new TracerProvider | ||
| helperResourceBuilder.register( | ||
| "META-INF/services/com.azure.core.util.tracing.Tracer", | ||
| "azure-core-1.53/META-INF/services/com.azure.core.util.tracing.Tracer"); | ||
| } | ||
|
|
||
| @Override | ||
| public void injectClasses(ClassInjector injector) { | ||
| injector | ||
| .proxyBuilder( | ||
| "io.opentelemetry.javaagent.instrumentation.azurecore.v1_53.shaded.com.azure.core.tracing.opentelemetry.OpenTelemetryTracer") | ||
| .inject(InjectionMode.CLASS_ONLY); | ||
| injector | ||
| .proxyBuilder( | ||
| "io.opentelemetry.javaagent.instrumentation.azurecore.v1_53.shaded.com.azure.core.tracing.opentelemetry.OpenTelemetryTracerProvider") | ||
| .inject(InjectionMode.CLASS_ONLY); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
| // LibraryTelemetryOptions was introduced in azure-core 1.53 | ||
| return hasClassesNamed("com.azure.core.util.LibraryTelemetryOptions") | ||
|
Comment on lines
+58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this class is straight copy from 1.36 except for this method |
||
| .and(not(hasClassesNamed("com.azure.core.tracing.opentelemetry.OpenTelemetryTracer"))); | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return asList(new EmptyTypeInstrumentation(), new AzureHttpClientInstrumentation()); | ||
| } | ||
|
|
||
| public static class EmptyTypeInstrumentation implements TypeInstrumentation { | ||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return namedOneOf( | ||
| "com.azure.core.util.tracing.TracerProvider", "com.azure.core.util.tracing.Tracer"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| // Nothing to instrument, no methods to match | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isIndyReady() { | ||
| return true; | ||
| } | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
...o/opentelemetry/javaagent/instrumentation/azurecore/v1_53/SuppressNestedClientHelper.java
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. straight copy from 1.36 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.azurecore.v1_53; | ||
|
|
||
| import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; | ||
|
|
||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.Scope; | ||
| import io.opentelemetry.instrumentation.api.internal.SpanKey; | ||
| import javax.annotation.Nullable; | ||
| import reactor.core.CoreSubscriber; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| public class SuppressNestedClientHelper { | ||
|
|
||
| @Nullable | ||
| public static Scope disallowNestedClientSpanSync(com.azure.core.util.Context azContext) { | ||
| Context parentContext = currentContext(); | ||
| boolean hasAzureClientSpan = azContext.getData("client-method-call-flag").isPresent(); | ||
| if (doesNotHaveClientSpan(parentContext) && hasAzureClientSpan) { | ||
| return disallowNestedClientSpan(parentContext).makeCurrent(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public static <T> Mono<T> disallowNestedClientSpanMono( | ||
| Mono<T> delegate, com.azure.core.util.Context azContext) { | ||
| return new Mono<T>() { | ||
| @Override | ||
| public void subscribe(CoreSubscriber<? super T> coreSubscriber) { | ||
| Context parentContext = currentContext(); | ||
|
|
||
| boolean hasAzureClientSpan = azContext.getData("client-method-call-flag").isPresent(); | ||
| if (doesNotHaveClientSpan(parentContext) && hasAzureClientSpan) { | ||
| try (Scope ignored = disallowNestedClientSpan(parentContext).makeCurrent()) { | ||
| delegate.subscribe(coreSubscriber); | ||
| } | ||
| } else { | ||
| delegate.subscribe(coreSubscriber); | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private static boolean doesNotHaveClientSpan(Context parentContext) { | ||
| return SpanKey.KIND_CLIENT.fromContextOrNull(parentContext) == null | ||
| && SpanKey.HTTP_CLIENT.fromContextOrNull(parentContext) == null; | ||
| } | ||
|
|
||
| private static Context disallowNestedClientSpan(Context parentContext) { | ||
| Span span = Span.getInvalid(); | ||
| return SpanKey.HTTP_CLIENT.storeInContext( | ||
| SpanKey.KIND_CLIENT.storeInContext(parentContext, span), span); | ||
| } | ||
|
|
||
| private SuppressNestedClientHelper() {} | ||
| } |
1 change: 1 addition & 0 deletions
1
...t/src/main/resources/azure-core-1.53/META-INF/services/com.azure.core.util.tracing.Tracer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.opentelemetry.javaagent.instrumentation.azurecore.v1_53.shaded.com.azure.core.tracing.opentelemetry.OpenTelemetryTracer |
1 change: 1 addition & 0 deletions
1
...in/resources/azure-core-1.53/META-INF/services/com.azure.core.util.tracing.TracerProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.opentelemetry.javaagent.instrumentation.azurecore.v1_53.shaded.com.azure.core.tracing.opentelemetry.OpenTelemetryTracerProvider |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
straight copy from 1.36