|
| 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