-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve config mapping for OpenTelemetry extensions (#7193)
* Support arbitrary lookup of 'otel.' config from extensions * Use property for OTel API version * Don't embed unnecessary classes * Use includes to control which areas of the OTel API we embed * Rework OTel package remapper to remap both shaded and unshaded references * Embed OTel instrumentation API, removing classes already covered by existing mappings as well as experimental packages * Embed OTel javaagent-extension API, removing classes already covered by existing mappings as well as experimental packages As part of this we redirect CallDepth requests to our own CallDepthThreadLocalMap * Embed opentelemetry-javaagent-servlet-common-bootstrap * Redirect InstrumentationConfig requests to our own ConfigProvider * Ignore partial build class-path when checking for forbidden APIs in otel-bootstrap
- Loading branch information
Showing
6 changed files
with
191 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 0 additions & 33 deletions
33
...t-otel/otel-bootstrap/src/main/java/datadog/trace/bootstrap/otel/Java8BytecodeBridge.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
.../otel-bootstrap/src/main/java/datadog/trace/bootstrap/otel/instrumentation/CallDepth.java
This file contains 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,24 @@ | ||
package datadog.trace.bootstrap.otel.instrumentation; | ||
|
||
import datadog.trace.bootstrap.CallDepthThreadLocalMap; | ||
|
||
/** Redirects requests to our own {@link CallDepthThreadLocalMap}. */ | ||
public final class CallDepth { | ||
private final Class<?> clazz; | ||
|
||
private CallDepth(final Class<?> clazz) { | ||
this.clazz = clazz; | ||
} | ||
|
||
public static CallDepth forClass(Class<?> clazz) { | ||
return new CallDepth(clazz); | ||
} | ||
|
||
public int getAndIncrement() { | ||
return CallDepthThreadLocalMap.incrementCallDepth(clazz); | ||
} | ||
|
||
public int decrementAndGet() { | ||
return CallDepthThreadLocalMap.decrementCallDepth(clazz); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...ain/java/datadog/trace/bootstrap/otel/instrumentation/internal/InstrumentationConfig.java
This file contains 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,93 @@ | ||
package datadog.trace.bootstrap.otel.instrumentation.internal; | ||
|
||
import datadog.trace.bootstrap.config.provider.ConfigProvider; | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** Redirects requests to our own {@link ConfigProvider}. */ | ||
public final class InstrumentationConfig { | ||
private static final InstrumentationConfig INSTANCE = new InstrumentationConfig(); | ||
|
||
private static final Pattern DURATION_PATTERN = Pattern.compile("(\\d+)(ms|[DdHhMmSs]?)"); | ||
|
||
private static final ConfigProvider delegate = ConfigProvider.getInstance(); | ||
|
||
public static InstrumentationConfig get() { | ||
return INSTANCE; | ||
} | ||
|
||
public String getString(String name) { | ||
return delegate.getString(name); | ||
} | ||
|
||
public String getString(String name, String defaultValue) { | ||
return delegate.getString(name, defaultValue); | ||
} | ||
|
||
public boolean getBoolean(String name, boolean defaultValue) { | ||
return delegate.getBoolean(name, defaultValue); | ||
} | ||
|
||
public int getInt(String name, int defaultValue) { | ||
return delegate.getInteger(name, defaultValue); | ||
} | ||
|
||
public long getLong(String name, long defaultValue) { | ||
return delegate.getLong(name, defaultValue); | ||
} | ||
|
||
public double getDouble(String name, double defaultValue) { | ||
return delegate.getDouble(name, defaultValue); | ||
} | ||
|
||
public Duration getDuration(String name, Duration defaultValue) { | ||
String durationString = delegate.getString(name); | ||
if (null == durationString) { | ||
return defaultValue; | ||
} | ||
Matcher matcher = DURATION_PATTERN.matcher(durationString); | ||
if (matcher.matches()) { | ||
long value = Integer.parseInt(matcher.group(1)); | ||
String unit = matcher.group(2); | ||
if ("D".equalsIgnoreCase(unit)) { | ||
return Duration.ofDays(value); | ||
} else if ("H".equalsIgnoreCase(unit)) { | ||
return Duration.ofHours(value); | ||
} else if ("M".equalsIgnoreCase(unit)) { | ||
return Duration.ofMinutes(value); | ||
} else if ("S".equalsIgnoreCase(unit)) { | ||
return Duration.ofSeconds(value); | ||
} else { | ||
return Duration.ofMillis(value); // already in ms | ||
} | ||
} else { | ||
throw new IllegalArgumentException( | ||
"Invalid duration property " + name + "=" + durationString); | ||
} | ||
} | ||
|
||
public List<String> getList(String name) { | ||
return getList(name, Collections.emptyList()); | ||
} | ||
|
||
public List<String> getList(String name, List<String> defaultValue) { | ||
return delegate.getList(name, defaultValue); | ||
} | ||
|
||
public Set<String> getSet(String name, Set<String> defaultValue) { | ||
return delegate.getSet(name, defaultValue); | ||
} | ||
|
||
public Map<String, String> getMap(String name, Map<String, String> defaultValue) { | ||
Map<String, String> map = delegate.getMergedMap(name); | ||
if (map.isEmpty()) { | ||
map = defaultValue; | ||
} | ||
return map; | ||
} | ||
} |
This file contains 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 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