-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathOtelSpiCollectorTest.java
More file actions
69 lines (57 loc) · 2.28 KB
/
OtelSpiCollectorTest.java
File metadata and controls
69 lines (57 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package datadog.trace.api.telemetry;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Iterator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class OtelSpiCollectorTest {
private final OtelSpiCollector collector = OtelSpiCollector.getInstance();
@BeforeEach
public void clearQueue() {
collector.drain();
}
@Test
public void singletonReturnsSameInstance() {
assertSame(OtelSpiCollector.getInstance(), OtelSpiCollector.getInstance());
}
@Test
public void recordedMetricSurfacesOnDrain() {
collector.recordSpiDetected(
"io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider", "extensions_path");
Iterator<OtelSpiCollector.OtelSpiMetric> drained = collector.drain().iterator();
assertTrue(drained.hasNext());
OtelSpiCollector.OtelSpiMetric metric = drained.next();
assertEquals("tracers", metric.namespace);
assertEquals("otel.spi.detected", metric.metricName);
assertEquals("count", metric.type);
assertTrue(metric.common);
assertEquals(1, metric.value);
assertTrue(
metric.tags.contains(
"spi_class:io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider"));
assertTrue(metric.tags.contains("source:extensions_path"));
}
@Test
public void multipleRecordsDrainAsDistinctMetrics() {
collector.recordSpiDetected(
"io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider", "app_classpath");
collector.recordSpiDetected(
"io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider", "app_classpath");
collector.recordSpiDetected(
"io.opentelemetry.sdk.autoconfigure.spi.ConfigurableSamplerProvider", "extensions_path");
assertEquals(3, collector.drain().size());
}
@Test
public void drainWithoutRecordsReturnsEmpty() {
assertEquals(0, collector.drain().size());
}
@Test
public void drainClearsQueue() {
collector.recordSpiDetected(
"io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider",
"extensions_path");
assertEquals(1, collector.drain().size());
assertEquals(0, collector.drain().size());
}
}