-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix azure-core nested HTTP suppression, update libs #12489
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
trask
merged 9 commits into
open-telemetry:main
from
lmolkova:azure-core-update-and-fix-suppression
Oct 26, 2024
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
67ee3d7
Fix HTTP suppression in azure-core instrumentation
ed22dc2
More fixes
e247e56
Address feedback, add tests, update changelog, lint
7adffc6
up
e41ce9e
fix some test failures
d473a59
fix more tests
a1c3408
simplify
trask 52a7f50
feedback
trask 65d6f00
spotless
trask 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
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
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
| 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 | ||
|
|
||
| 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:+") | ||
| implementation("com.azure:azure-core-test:+") | ||
| } else { | ||
| implementation("com.azure:azure-core:1.53.0") | ||
| implementation("com.azure:azure-core-test:1.26.2") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks { | ||
| check { | ||
| dependsOn(testing.suites) | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
...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,79 @@ | ||
| /* | ||
| * 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 net.bytebuddy.asm.Advice; | ||
| 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 { | ||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void asyncSendExit( | ||
| @Advice.Argument(1) com.azure.core.util.Context azContext, | ||
| @Advice.Return(readOnly = false) Mono<HttpResponse> mono) { | ||
| mono = disallowNestedClientSpanMono(mono, azContext); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class SuppressNestedClientSyncAdvice { | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void syncSendEnter( | ||
| @Advice.Argument(1) com.azure.core.util.Context azContext, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
| scope = disallowNestedClientSpanSync(azContext); | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void syncSendExit( | ||
| @Advice.Return HttpResponse response, @Advice.Local("otelScope") Scope scope) { | ||
| if (scope != null) { | ||
| scope.close(); | ||
| } | ||
| } | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...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,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.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() { | ||
| // this class was introduced in azure-core 1.53 | ||
| return hasClassesNamed("com.azure.core.util.LibraryTelemetryOptions") | ||
| .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 | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.