-
Couldn't load subscription status.
- Fork 1k
fix instrumentation module not loading silently when duplicate helper… #13005
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 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
df9158c
Add test for duplicate helper class
laurit f9eb7cb
fix instrumentation module not loading silently when duplicate helper…
FlorianBruckner 3b19c67
Merge pull request #1 from laurit/duplicate-helper-test
FlorianBruckner 576ef17
spotless fixes for test cases
FlorianBruckner 2d06080
Fix indy test suite
FlorianBruckner 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
14 changes: 14 additions & 0 deletions
14
testing-common/integration-tests/src/main/java/helper/DuplicateHelper.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,14 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package helper; | ||
|
|
||
| public class DuplicateHelper { | ||
| public static String addSuffix(String string, String suffix) { | ||
| return string + suffix; | ||
| } | ||
|
|
||
| private DuplicateHelper() {} | ||
| } |
34 changes: 34 additions & 0 deletions
34
testing-common/integration-tests/src/main/java/helper/DuplicateHelperInstrumentation.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,34 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package helper; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
|
||
| 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; | ||
|
|
||
| public class DuplicateHelperInstrumentation implements TypeInstrumentation { | ||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named("helper.DuplicateHelperTestClass"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod(named("transform"), this.getClass().getName() + "$TestAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class TestAdvice { | ||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| static void addSuffix(@Advice.Return(readOnly = false) String string) { | ||
| string = DuplicateHelper.addSuffix(string, " foo"); | ||
| } | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
...g-common/integration-tests/src/main/java/helper/DuplicateHelperInstrumentationModule.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,37 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package helper; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class DuplicateHelperInstrumentationModule extends InstrumentationModule { | ||
| public DuplicateHelperInstrumentationModule() { | ||
| super("duplicate-helper"); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getAdditionalHelperClassNames() { | ||
| // muzzle adds the same class as helper, listing it twice to ensure it doesn't fail | ||
| return Arrays.asList("helper.DuplicateHelper", "helper.DuplicateHelper"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isHelperClass(String className) { | ||
| return "helper.DuplicateHelper".equals(className); | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return singletonList(new DuplicateHelperInstrumentation()); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
testing-common/integration-tests/src/test/java/helper/DuplicateHelperTest.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,19 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package helper; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class DuplicateHelperTest { | ||
|
|
||
| @Test | ||
| void duplicateHelper() { | ||
| String string = DuplicateHelperTestClass.transform("test"); | ||
| assertThat(string).isEqualTo("test foo"); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
testing-common/integration-tests/src/test/java/helper/DuplicateHelperTestClass.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,16 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package helper; | ||
|
|
||
| class DuplicateHelperTestClass { | ||
|
|
||
| // this method is transformed by instrumentation | ||
| public static String transform(String string) { | ||
| return string; | ||
| } | ||
|
|
||
| private DuplicateHelperTestClass() {} | ||
| } |
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.