Skip to content
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

Support OpenTelemetry extension helpers #7127

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public final class OtelInstrumentationMapper extends ClassRemapper {
Arrays.asList("io/opentelemetry/javaagent/tooling/muzzle/InstrumentationModuleMuzzle"));

private static final Set<String> UNSUPPORTED_METHODS =
new HashSet<>(
Arrays.asList(
"getMuzzleReferences", "getMuzzleHelperClassNames", "registerMuzzleVirtualFields"));
new HashSet<>(Arrays.asList("getMuzzleReferences", "registerMuzzleVirtualFields"));

public OtelInstrumentationMapper(ClassVisitor classVisitor) {
super(classVisitor, Renamer.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import datadog.trace.agent.tooling.InstrumenterModule;
import datadog.trace.api.InstrumenterConfig;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Replaces OpenTelemetry's {@code InstrumentationModule} when mapping extensions.
Expand Down Expand Up @@ -30,4 +33,33 @@ private static String[] namespace(String[] names) {
}
return namespaced;
}

@Override
public String[] helperClassNames() {
List<String> helperClassNames;
List<String> additionalClassNames = getAdditionalHelperClassNames();
if (additionalClassNames.isEmpty()) {
// no additional names, just use those captured at build time
helperClassNames = getMuzzleHelperClassNames();
} else {
// combine names captured at build time with additional names
helperClassNames = new ArrayList<>(getMuzzleHelperClassNames());
helperClassNames.addAll(additionalClassNames);
}
if (helperClassNames.isEmpty()) {
return NO_HELPERS;
} else {
return helperClassNames.toArray(new String[0]);
}
}

/** This method is generated by OpenTelemetry's muzzle plugin at build time. */
public List<String> getMuzzleHelperClassNames() {
return Collections.emptyList();
}

/** Extensions override this to supply names not covered by the muzzle plugin. */
public List<String> getAdditionalHelperClassNames() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public enum TargetSystem {

private static final Logger log = LoggerFactory.getLogger(InstrumenterModule.class);

protected static final String[] NO_HELPERS = {};

private final List<String> instrumentationNames;
private final String instrumentationPrimaryName;
private final boolean enabled;
Expand Down Expand Up @@ -106,7 +108,7 @@ public static ReferenceMatcher loadStaticMuzzleReferences(

/** @return Class names of helpers to inject into the user's classloader */
public String[] helperClassNames() {
return new String[0];
return NO_HELPERS;
}

/**
Expand Down
Loading