Skip to content

Commit

Permalink
Fix AWS tests for indy, enable for testing with indy flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz committed Oct 2, 2023
1 parent 80dee2f commit 5adf59e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public boolean isHelperClass(String className) {
return className.startsWith("io.opentelemetry.contrib.awsxray.");
}

@Override
public boolean isIndyModule() {
return false;
}

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// We don't actually transform it but want to make sure we only apply the instrumentation when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import io.opentelemetry.javaagent.extension.instrumentation.internal.injection.ClassInjector;
import io.opentelemetry.javaagent.extension.instrumentation.internal.injection.ExtendedInstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.internal.injection.InjectionMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class AwsSdkInstrumentationModule extends AbstractAwsSdkInstrumentationModule
Expand All @@ -21,6 +24,35 @@ public AwsSdkInstrumentationModule() {
super("aws-sdk-2.2-core");
}

@Override
@SuppressWarnings("unchecked")
public List<String> getAdditionalHelperClassNames() {
if (isIndyModule()) {
// With the invokedynamic approach, the SnsInstrumentationModule and SqsInstrumentationModule
// are not required anymore, because we don't inject the helpers which reference potentially
// missing classes
// Instead, those are loaded by the InstrumentationModuleClassloader and LinkageErrors are
// caught just like when using those classes as library instrumentation
List<String> helpers = new ArrayList<>();
InstrumentationModule[] modules = {
new SnsInstrumentationModule(), new SqsInstrumentationModule()
};
for (InstrumentationModule include : modules) {
try {
List<String> moduleRefs =
(List<String>)
include.getClass().getDeclaredMethod("getMuzzleHelperClassNames").invoke(include);
helpers.addAll(moduleRefs);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
return helpers;
} else {
return Collections.emptyList();
}
}

/**
* Injects resource file with reference to our {@link TracingExecutionInterceptor} to allow SDK's
* service loading mechanism to pick it up.
Expand Down

0 comments on commit 5adf59e

Please sign in to comment.