|
1 | 1 | package datadog.trace.core; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
| 3 | +import static datadog.trace.api.config.OtlpConfig.LOGS_OTEL_ENABLED; |
| 4 | +import static datadog.trace.api.config.OtlpConfig.LOGS_OTEL_EXPORTER; |
| 5 | +import static datadog.trace.api.config.OtlpConfig.METRICS_OTEL_ENABLED; |
| 6 | +import static datadog.trace.api.config.OtlpConfig.METRICS_OTEL_EXPORTER; |
| 7 | +import static datadog.trace.api.config.OtlpConfig.OTEL_TRACES_SPAN_METRICS_ENABLED; |
| 8 | +import static datadog.trace.api.config.OtlpConfig.TRACE_OTEL_EXPORTER; |
| 9 | +import static datadog.trace.api.config.TracerConfig.WRITER_TYPE; |
| 10 | +import static datadog.trace.bootstrap.instrumentation.api.WriterConstants.DD_AGENT_WRITER_TYPE; |
| 11 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 12 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 13 |
|
5 | 14 | import com.squareup.moshi.Moshi; |
6 | 15 | import datadog.trace.api.Config; |
7 | | -import datadog.trace.api.config.OtlpConfig; |
8 | | -import datadog.trace.api.config.TracerConfig; |
9 | 16 | import datadog.trace.test.junit.utils.config.WithConfig; |
| 17 | +import datadog.trace.test.util.DDJavaSpecification; |
10 | 18 | import java.io.IOException; |
11 | 19 | import java.util.Map; |
12 | 20 | import java.util.concurrent.TimeUnit; |
13 | 21 | import org.junit.jupiter.api.Test; |
14 | 22 | import org.junit.jupiter.api.Timeout; |
15 | 23 |
|
16 | 24 | @Timeout(value = 10, unit = TimeUnit.SECONDS) |
17 | | -public class StatusLoggerTest extends DDCoreJavaSpecification { |
| 25 | +public class StatusLoggerTest extends DDJavaSpecification { |
18 | 26 |
|
19 | 27 | @Test |
20 | 28 | void otlpExportDisabledByDefault() throws IOException { |
21 | | - Map<String, Object> startupLog = startupLog(Config.get()); |
| 29 | + Map<String, Object> startupLog = startupLog(); |
22 | 30 |
|
23 | | - assertEquals(false, startupLog.get("otlp_traces_export_enabled")); |
24 | | - assertEquals(false, startupLog.get("otlp_metrics_export_enabled")); |
25 | | - assertEquals(false, startupLog.get("otlp_logs_export_enabled")); |
| 31 | + assertFalse(flag(startupLog, "otlp_traces_export_enabled")); |
| 32 | + assertFalse(flag(startupLog, "otlp_metrics_export_enabled")); |
| 33 | + assertFalse(flag(startupLog, "otlp_logs_export_enabled")); |
26 | 34 | } |
27 | 35 |
|
28 | 36 | @Test |
29 | | - @WithConfig(key = OtlpConfig.TRACE_OTEL_EXPORTER, value = "otlp") |
30 | | - @WithConfig(key = OtlpConfig.METRICS_OTEL_ENABLED, value = "true") |
31 | | - @WithConfig(key = OtlpConfig.METRICS_OTEL_EXPORTER, value = "otlp") |
32 | | - @WithConfig(key = OtlpConfig.LOGS_OTEL_ENABLED, value = "true") |
33 | | - @WithConfig(key = OtlpConfig.LOGS_OTEL_EXPORTER, value = "otlp") |
| 37 | + @WithConfig(key = TRACE_OTEL_EXPORTER, value = "otlp") |
| 38 | + @WithConfig(key = METRICS_OTEL_ENABLED, value = "true") |
| 39 | + @WithConfig(key = METRICS_OTEL_EXPORTER, value = "otlp") |
| 40 | + @WithConfig(key = LOGS_OTEL_ENABLED, value = "true") |
| 41 | + @WithConfig(key = LOGS_OTEL_EXPORTER, value = "otlp") |
34 | 42 | void otlpExportEnabledWhenConfigured() throws IOException { |
35 | | - Map<String, Object> startupLog = startupLog(Config.get()); |
| 43 | + Map<String, Object> startupLog = startupLog(); |
36 | 44 |
|
37 | | - assertEquals(true, startupLog.get("otlp_traces_export_enabled")); |
38 | | - assertEquals(true, startupLog.get("otlp_metrics_export_enabled")); |
39 | | - assertEquals(true, startupLog.get("otlp_logs_export_enabled")); |
| 45 | + assertTrue(flag(startupLog, "otlp_traces_export_enabled")); |
| 46 | + assertTrue(flag(startupLog, "otlp_metrics_export_enabled")); |
| 47 | + assertTrue(flag(startupLog, "otlp_logs_export_enabled")); |
40 | 48 | } |
41 | 49 |
|
42 | 50 | @Test |
43 | | - @WithConfig(key = OtlpConfig.TRACE_OTEL_EXPORTER, value = "otlp") |
44 | | - @WithConfig(key = OtlpConfig.METRICS_OTEL_EXPORTER, value = "otlp") |
45 | | - @WithConfig(key = OtlpConfig.LOGS_OTEL_EXPORTER, value = "otlp") |
| 51 | + @WithConfig(key = TRACE_OTEL_EXPORTER, value = "otlp") |
| 52 | + @WithConfig(key = METRICS_OTEL_EXPORTER, value = "otlp") |
| 53 | + @WithConfig(key = LOGS_OTEL_EXPORTER, value = "otlp") |
46 | 54 | void metricsAndLogsRequireOtelSignalEnabled() throws IOException { |
47 | | - // The OTLP exporter is selected for every signal, but the metrics and logs OTel signals are |
48 | | - // left disabled, so only trace export should be reported as enabled. |
49 | | - Map<String, Object> startupLog = startupLog(Config.get()); |
| 55 | + Map<String, Object> startupLog = startupLog(); |
50 | 56 |
|
51 | | - assertEquals(true, startupLog.get("otlp_traces_export_enabled")); |
52 | | - assertEquals(false, startupLog.get("otlp_metrics_export_enabled")); |
53 | | - assertEquals(false, startupLog.get("otlp_logs_export_enabled")); |
| 57 | + assertTrue(flag(startupLog, "otlp_traces_export_enabled")); |
| 58 | + assertFalse(flag(startupLog, "otlp_metrics_export_enabled")); |
| 59 | + assertFalse(flag(startupLog, "otlp_logs_export_enabled")); |
54 | 60 | } |
55 | 61 |
|
56 | 62 | @Test |
57 | | - @WithConfig(key = OtlpConfig.TRACE_OTEL_EXPORTER, value = "otlp") |
58 | | - @WithConfig(key = TracerConfig.WRITER_TYPE, value = "DDAgentWriter") |
| 63 | + @WithConfig(key = TRACE_OTEL_EXPORTER, value = "otlp") |
| 64 | + @WithConfig(key = WRITER_TYPE, value = DD_AGENT_WRITER_TYPE) |
59 | 65 | void tracesNotExportedWhenWriterTypeOverridesOtlpExporter() throws IOException { |
60 | | - // The OTLP trace exporter is selected, but an explicit dd.writer.type override wins in |
61 | | - // WriterFactory, so the effective writer is the DDAgentWriter and traces are not exported over |
62 | | - // OTLP. |
63 | | - Map<String, Object> startupLog = startupLog(Config.get()); |
| 66 | + assertFalse(flag(startupLog(), "otlp_traces_export_enabled")); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + @WithConfig(key = WRITER_TYPE, value = "MultiWriter:OtlpWriter,DDAgentWriter") |
| 71 | + void tracesExportedWhenMultiWriterIncludesOtlpWriter() throws IOException { |
| 72 | + assertTrue(flag(startupLog(), "otlp_traces_export_enabled")); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + @WithConfig(key = WRITER_TYPE, value = "MultiWriter:DDAgentWriter,MultiWriter:OtlpWriter") |
| 77 | + void tracesExportedWhenMultiWriterPrefixRepeats() throws IOException { |
| 78 | + assertTrue(flag(startupLog(), "otlp_traces_export_enabled")); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + @WithConfig(key = WRITER_TYPE, value = "MultiWriter:LoggingWriter,DDAgentWriter") |
| 83 | + void tracesNotExportedWhenMultiWriterExcludesOtlpWriter() throws IOException { |
| 84 | + assertFalse(flag(startupLog(), "otlp_traces_export_enabled")); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + @WithConfig(key = WRITER_TYPE, value = "MultiWriter: OtlpWriter") |
| 89 | + void tracesNotExportedWhenMultiWriterSubTypeIsPadded() throws IOException { |
| 90 | + assertFalse(flag(startupLog(), "otlp_traces_export_enabled")); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + @WithConfig(key = WRITER_TYPE, value = "MultiWriter:OtlpWriterExtra") |
| 95 | + void tracesNotExportedWhenMultiWriterSubTypeOnlyPrefixesOtlpWriter() throws IOException { |
| 96 | + assertFalse(flag(startupLog(), "otlp_traces_export_enabled")); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + @WithConfig(key = WRITER_TYPE, value = "DDAgentWriter,OtlpWriter") |
| 101 | + void tracesNotExportedWhenCommaSeparatedWithoutMultiWriterPrefix() throws IOException { |
| 102 | + assertFalse(flag(startupLog(), "otlp_traces_export_enabled")); |
| 103 | + } |
64 | 104 |
|
65 | | - assertEquals(false, startupLog.get("otlp_traces_export_enabled")); |
| 105 | + @Test |
| 106 | + @WithConfig(key = WRITER_TYPE, value = "TraceStructureWriter:/tmp/out,OtlpWriter") |
| 107 | + void tracesNotExportedWhenTraceStructureWriterTakesPrecedence() throws IOException { |
| 108 | + assertFalse(flag(startupLog(), "otlp_traces_export_enabled")); |
66 | 109 | } |
67 | 110 |
|
68 | 111 | @Test |
69 | | - @WithConfig(key = OtlpConfig.OTEL_TRACES_SPAN_METRICS_ENABLED, value = "true") |
| 112 | + @WithConfig(key = OTEL_TRACES_SPAN_METRICS_ENABLED, value = "true") |
70 | 113 | void metricsExportedWhenSpanMetricsEnabled() throws IOException { |
71 | | - // Span metrics are exported over OTLP via OtlpStatsMetricWriter whenever span metrics are |
72 | | - // enabled, independently of the OTel metrics signal, so metrics export should be reported. |
73 | | - Map<String, Object> startupLog = startupLog(Config.get()); |
| 114 | + assertTrue(flag(startupLog(), "otlp_metrics_export_enabled")); |
| 115 | + } |
74 | 116 |
|
75 | | - assertEquals(true, startupLog.get("otlp_metrics_export_enabled")); |
| 117 | + @Test |
| 118 | + @WithConfig(key = METRICS_OTEL_ENABLED, value = "true") |
| 119 | + @WithConfig(key = METRICS_OTEL_EXPORTER, value = "otlp") |
| 120 | + @WithConfig(key = OTEL_TRACES_SPAN_METRICS_ENABLED, value = "false") |
| 121 | + void metricsExportedWhenOtelMetricsSignalEnabledWithoutSpanMetrics() throws IOException { |
| 122 | + assertTrue(flag(startupLog(), "otlp_metrics_export_enabled")); |
76 | 123 | } |
77 | 124 |
|
78 | 125 | @SuppressWarnings("unchecked") |
79 | | - private static Map<String, Object> startupLog(Config config) throws IOException { |
| 126 | + private static Map<String, Object> startupLog() throws IOException { |
80 | 127 | String json = |
81 | | - new Moshi.Builder().add(new StatusLogger()).build().adapter(Config.class).toJson(config); |
| 128 | + new Moshi.Builder() |
| 129 | + .add(new StatusLogger()) |
| 130 | + .build() |
| 131 | + .adapter(Config.class) |
| 132 | + .toJson(Config.get()); |
82 | 133 | return (Map<String, Object>) new Moshi.Builder().build().adapter(Object.class).fromJson(json); |
83 | 134 | } |
| 135 | + |
| 136 | + private static boolean flag(Map<String, Object> startupLog, String name) { |
| 137 | + Object value = startupLog.get(name); |
| 138 | + assertTrue(value instanceof Boolean, name + " should be a boolean, was " + value); |
| 139 | + return (Boolean) value; |
| 140 | + } |
84 | 141 | } |
0 commit comments