Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public void toJson(JsonWriter writer, Config config) throws IOException {
writer.value(config.isDataStreamsEnabled());
writer.name("data_streams_transaction_extractors");
writer.value(config.getDataStreamsTransactionExtractors());
writer.name("otlp_traces_export_enabled");
writer.value(config.isOtlpTracesExportEnabled());
writer.name("otlp_metrics_export_enabled");
writer.value(config.isOtlpMetricsExportEnabled());
writer.name("otlp_logs_export_enabled");
writer.value(config.isOtlpLogsExportEnabled());

writer.name("app_logs_collection_enabled");
writer.value(config.isAppLogsCollectionEnabled());
Expand Down
135 changes: 135 additions & 0 deletions dd-trace-core/src/test/java/datadog/trace/core/StatusLoggerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package datadog.trace.core;

import static datadog.trace.api.config.OtlpConfig.LOGS_OTEL_ENABLED;
import static datadog.trace.api.config.OtlpConfig.LOGS_OTEL_EXPORTER;
import static datadog.trace.api.config.OtlpConfig.METRICS_OTEL_ENABLED;
import static datadog.trace.api.config.OtlpConfig.METRICS_OTEL_EXPORTER;
import static datadog.trace.api.config.OtlpConfig.OTEL_TRACES_SPAN_METRICS_ENABLED;
import static datadog.trace.api.config.OtlpConfig.TRACE_OTEL_EXPORTER;
import static datadog.trace.api.config.TracerConfig.WRITER_TYPE;
import static datadog.trace.bootstrap.instrumentation.api.WriterConstants.DD_AGENT_WRITER_TYPE;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.squareup.moshi.Moshi;
import datadog.json.JsonMapper;
import datadog.trace.api.Config;
import datadog.trace.test.junit.utils.config.WithConfig;
import datadog.trace.test.util.DDJavaSpecification;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(value = 10, unit = TimeUnit.SECONDS)
public class StatusLoggerTest extends DDJavaSpecification {

@Test
void otlpExportDisabledByDefault() throws IOException {
Map<String, Object> startupLog = startupLog();

assertFalse(flag(startupLog, "otlp_traces_export_enabled"));
assertFalse(flag(startupLog, "otlp_metrics_export_enabled"));
assertFalse(flag(startupLog, "otlp_logs_export_enabled"));
}

@Test
@WithConfig(key = TRACE_OTEL_EXPORTER, value = "otlp")
@WithConfig(key = METRICS_OTEL_ENABLED, value = "true")
@WithConfig(key = METRICS_OTEL_EXPORTER, value = "otlp")
@WithConfig(key = LOGS_OTEL_ENABLED, value = "true")
@WithConfig(key = LOGS_OTEL_EXPORTER, value = "otlp")
void otlpExportEnabledWhenConfigured() throws IOException {
Map<String, Object> startupLog = startupLog();

assertTrue(flag(startupLog, "otlp_traces_export_enabled"));
assertTrue(flag(startupLog, "otlp_metrics_export_enabled"));
assertTrue(flag(startupLog, "otlp_logs_export_enabled"));
}

@Test
@WithConfig(key = TRACE_OTEL_EXPORTER, value = "otlp")
@WithConfig(key = METRICS_OTEL_EXPORTER, value = "otlp")
@WithConfig(key = LOGS_OTEL_EXPORTER, value = "otlp")
void metricsAndLogsRequireOtelSignalEnabled() throws IOException {
Map<String, Object> startupLog = startupLog();

assertTrue(flag(startupLog, "otlp_traces_export_enabled"));
assertFalse(flag(startupLog, "otlp_metrics_export_enabled"));
assertFalse(flag(startupLog, "otlp_logs_export_enabled"));
}

@Test
@WithConfig(key = TRACE_OTEL_EXPORTER, value = "otlp")
@WithConfig(key = WRITER_TYPE, value = DD_AGENT_WRITER_TYPE)
void tracesNotExportedWhenWriterTypeOverridesOtlpExporter() throws IOException {
assertFalse(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = WRITER_TYPE, value = "MultiWriter:OtlpWriter,DDAgentWriter")
void tracesExportedWhenMultiWriterIncludesOtlpWriter() throws IOException {
assertTrue(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = WRITER_TYPE, value = "MultiWriter:LoggingWriter,DDAgentWriter")
void tracesNotExportedWhenMultiWriterExcludesOtlpWriter() throws IOException {
assertFalse(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = WRITER_TYPE, value = "MultiWriter: OtlpWriter")
void tracesNotExportedWhenMultiWriterSubTypeIsPadded() throws IOException {
assertFalse(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = WRITER_TYPE, value = "MultiWriter:OtlpWriterExtra")
void tracesNotExportedWhenMultiWriterSubTypeOnlyPrefixesOtlpWriter() throws IOException {
assertFalse(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = WRITER_TYPE, value = "DDAgentWriter,OtlpWriter")
void tracesNotExportedWhenCommaSeparatedWithoutMultiWriterPrefix() throws IOException {
assertFalse(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = WRITER_TYPE, value = "TraceStructureWriter:/tmp/out,OtlpWriter")
void tracesNotExportedWhenTraceStructureWriterTakesPrecedence() throws IOException {
assertFalse(flag(startupLog(), "otlp_traces_export_enabled"));
}

@Test
@WithConfig(key = OTEL_TRACES_SPAN_METRICS_ENABLED, value = "true")
void metricsExportedWhenSpanMetricsEnabled() throws IOException {
assertTrue(flag(startupLog(), "otlp_metrics_export_enabled"));
}

@Test
@WithConfig(key = METRICS_OTEL_ENABLED, value = "true")
@WithConfig(key = METRICS_OTEL_EXPORTER, value = "otlp")
@WithConfig(key = OTEL_TRACES_SPAN_METRICS_ENABLED, value = "false")
void metricsExportedWhenOtelMetricsSignalEnabledWithoutSpanMetrics() throws IOException {
assertTrue(flag(startupLog(), "otlp_metrics_export_enabled"));
}

private static Map<String, Object> startupLog() throws IOException {
String json =
new Moshi.Builder()
.add(new StatusLogger())
.build()
.adapter(Config.class)
.toJson(Config.get());
return JsonMapper.fromJsonToMap(json);
}

private static boolean flag(Map<String, Object> startupLog, String name) {
Object value = startupLog.get(name);
assertTrue(value instanceof Boolean, name + " should be a boolean, was " + value);
return (Boolean) value;
}
}
23 changes: 23 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 @@ -741,6 +741,7 @@
import static datadog.trace.api.featureflag.config.FeatureFlaggingConfig.isSupportedConfigurationSource;
import static datadog.trace.api.featureflag.config.FeatureFlaggingConfig.resolveConfiguration;
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
import static datadog.trace.bootstrap.instrumentation.api.WriterConstants.MULTI_WRITER_TYPE;
import static datadog.trace.bootstrap.instrumentation.api.WriterConstants.OTLP_WRITER_TYPE;
import static datadog.trace.util.CollectionUtils.tryMakeImmutableList;
import static datadog.trace.util.CollectionUtils.tryMakeImmutableSet;
Expand Down Expand Up @@ -5747,6 +5748,10 @@ public boolean isLogsOtlpExporterEnabled() {
return "otlp".equalsIgnoreCase(logsOtelExporter);
}

public boolean isOtlpLogsExportEnabled() {
return isLogsOtelEnabled() && isLogsOtlpExporterEnabled();
}

public int getLogsOtelInterval() {
return logsOtelInterval;
}
Expand Down Expand Up @@ -5791,6 +5796,11 @@ public boolean isMetricsOtlpExporterEnabled() {
return "otlp".equalsIgnoreCase(metricsOtelExporter);
}

public boolean isOtlpMetricsExportEnabled() {
return (isMetricsOtelEnabled() && isMetricsOtlpExporterEnabled())
|| isOtelTracesSpanMetricsEnabled();
}

public boolean isMetricsOtelExperimentalEnabled() {
return metricsOtelExperimentalEnabled;
}
Expand Down Expand Up @@ -5847,6 +5857,19 @@ public boolean isTraceOtlpExporterEnabled() {
return "otlp".equalsIgnoreCase(traceOtelExporter);
}

public boolean isOtlpTracesExportEnabled() {
Comment thread
bm1549 marked this conversation as resolved.
if (!writerType.startsWith(MULTI_WRITER_TYPE)) {
return OTLP_WRITER_TYPE.equals(writerType);
}
String multiWriterConfig = writerType.substring(MULTI_WRITER_TYPE.length() + 1);
for (CharSequence subWriterType : Strings.split(multiWriterConfig, ',')) {
if (OTLP_WRITER_TYPE.contentEquals(subWriterType)) {
return true;
}
}
return false;
}

public String getOtlpTracesEndpoint() {
return otlpTracesEndpoint;
}
Expand Down
Loading