/* * Copyright The OpenTelemetry Authors * SPDX-License-Identifier: Apache-2.0 */ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION import com.twitter.finatra.http.HttpServer import com.twitter.util.Await import com.twitter.util.Duration import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.sdk.trace.data.SpanData import java.util.concurrent.TimeUnit import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS import static org.awaitility.Awaitility.await class FinatraServerTest extends HttpServerTest implements AgentTestTrait { private static final Duration TIMEOUT = Duration.fromSeconds(5) @Override HttpServer startServer(int port) { HttpServer testServer = new FinatraServer() // Starting the server is blocking so start it in a separate thread Thread startupThread = new Thread({ testServer.main("-admin.port=:0", "-http.port=:" + port) }) startupThread.setDaemon(true) startupThread.start() await() .atMost(1, TimeUnit.MINUTES) .until({ testServer.started() }) return testServer } @Override void stopServer(HttpServer httpServer) { Await.ready(httpServer.close(), TIMEOUT) } @Override boolean hasHandlerSpan(ServerEndpoint endpoint) { endpoint != NOT_FOUND } @Override String expectedServerSpanName(ServerEndpoint endpoint) { return endpoint == NOT_FOUND ? "HTTP GET" : super.expectedServerSpanName(endpoint) } @Override boolean testPathParam() { true } @Override void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) { trace.span(index) { name "FinatraController" kind INTERNAL childOf(parent as SpanData) if (endpoint == EXCEPTION) { status StatusCode.ERROR errorEvent(Exception, EXCEPTION.body) } attributes { } } } }