Skip to content

Commit

Permalink
Support OpenTelemetry extension helpers (#7127)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Jun 5, 2024
1 parent 239d9a9 commit aa92d53
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
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

0 comments on commit aa92d53

Please sign in to comment.