|
| 1 | +package datadog.trace.common.writer; |
| 2 | + |
| 3 | +import static datadog.trace.api.config.OtlpConfig.TRACE_OTEL_EXPORTER; |
| 4 | +import static datadog.trace.junit.utils.config.WithConfigExtension.injectSysConfig; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | + |
| 7 | +import com.sun.net.httpserver.HttpServer; |
| 8 | +import datadog.trace.core.CoreTracer; |
| 9 | +import datadog.trace.core.DDCoreJavaSpecification; |
| 10 | +import java.io.IOException; |
| 11 | +import java.net.InetSocketAddress; |
| 12 | +import java.util.concurrent.CountDownLatch; |
| 13 | +import java.util.concurrent.TimeUnit; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | +import org.junit.jupiter.api.Timeout; |
| 16 | + |
| 17 | +@Timeout(value = 10, unit = TimeUnit.SECONDS) |
| 18 | +class OtlpWriterCombinedTest extends DDCoreJavaSpecification { |
| 19 | + |
| 20 | + @Test |
| 21 | + void happyPathOverHttp() throws IOException, InterruptedException { |
| 22 | + injectSysConfig(TRACE_OTEL_EXPORTER, "otlp"); |
| 23 | + |
| 24 | + CountDownLatch received = new CountDownLatch(1); |
| 25 | + HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 0), 0); |
| 26 | + server.createContext( |
| 27 | + "/v1/traces", |
| 28 | + exchange -> { |
| 29 | + received.countDown(); |
| 30 | + exchange.sendResponseHeaders(200, -1); |
| 31 | + exchange.close(); |
| 32 | + }); |
| 33 | + server.start(); |
| 34 | + |
| 35 | + OtlpWriter writer = |
| 36 | + OtlpWriter.builder() |
| 37 | + .endpoint( |
| 38 | + "http://" |
| 39 | + + server.getAddress().getHostString() |
| 40 | + + ":" |
| 41 | + + server.getAddress().getPort() |
| 42 | + + "/v1/traces") |
| 43 | + .flushIntervalMilliseconds(-1) |
| 44 | + .build(); |
| 45 | + CoreTracer tracer = tracerBuilder().writer(writer).build(); |
| 46 | + try { |
| 47 | + tracer.buildSpan("test", "fakeOperation").start().finish(); |
| 48 | + writer.flush(); |
| 49 | + |
| 50 | + assertTrue(received.await(5, TimeUnit.SECONDS), "OTLP server should receive a request"); |
| 51 | + } finally { |
| 52 | + tracer.close(); |
| 53 | + server.stop(0); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments