Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
141 changes: 141 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,141 @@
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.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:DDAgentWriter,MultiWriter:OtlpWriter")
void tracesExportedWhenMultiWriterPrefixRepeats() 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"));
}

@SuppressWarnings("unchecked")
private static Map<String, Object> startupLog() throws IOException {
String json =
new Moshi.Builder()
.add(new StatusLogger())
.build()
.adapter(Config.class)
.toJson(Config.get());
return (Map<String, Object>) new Moshi.Builder().build().adapter(Object.class).fromJson(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 @@ -727,6 +727,7 @@
import static datadog.trace.api.config.TracerConfig.WRITER_LINKS_INJECT;
import static datadog.trace.api.config.TracerConfig.WRITER_TYPE;
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 @@ -5577,6 +5578,10 @@ public boolean isLogsOtlpExporterEnabled() {
return "otlp".equalsIgnoreCase(logsOtelExporter);
}

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

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

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

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

public boolean isOtlpTracesExportEnabled() {
if (!writerType.startsWith(MULTI_WRITER_TYPE)) {
return OTLP_WRITER_TYPE.equals(writerType);
}
String multiWriterConfig = Strings.replace(writerType, MULTI_WRITER_TYPE + ":", "");
for (String subWriterType : multiWriterConfig.split(",")) {
if (OTLP_WRITER_TYPE.equals(subWriterType)) {
return true;
}
}
return false;
}

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