-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
443 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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
6 changes: 6 additions & 0 deletions
6
.../jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/jaxrs-2.0-resteasy-common-javaagent.gradle
This file contains 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,6 @@ | ||
apply from: "$rootDir/gradle/instrumentation.gradle" | ||
|
||
dependencies { | ||
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' | ||
compileOnly group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.0.Final' | ||
} |
72 changes: 72 additions & 0 deletions
72
...y/javaagent/instrumentation/jaxrs/v2_0/ResteasyResourceLocatorInvokerInstrumentation.java
This file contains 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,72 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.instrumentation.api.jaxrs.JaxrsContextPath; | ||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.jboss.resteasy.core.ResourceLocatorInvoker; | ||
|
||
public class ResteasyResourceLocatorInvokerInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.jboss.resteasy.core.ResourceLocatorInvoker"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return singletonMap( | ||
named("invokeOnTargetObject") | ||
.and(takesArgument(0, named("org.jboss.resteasy.spi.HttpRequest"))) | ||
.and(takesArgument(1, named("org.jboss.resteasy.spi.HttpResponse"))) | ||
.and(takesArgument(2, Object.class)), | ||
ResteasyResourceLocatorInvokerInstrumentation.class.getName() | ||
+ "$InvokeOnTargetObjectAdvice"); | ||
} | ||
|
||
public static class InvokeOnTargetObjectAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.This ResourceLocatorInvoker resourceInvoker, | ||
@Advice.Local("otelScope") Scope scope) { | ||
|
||
Context currentContext = Java8BytecodeBridge.currentContext(); | ||
|
||
String name = | ||
InstrumentationContext.get(ResourceLocatorInvoker.class, String.class) | ||
.get(resourceInvoker); | ||
ResteasyTracingUtil.updateServerSpanName(currentContext, name); | ||
|
||
// subresource locator returns a resources class that may have @Path annotations | ||
// append current path to jax-rs context path so that it would be present in the final path | ||
Context context = | ||
JaxrsContextPath.init(currentContext, JaxrsContextPath.prepend(currentContext, name)); | ||
if (context != null) { | ||
scope = context.makeCurrent(); | ||
} | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void stopSpan(@Advice.Local("otelScope") Scope scope) { | ||
if (scope != null) { | ||
scope.close(); | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ry/javaagent/instrumentation/jaxrs/v2_0/ResteasyResourceMethodInvokerInstrumentation.java
This file contains 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,49 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.jboss.resteasy.core.ResourceMethodInvoker; | ||
|
||
public class ResteasyResourceMethodInvokerInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.jboss.resteasy.core.ResourceMethodInvoker"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return singletonMap( | ||
named("invokeOnTarget") | ||
.and(takesArgument(0, named("org.jboss.resteasy.spi.HttpRequest"))) | ||
.and(takesArgument(1, named("org.jboss.resteasy.spi.HttpResponse"))) | ||
.and(takesArgument(2, Object.class)), | ||
ResteasyResourceMethodInvokerInstrumentation.class.getName() + "$InvokeOnTargetAdvice"); | ||
} | ||
|
||
public static class InvokeOnTargetAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter(@Advice.This ResourceMethodInvoker resourceInvoker) { | ||
|
||
String name = | ||
InstrumentationContext.get(ResourceMethodInvoker.class, String.class) | ||
.get(resourceInvoker); | ||
ResteasyTracingUtil.updateServerSpanName(Java8BytecodeBridge.currentContext(), name); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...entelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasyRootNodeTypeInstrumentation.java
This file contains 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,63 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.implementation.bytecode.assign.Assigner; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.jboss.resteasy.core.ResourceLocatorInvoker; | ||
import org.jboss.resteasy.core.ResourceMethodInvoker; | ||
|
||
public class ResteasyRootNodeTypeInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.jboss.resteasy.core.registry.RootNode"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
Map<ElementMatcher<MethodDescription>, String> transformers = new HashMap<>(); | ||
transformers.put( | ||
named("addInvoker") | ||
.and(takesArgument(0, String.class)) | ||
// package of ResourceInvoker was changed in reasteasy 4 | ||
.and( | ||
takesArgument( | ||
1, | ||
named("org.jboss.resteasy.core.ResourceInvoker") | ||
.or(named("org.jboss.resteasy.spi.ResourceInvoker")))), | ||
ResteasyRootNodeTypeInstrumentation.class.getName() + "$AddInvokerAdvice"); | ||
|
||
return transformers; | ||
} | ||
|
||
public static class AddInvokerAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void addInvoker( | ||
@Advice.Argument(0) String path, | ||
@Advice.Argument(value = 1, typing = Assigner.Typing.DYNAMIC) Object invoker) { | ||
String normalizedPath = ResteasyTracingUtil.normalizePath(path); | ||
if (invoker instanceof ResourceLocatorInvoker) { | ||
ResourceLocatorInvoker resourceLocatorInvoker = (ResourceLocatorInvoker) invoker; | ||
InstrumentationContext.get(ResourceLocatorInvoker.class, String.class) | ||
.put(resourceLocatorInvoker, normalizedPath); | ||
} else if (invoker instanceof ResourceMethodInvoker) { | ||
ResourceMethodInvoker resourceMethodInvoker = (ResourceMethodInvoker) invoker; | ||
InstrumentationContext.get(ResourceMethodInvoker.class, String.class) | ||
.put(resourceMethodInvoker, normalizedPath); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.