Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public final class OtlpConfig {
public static final String OTLP_METRICS_TEMPORALITY_PREFERENCE =
"otlp.metrics.temporality.preference";

public static final String TRACE_OTEL_EXPORTER = "trace.otel.exporter";

public enum Protocol {
GRPC,
HTTP_PROTOBUF,
Expand Down
11 changes: 11 additions & 0 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
import static datadog.trace.api.config.OtlpConfig.OTLP_METRICS_PROTOCOL;
import static datadog.trace.api.config.OtlpConfig.OTLP_METRICS_TEMPORALITY_PREFERENCE;
import static datadog.trace.api.config.OtlpConfig.OTLP_METRICS_TIMEOUT;
import static datadog.trace.api.config.OtlpConfig.TRACE_OTEL_EXPORTER;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_AGENTLESS;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_AGENTLESS_DEFAULT;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_API_KEY_FILE_OLD;
Expand Down Expand Up @@ -913,6 +914,8 @@ public static String getHostName() {
private final boolean jmxFetchMultipleRuntimeServicesEnabled;
private final int jmxFetchMultipleRuntimeServicesLimit;

private final String traceOtelExporter;

private final boolean metricsOtelEnabled;
private final int metricsOtelInterval;
private final int metricsOtelTimeout;
Expand Down Expand Up @@ -1889,6 +1892,8 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins
statsDClientSocketBuffer = configProvider.getInteger(STATSD_CLIENT_SOCKET_BUFFER);
statsDClientSocketTimeout = configProvider.getInteger(STATSD_CLIENT_SOCKET_TIMEOUT);

traceOtelExporter = configProvider.getString(TRACE_OTEL_EXPORTER);

metricsOtelEnabled =
configProvider.getBoolean(METRICS_OTEL_ENABLED, DEFAULT_METRICS_OTEL_ENABLED);

Expand Down Expand Up @@ -5204,6 +5209,10 @@ public boolean isJmxFetchIntegrationEnabled(
return configProvider.isEnabled(integrationNames, "jmxfetch.", ".enabled", defaultEnabled);
}

public boolean isOtlpTracesExporterEnabled() {
return "otlp".equalsIgnoreCase(traceOtelExporter);
}
Comment on lines +5212 to +5214
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not currently used, but will be used in a follow-up PR.

I previously had an additional method for getTraceOtelExporter, to just get the value, but I removed this as it was not currently used, and my immediate follow-up PRs will not use it.

It will only become necessary if we support the other OTEL_TRACES_EXPORTER fields in the future.


public boolean isMetricsOtelEnabled() {
return metricsOtelEnabled;
}
Expand Down Expand Up @@ -6255,6 +6264,8 @@ public String toString() {
+ aiGuardEnabled
+ ", aiGuardEndpoint="
+ aiGuardEndpoint
+ ", traceOtelExporter="
+ traceOtelExporter
+ ", metricsOtelEnabled="
+ metricsOtelEnabled
+ ", metricsOtelInterval="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class OtelEnvMetricCollectorImplTest extends DDSpecification {
where:
otelEnvKey | otelEnvValue || metricType | metricValue | metricNamespace | metricName | tagsOtelValue
'OTEL_METRICS_EXPORTER' | 'otlp' || 'count' | 1 | 'tracers' | 'otel.env.unsupported' | 'config_opentelemetry:otel_metrics_exporter'
'OTEL_TRACES_EXPORTER' | 'otlp' || 'count' | 1 | 'tracers' | 'otel.env.unsupported' | 'config_opentelemetry:otel_traces_exporter'
'OTEL_TRACES_EXPORTER' | 'zipkin' || 'count' | 1 | 'tracers' | 'otel.env.unsupported' | 'config_opentelemetry:otel_traces_exporter'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems to just be checking that the otel.env.unsupported metric is reported when an otel environment variable is discovered with an unsupported value; since this PR adds support for OTEL_TRACES_EXPORTER=otlp, I changed the test value to some other unsupported value -- "zipkin"

Reference: https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#exporter-selection

'OTEL_LOGS_EXPORTER' | 'otlp' || 'count' | 1 | 'tracers' | 'otel.env.unsupported' | 'config_opentelemetry:otel_logs_exporter'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import static datadog.trace.api.config.GeneralConfig.RUNTIME_METRICS_ENABLED
import static datadog.trace.api.config.GeneralConfig.SERVICE_NAME
import static datadog.trace.api.config.GeneralConfig.TAGS
import static datadog.trace.api.config.GeneralConfig.VERSION
import static datadog.trace.api.config.OtlpConfig.TRACE_OTEL_EXPORTER
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_ENABLED
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_EXTENSIONS_PATH
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_OTEL_ENABLED
Expand Down Expand Up @@ -231,6 +232,44 @@ class OtelEnvironmentConfigSourceTest extends DDSpecification {
source.get(TRACE_EXTENSIONS_PATH) == '/opt/opentelemetry/extensions'
}

def "otel traces exporter otlp system property is mapped"() {
setup:
injectSysConfig('dd.trace.otel.enabled', 'true', false)
injectSysConfig('otel.traces.exporter', 'otlp', false)

when:
def source = new OtelEnvironmentConfigSource()

then:
source.get(TRACE_ENABLED) == null
source.get(TRACE_OTEL_EXPORTER) == 'otlp'
}

def "otel traces exporter otlp environment variable is mapped"() {
setup:
injectEnvConfig('DD_TRACE_OTEL_ENABLED', 'true', false)
injectEnvConfig('OTEL_TRACES_EXPORTER', 'otlp', false)

when:
def source = new OtelEnvironmentConfigSource()

then:
source.get(TRACE_ENABLED) == null
source.get(TRACE_OTEL_EXPORTER) == 'otlp'
}

def "otel traces exporter none still disables tracing"() {
setup:
injectEnvConfig('DD_TRACE_OTEL_ENABLED', 'true', false)
injectEnvConfig('OTEL_TRACES_EXPORTER', 'none', false)

when:
def source = new OtelEnvironmentConfigSource()

then:
source.get(TRACE_ENABLED) == 'false'
}

def "otel resource attributes system property is mapped"() {
setup:
injectSysConfig('dd.trace.otel.enabled', 'true', false)
Expand Down
8 changes: 8 additions & 0 deletions metadata/supported-configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8177,6 +8177,14 @@
"aliases": []
}
],
"DD_TRACE_OTEL_EXPORTER": [
Comment thread
mcculls marked this conversation as resolved.
{
"version": "A",
"type": "string",
"default": null,
"aliases": []
}
],
"DD_TRACE_PARTIAL_FLUSH_ENABLED": [
{
"version": "B",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static datadog.trace.api.config.OtlpConfig.OTLP_METRICS_PROTOCOL;
import static datadog.trace.api.config.OtlpConfig.OTLP_METRICS_TEMPORALITY_PREFERENCE;
import static datadog.trace.api.config.OtlpConfig.OTLP_METRICS_TIMEOUT;
import static datadog.trace.api.config.OtlpConfig.TRACE_OTEL_EXPORTER;
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_ENABLED;
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_EXTENSIONS_PATH;
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_OTEL_ENABLED;
Expand Down Expand Up @@ -134,11 +135,20 @@ private void setupTraceOtelEnvironment() {
capture(TRACE_PROPAGATION_STYLE, mapPropagationStyle(propagators));
capture(TRACE_SAMPLE_RATE, mapSampleRate(tracesSampler));
capture(TRACE_ENABLED, mapDataCollection("traces"));
capture(TRACE_OTEL_EXPORTER, mapTracesExporter());
capture(REQUEST_HEADER_TAGS, mapHeaderTags("http.request.header.", requestHeaders));
capture(RESPONSE_HEADER_TAGS, mapHeaderTags("http.response.header.", responseHeaders));
capture(TRACE_EXTENSIONS_PATH, extensions);
}

private String mapTracesExporter() {
String exporter = getOtelProperty("otel.traces.exporter");
if ("otlp".equalsIgnoreCase(exporter)) {
return "otlp";
}
return null;
}

private void setupMetricsOtelEnvironment() {
capture(
METRICS_OTEL_INTERVAL,
Expand Down Expand Up @@ -439,7 +449,11 @@ private String mapDataCollection(String signal) {
}

if ("none".equalsIgnoreCase(exporter)) {
return "false"; // currently we only accept "none" which maps to disable data collection
return "false"; // "none" maps to disable data collection
}

if ("traces".equals(signal) && "otlp".equalsIgnoreCase(exporter)) {
return null; // otlp is handled separately for traces
}

log.warn("OTEL_{}_EXPORTER={} is not supported", signal, exporter.toUpperCase(Locale.ROOT));
Expand Down
Loading