-
Notifications
You must be signed in to change notification settings - Fork 1k
make javaagent-tooling and testing-common indy-ready #15133
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
Changes from 17 commits
1d8900b
6c4c934
49b6dc2
2a2b04f
2a7b0e3
340c519
723b3f7
37219a3
4543aec
0eb25d9
6f01994
9bad366
420a1ae
d9c04c3
b743787
033d6f7
e704500
1ea0d57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,17 @@ | |
|
|
||
| package context; | ||
|
|
||
| import static context.ContextTestSingletons.CONTEXT; | ||
| import static context.ContextTestSingletons.INTEGER; | ||
| import static context.ContextTestSingletons.INTERFACE_INTEGER; | ||
| import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
|
||
| import io.opentelemetry.instrumentation.api.util.VirtualField; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import library.KeyClass; | ||
| import library.KeyInterface; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.asm.Advice.AssignReturned; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
|
|
@@ -42,78 +44,71 @@ public void transform(TypeTransformer transformer) { | |
|
|
||
| @SuppressWarnings("unused") | ||
| public static class MarkInstrumentedAdvice { | ||
| @AssignReturned.ToReturned | ||
| @Advice.OnMethodExit | ||
| public static void methodExit(@Advice.Return(readOnly = false) boolean isInstrumented) { | ||
| isInstrumented = true; | ||
| public static boolean methodExit() { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class StoreAndIncrementApiUsageAdvice { | ||
| @AssignReturned.ToReturned | ||
| @Advice.OnMethodExit | ||
| public static void methodExit( | ||
| @Advice.This KeyClass thiz, @Advice.Return(readOnly = false) int contextCount) { | ||
|
|
||
| VirtualField<KeyClass, Context> virtualField = | ||
| VirtualField.find(KeyClass.class, Context.class); | ||
|
|
||
| Context context = virtualField.get(thiz); | ||
| public static int methodExit(@Advice.This KeyClass thiz) { | ||
| Context context = CONTEXT.get(thiz); | ||
| if (context == null) { | ||
| context = new Context(); | ||
| virtualField.set(thiz, context); | ||
| CONTEXT.set(thiz, context); | ||
| } | ||
|
|
||
| contextCount = ++context.count; | ||
| return ++context.count; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class GetApiUsageAdvice { | ||
|
|
||
| @Advice.OnMethodEnter(skipOn = Advice.OnNonDefaultValue.class) | ||
| public static boolean methodEnter() { | ||
| // always skip original method body | ||
| return true; | ||
| } | ||
|
Comment on lines
+72
to
+76
Contributor
Author
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. [for reviewer] Without this the original return value |
||
|
|
||
| @AssignReturned.ToReturned | ||
| @Advice.OnMethodExit | ||
| public static void methodExit( | ||
| @Advice.This KeyClass thiz, @Advice.Return(readOnly = false) int contextCount) { | ||
| VirtualField<KeyClass, Context> virtualField = | ||
| VirtualField.find(KeyClass.class, Context.class); | ||
| Context context = virtualField.get(thiz); | ||
| contextCount = context == null ? 0 : context.count; | ||
| public static int methodExit(@Advice.This KeyClass thiz) { | ||
| Context context = CONTEXT.get(thiz); | ||
| return context == null ? 0 : context.count; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class PutApiUsageAdvice { | ||
| @Advice.OnMethodExit | ||
| public static void methodExit(@Advice.This KeyClass thiz, @Advice.Argument(0) int value) { | ||
| VirtualField<KeyClass, Context> virtualField = | ||
| VirtualField.find(KeyClass.class, Context.class); | ||
| Context context = new Context(); | ||
| context.count = value; | ||
| virtualField.set(thiz, context); | ||
| CONTEXT.set(thiz, context); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class RemoveApiUsageAdvice { | ||
| @Advice.OnMethodExit | ||
| public static void methodExit(@Advice.This KeyClass thiz) { | ||
| VirtualField<KeyClass, Context> virtualField = | ||
| VirtualField.find(KeyClass.class, Context.class); | ||
| virtualField.set(thiz, null); | ||
| CONTEXT.set(thiz, null); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class UseMultipleFieldsAdvice { | ||
| @Advice.OnMethodExit | ||
| public static void methodExit(@Advice.This KeyClass thiz) { | ||
| VirtualField<KeyClass, Context> field1 = VirtualField.find(KeyClass.class, Context.class); | ||
| VirtualField<KeyClass, Integer> field2 = VirtualField.find(KeyClass.class, Integer.class); | ||
| VirtualField<KeyInterface, Integer> interfaceField = | ||
| VirtualField.find(KeyInterface.class, Integer.class); | ||
|
|
||
| Context context = field1.get(thiz); | ||
| Context context = CONTEXT.get(thiz); | ||
| int count = context == null ? 0 : context.count; | ||
| field2.set(thiz, count); | ||
| interfaceField.set(thiz, count); | ||
| INTEGER.set(thiz, count); | ||
| INTERFACE_INTEGER.set(thiz, count); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package context; | ||
|
|
||
| import io.opentelemetry.instrumentation.api.util.VirtualField; | ||
| import library.KeyClass; | ||
| import library.KeyInterface; | ||
|
|
||
| public class ContextTestSingletons { | ||
|
|
||
| public static final VirtualField<KeyClass, Context> CONTEXT = | ||
| VirtualField.find(KeyClass.class, Context.class); | ||
| public static final VirtualField<KeyClass, Integer> INTEGER = | ||
| VirtualField.find(KeyClass.class, Integer.class); | ||
| public static final VirtualField<KeyInterface, Integer> INTERFACE_INTEGER = | ||
| VirtualField.find(KeyInterface.class, Integer.class); | ||
|
|
||
| private ContextTestSingletons() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,12 +176,11 @@ public static void onMethodEnter() { | |
| throw new RuntimeException("This exception should be suppressed"); | ||
| } | ||
|
|
||
| @Advice.AssignReturned.ToReturned | ||
| @Advice.OnMethodExit( | ||
| suppress = Throwable.class, | ||
| onThrowable = Throwable.class, | ||
| inline = false) | ||
| public static void onMethodExit(@Advice.Thrown Throwable throwable) { | ||
|
Contributor
Author
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. removing unused argument and useless annotation (advice returns void) |
||
| public static void onMethodExit() { | ||
| throw new RuntimeException("This exception should be suppressed"); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.