Skip to content

Commit a4287c5

Browse files
bm1549claude
andcommitted
Add OTLP export flags to tracer startup diagnostic log
Report whether the tracer exports each telemetry signal over OTLP in the "DATADOG TRACER CONFIGURATION" startup log via three boolean fields: otlp_traces_export_enabled, otlp_metrics_export_enabled, and otlp_logs_export_enabled. Metrics and logs require both the OTel signal to be enabled and the OTLP exporter to be selected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4900f89 commit a4287c5

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

dd-trace-core/src/main/java/datadog/trace/core/StatusLogger.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ public void toJson(JsonWriter writer, Config config) throws IOException {
158158
writer.value(config.isDataStreamsEnabled());
159159
writer.name("data_streams_transaction_extractors");
160160
writer.value(config.getDataStreamsTransactionExtractors());
161+
writer.name("otlp_traces_export_enabled");
162+
writer.value(config.isTraceOtlpExporterEnabled());
163+
writer.name("otlp_metrics_export_enabled");
164+
writer.value(config.isMetricsOtelEnabled() && config.isMetricsOtlpExporterEnabled());
165+
writer.name("otlp_logs_export_enabled");
166+
writer.value(config.isLogsOtelEnabled() && config.isLogsOtlpExporterEnabled());
161167

162168
writer.name("app_logs_collection_enabled");
163169
writer.value(config.isAppLogsCollectionEnabled());
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package datadog.trace.core;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.squareup.moshi.Moshi;
6+
import datadog.trace.api.Config;
7+
import datadog.trace.api.config.OtlpConfig;
8+
import datadog.trace.test.junit.utils.config.WithConfig;
9+
import java.io.IOException;
10+
import java.util.Map;
11+
import java.util.concurrent.TimeUnit;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.Timeout;
14+
15+
@Timeout(value = 10, unit = TimeUnit.SECONDS)
16+
public class StatusLoggerTest extends DDCoreJavaSpecification {
17+
18+
@Test
19+
void otlpExportDisabledByDefault() throws IOException {
20+
Map<String, Object> startupLog = startupLog(Config.get());
21+
22+
assertEquals(false, startupLog.get("otlp_traces_export_enabled"));
23+
assertEquals(false, startupLog.get("otlp_metrics_export_enabled"));
24+
assertEquals(false, startupLog.get("otlp_logs_export_enabled"));
25+
}
26+
27+
@Test
28+
@WithConfig(key = OtlpConfig.TRACE_OTEL_EXPORTER, value = "otlp")
29+
@WithConfig(key = OtlpConfig.METRICS_OTEL_ENABLED, value = "true")
30+
@WithConfig(key = OtlpConfig.METRICS_OTEL_EXPORTER, value = "otlp")
31+
@WithConfig(key = OtlpConfig.LOGS_OTEL_ENABLED, value = "true")
32+
@WithConfig(key = OtlpConfig.LOGS_OTEL_EXPORTER, value = "otlp")
33+
void otlpExportEnabledWhenConfigured() throws IOException {
34+
Map<String, Object> startupLog = startupLog(Config.get());
35+
36+
assertEquals(true, startupLog.get("otlp_traces_export_enabled"));
37+
assertEquals(true, startupLog.get("otlp_metrics_export_enabled"));
38+
assertEquals(true, startupLog.get("otlp_logs_export_enabled"));
39+
}
40+
41+
@Test
42+
@WithConfig(key = OtlpConfig.TRACE_OTEL_EXPORTER, value = "otlp")
43+
@WithConfig(key = OtlpConfig.METRICS_OTEL_EXPORTER, value = "otlp")
44+
@WithConfig(key = OtlpConfig.LOGS_OTEL_EXPORTER, value = "otlp")
45+
void metricsAndLogsRequireOtelSignalEnabled() throws IOException {
46+
// The OTLP exporter is selected for every signal, but the metrics and logs OTel signals are
47+
// left disabled, so only trace export should be reported as enabled.
48+
Map<String, Object> startupLog = startupLog(Config.get());
49+
50+
assertEquals(true, startupLog.get("otlp_traces_export_enabled"));
51+
assertEquals(false, startupLog.get("otlp_metrics_export_enabled"));
52+
assertEquals(false, startupLog.get("otlp_logs_export_enabled"));
53+
}
54+
55+
@SuppressWarnings("unchecked")
56+
private static Map<String, Object> startupLog(Config config) throws IOException {
57+
String json =
58+
new Moshi.Builder().add(new StatusLogger()).build().adapter(Config.class).toJson(config);
59+
return (Map<String, Object>) new Moshi.Builder().build().adapter(Object.class).fromJson(json);
60+
}
61+
}

0 commit comments

Comments
 (0)