-
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1d8900b
javaagent-tooling
SylvainJuge 6c4c934
testing-common
SylvainJuge 49b6dc2
add missing file
SylvainJuge 2a2b04f
fix AssignReturned.ToReturned
SylvainJuge 2a7b0e3
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 340c519
fix things
SylvainJuge 723b3f7
fix helper class visibility
SylvainJuge 37219a3
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 4543aec
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 0eb25d9
skip get original return value
SylvainJuge 6f01994
remove useless argument
SylvainJuge 9bad366
post-review changes
SylvainJuge 420a1ae
fix api change
SylvainJuge d9c04c3
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge b743787
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 033d6f7
minor changes
SylvainJuge e704500
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 1ea0d57
simplify
laurit 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
Some comments aren't visible on the classic Files Changed page.
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
| 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); | ||
| } | ||
| } | ||
| } | ||
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
22 changes: 22 additions & 0 deletions
22
testing-common/integration-tests/src/main/java/context/ContextTestSingletons.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,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() {} | ||
| } |
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
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.