Write http server tests in java (#5501)
* Write http server tests in java * typo * Apply suggestions from code review Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> * add comments * address review comments * use Predicate Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
parent
b6a5f2876b
commit
b3496381f1
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
|
||||
abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<Object> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ import akka.http.scaladsl.model._
|
|||
import akka.stream.ActorMaterializer
|
||||
import groovy.lang.Closure
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
|
||||
|
||||
import scala.concurrent.{Await, ExecutionContextExecutor, Future}
|
||||
|
||||
|
@ -23,8 +24,7 @@ object AkkaHttpTestAsyncWebServer {
|
|||
val asyncHandler: HttpRequest => Future[HttpResponse] = {
|
||||
case HttpRequest(GET, uri: Uri, _, _, _) =>
|
||||
Future {
|
||||
val endpoint =
|
||||
HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
|
||||
val endpoint = ServerEndpoint.forPath(uri.path.toString())
|
||||
HttpServerTest.controller(
|
||||
endpoint,
|
||||
new Closure[HttpResponse](()) {
|
||||
|
|
|
@ -11,7 +11,8 @@ import akka.http.scaladsl.model._
|
|||
import akka.stream.ActorMaterializer
|
||||
import groovy.lang.Closure
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
|
||||
|
||||
import scala.concurrent.Await
|
||||
|
||||
|
@ -22,7 +23,7 @@ object AkkaHttpTestSyncWebServer {
|
|||
implicit val executionContext = system.dispatcher
|
||||
val syncHandler: HttpRequest => HttpResponse = {
|
||||
case HttpRequest(GET, uri: Uri, _, _, _) => {
|
||||
val endpoint = HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
|
||||
val endpoint = ServerEndpoint.forPath(uri.path.toString())
|
||||
HttpServerTest.controller(
|
||||
endpoint,
|
||||
new Closure[HttpResponse](()) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import akka.http.scaladsl.model._
|
|||
import akka.http.scaladsl.server.Directives._
|
||||
import akka.http.scaladsl.server.ExceptionHandler
|
||||
import akka.stream.ActorMaterializer
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
|
||||
|
||||
import scala.concurrent.Await
|
||||
|
||||
|
|
|
@ -21,19 +21,20 @@ import com.linecorp.armeria.server.ServiceRequestContext
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.api.trace.Span
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
|
||||
import java.util.function.Function
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractArmeriaHttpServerTest extends HttpServerTest<Server> {
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@ import javax.ws.rs.container.Suspended
|
|||
import javax.ws.rs.core.Response
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class DropwizardAsyncTest extends DropwizardTest {
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
|
||||
|
@ -24,15 +25,15 @@ import javax.ws.rs.QueryParam
|
|||
import javax.ws.rs.core.Response
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class DropwizardTest extends HttpServerTest<DropwizardTestSupport> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -13,12 +13,13 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class FinatraServerLatestTest extends HttpServerTest<HttpServer> implements AgentTestTrait {
|
||||
private static final Duration TIMEOUT = Duration.fromSeconds(5)
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.twitter.finagle.http.{Request, Response}
|
|||
import com.twitter.finatra.http.Controller
|
||||
import com.twitter.util.Future
|
||||
import groovy.lang.Closure
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.controller
|
||||
|
||||
class FinatraController extends Controller {
|
||||
|
|
|
@ -10,14 +10,15 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
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.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static org.awaitility.Awaitility.await
|
||||
|
||||
class FinatraServerTest extends HttpServerTest<HttpServer> implements AgentTestTrait {
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.twitter.finagle.http.{Request, Response}
|
|||
import com.twitter.finatra.http.Controller
|
||||
import com.twitter.util.Future
|
||||
import groovy.lang.Closure
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.controller
|
||||
|
||||
class FinatraController extends Controller {
|
||||
|
|
|
@ -8,7 +8,7 @@ package test
|
|||
import grails.artefact.Controller
|
||||
import grails.web.Action
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
|
||||
class ErrorController implements Controller {
|
||||
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import grails.boot.GrailsApp
|
||||
import grails.boot.config.GrailsAutoConfiguration
|
||||
import groovy.transform.CompileStatic
|
||||
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 org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
|
||||
class GrailsTest extends HttpServerTest<ConfigurableApplicationContext> implements AgentTestTrait {
|
||||
|
||||
@CompileStatic
|
||||
@SpringBootApplication
|
||||
static class TestApplication extends GrailsAutoConfiguration {
|
||||
static ConfigurableApplicationContext start(int port, String contextPath) {
|
||||
GrailsApp grailsApp = new GrailsApp(TestApplication)
|
||||
// context path configuration property name changes between spring boot versions
|
||||
def contextPathKey = "server.context-path"
|
||||
try {
|
||||
ServerProperties.getDeclaredMethod("getServlet")
|
||||
contextPathKey = "server.servlet.contextPath"
|
||||
} catch (NoSuchMethodException ignore) {
|
||||
}
|
||||
Map<String, Object> properties = new HashMap<>()
|
||||
properties.put("server.port", port)
|
||||
properties.put(contextPathKey, contextPath)
|
||||
grailsApp.setDefaultProperties(properties)
|
||||
return grailsApp.run()
|
||||
}
|
||||
|
||||
@Override
|
||||
Collection<Class> classes() {
|
||||
return Arrays.asList(TestController, ErrorController, UrlMappings)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint) {
|
||||
if (endpoint == PATH_PARAM) {
|
||||
return getContextPath() + "/test/path"
|
||||
} else if (endpoint == QUERY_PARAM) {
|
||||
return getContextPath() + "/test/query"
|
||||
} else if (endpoint == ERROR) {
|
||||
return getContextPath() + "/test/error"
|
||||
} else if (endpoint == NOT_FOUND) {
|
||||
return getContextPath() + "/**"
|
||||
}
|
||||
return getContextPath() + "/test" + endpoint.path
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigurableApplicationContext startServer(int port) {
|
||||
return TestApplication.start(port, getContextPath())
|
||||
}
|
||||
|
||||
@Override
|
||||
void stopServer(ConfigurableApplicationContext ctx) {
|
||||
ctx.close()
|
||||
}
|
||||
|
||||
@Override
|
||||
String getContextPath() {
|
||||
return "/xyz"
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean hasHandlerSpan(ServerEndpoint endpoint) {
|
||||
true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean hasResponseSpan(ServerEndpoint endpoint) {
|
||||
endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean hasErrorPageSpans(ServerEndpoint endpoint) {
|
||||
endpoint == ERROR || endpoint == EXCEPTION || endpoint == NOT_FOUND
|
||||
}
|
||||
|
||||
@Override
|
||||
int getErrorPageSpansCount(ServerEndpoint endpoint) {
|
||||
endpoint == NOT_FOUND ? 2 : 1
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testPathParam() {
|
||||
true
|
||||
}
|
||||
|
||||
@Override
|
||||
void errorPageSpans(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) {
|
||||
trace.span(index) {
|
||||
name endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index"
|
||||
kind INTERNAL
|
||||
attributes {
|
||||
}
|
||||
}
|
||||
if (endpoint == NOT_FOUND) {
|
||||
trace.span(index + 1) {
|
||||
name ~/\.sendError$/
|
||||
kind INTERNAL
|
||||
attributes {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void responseSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) {
|
||||
trace.span(index) {
|
||||
name endpoint == REDIRECT ? ~/\.sendRedirect$/ : ~/\.sendError$/
|
||||
kind INTERNAL
|
||||
attributes {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) {
|
||||
trace.span(index) {
|
||||
if (endpoint == QUERY_PARAM) {
|
||||
name "TestController.query"
|
||||
} else if (endpoint == PATH_PARAM) {
|
||||
name "TestController.path"
|
||||
} else if (endpoint == CAPTURE_HEADERS) {
|
||||
name "TestController.captureHeaders"
|
||||
} else if (endpoint == INDEXED_CHILD) {
|
||||
name "TestController.child"
|
||||
} else if (endpoint == NOT_FOUND) {
|
||||
name "ResourceHttpRequestHandler.handleRequest"
|
||||
} else {
|
||||
name "TestController.${endpoint.name().toLowerCase()}"
|
||||
}
|
||||
kind INTERNAL
|
||||
if (endpoint == EXCEPTION) {
|
||||
status StatusCode.ERROR
|
||||
errorEvent(Exception, EXCEPTION.body)
|
||||
}
|
||||
childOf((SpanData) parent)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,14 +9,14 @@ import grails.artefact.Controller
|
|||
import grails.web.Action
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class TestController implements Controller {
|
||||
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package test;
|
||||
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
|
||||
import grails.boot.GrailsApp;
|
||||
import grails.boot.config.GrailsAutoConfiguration;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
|
||||
import io.opentelemetry.sdk.trace.data.StatusData;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
public class GrailsTest extends AbstractHttpServerTest<ConfigurableApplicationContext> {
|
||||
|
||||
@RegisterExtension
|
||||
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();
|
||||
|
||||
@Override
|
||||
protected ConfigurableApplicationContext setupServer() {
|
||||
return startServer(port);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopServer(ConfigurableApplicationContext ctx) {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpServerTestOptions options) {
|
||||
options.setContextPath(getContextPath());
|
||||
options.setHasHandlerSpan(unused -> true);
|
||||
options.setHasResponseSpan(
|
||||
endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND);
|
||||
options.setHasErrorPageSpans(
|
||||
endpoint -> endpoint == ERROR || endpoint == EXCEPTION || endpoint == NOT_FOUND);
|
||||
options.setTestPathParam(true);
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
static class TestApplication extends GrailsAutoConfiguration {
|
||||
static ConfigurableApplicationContext start(int port, String contextPath) {
|
||||
GrailsApp grailsApp = new GrailsApp(TestApplication.class);
|
||||
// context path configuration property name changes between spring boot versions
|
||||
String contextPathKey;
|
||||
try {
|
||||
Method method = ServerProperties.class.getDeclaredMethod("getServlet");
|
||||
contextPathKey = "server.servlet.contextPath";
|
||||
} catch (NoSuchMethodException ignore) {
|
||||
contextPathKey = "server.context-path";
|
||||
}
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put("server.port", port);
|
||||
properties.put(contextPathKey, contextPath);
|
||||
grailsApp.setDefaultProperties(properties);
|
||||
return grailsApp.run();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Collection<Class> classes() {
|
||||
// java compiler does not see groovy classes
|
||||
return Arrays.asList(
|
||||
load("test.TestController"), load("test.ErrorController"), load("test.UrlMappings"));
|
||||
}
|
||||
|
||||
private static Class<?> load(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (ClassNotFoundException exception) {
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getContextPath() {
|
||||
return "/xyz";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String expectedHttpRoute(ServerEndpoint endpoint) {
|
||||
switch (endpoint) {
|
||||
case PATH_PARAM:
|
||||
return getContextPath() + "/test/path";
|
||||
case QUERY_PARAM:
|
||||
return getContextPath() + "/test/query";
|
||||
case ERROR:
|
||||
return getContextPath() + "/test/error";
|
||||
case NOT_FOUND:
|
||||
return getContextPath() + "/**";
|
||||
default:
|
||||
return getContextPath() + "/test" + endpoint.getPath();
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurableApplicationContext startServer(int port) {
|
||||
return TestApplication.start(port, getContextPath());
|
||||
}
|
||||
|
||||
private static String getHandlerSpanName(ServerEndpoint endpoint) {
|
||||
switch (endpoint) {
|
||||
case QUERY_PARAM:
|
||||
return "TestController.query";
|
||||
case PATH_PARAM:
|
||||
return "TestController.path";
|
||||
case CAPTURE_HEADERS:
|
||||
return "TestController.captureHeaders";
|
||||
case INDEXED_CHILD:
|
||||
return "TestController.child";
|
||||
case NOT_FOUND:
|
||||
return "ResourceHttpRequestHandler.handleRequest";
|
||||
default:
|
||||
return "TestController." + endpoint.name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpanDataAssert assertHandlerSpan(
|
||||
SpanDataAssert span, String method, ServerEndpoint endpoint) {
|
||||
span.hasName(getHandlerSpanName(endpoint)).hasKind(SpanKind.INTERNAL);
|
||||
if (endpoint == EXCEPTION) {
|
||||
span.hasStatus(StatusData.error());
|
||||
span.hasException(new Exception(EXCEPTION.getBody()));
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpanDataAssert assertResponseSpan(
|
||||
SpanDataAssert span, String method, ServerEndpoint endpoint) {
|
||||
if (endpoint == REDIRECT) {
|
||||
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"));
|
||||
} else {
|
||||
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"));
|
||||
}
|
||||
span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty);
|
||||
return span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
|
||||
String method, ServerEndpoint endpoint) {
|
||||
List<Consumer<SpanDataAssert>> spanAssertions = new ArrayList<>();
|
||||
spanAssertions.add(
|
||||
span ->
|
||||
span.hasName(
|
||||
endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
.hasAttributesSatisfying(Attributes::isEmpty));
|
||||
if (endpoint == NOT_FOUND) {
|
||||
spanAssertions.add(
|
||||
span ->
|
||||
span.satisfies(
|
||||
spanData -> Assertions.assertThat(spanData.getName()).endsWith(".sendError"))
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
.hasAttributesSatisfying(Attributes::isEmpty));
|
||||
}
|
||||
return spanAssertions;
|
||||
}
|
||||
}
|
|
@ -16,12 +16,12 @@ import javax.ws.rs.core.Response
|
|||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class GrizzlyAsyncTest extends GrizzlyTest {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.glassfish.grizzly.filterchain.BaseFilter
|
||||
import org.glassfish.grizzly.filterchain.FilterChain
|
||||
|
@ -29,15 +30,15 @@ import org.glassfish.grizzly.utils.IdleTimeoutFilter
|
|||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static java.lang.String.valueOf
|
||||
import static java.nio.charset.Charset.defaultCharset
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS
|
||||
|
@ -150,7 +151,7 @@ class GrizzlyFilterchainServerTest extends HttpServerTest<HttpServer> implements
|
|||
String uri = request.getRequestURI()
|
||||
Map<String, String> headers = new HashMap<>()
|
||||
|
||||
HttpServerTest.ServerEndpoint endpoint
|
||||
ServerEndpoint endpoint
|
||||
Closure closure
|
||||
switch (uri) {
|
||||
case "/success":
|
||||
|
@ -198,12 +199,12 @@ class GrizzlyFilterchainServerTest extends HttpServerTest<HttpServer> implements
|
|||
|
||||
static class ResponseParameters {
|
||||
Map<String, String> headers
|
||||
HttpServerTest.ServerEndpoint endpoint
|
||||
ServerEndpoint endpoint
|
||||
int status
|
||||
byte[] responseBody
|
||||
Closure closure
|
||||
|
||||
ResponseParameters(HttpServerTest.ServerEndpoint endpoint,
|
||||
ResponseParameters(ServerEndpoint endpoint,
|
||||
int status,
|
||||
byte[] responseBody,
|
||||
Map<String, String> headers,
|
||||
|
@ -223,7 +224,7 @@ class GrizzlyFilterchainServerTest extends HttpServerTest<HttpServer> implements
|
|||
return responseBody
|
||||
}
|
||||
|
||||
HttpServerTest.ServerEndpoint getEndpoint() {
|
||||
ServerEndpoint getEndpoint() {
|
||||
return endpoint
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.glassfish.grizzly.http.server.HttpHandler
|
||||
import org.glassfish.grizzly.http.server.HttpServer
|
||||
|
@ -20,12 +21,12 @@ import javax.ws.rs.QueryParam
|
|||
import javax.ws.rs.core.Response
|
||||
import javax.ws.rs.ext.ExceptionMapper
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class GrizzlyTest extends HttpServerTest<HttpServer> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import spock.lang.Unroll
|
||||
|
@ -14,9 +15,9 @@ import test.JaxRsTestResource
|
|||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
||||
import static io.opentelemetry.api.trace.StatusCode.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
|
||||
import static java.util.concurrent.TimeUnit.SECONDS
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue
|
||||
|
|
|
@ -24,14 +24,14 @@ import java.util.concurrent.CompletableFuture
|
|||
import java.util.concurrent.CompletionStage
|
||||
import java.util.concurrent.CyclicBarrier
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
@Path("")
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import jakarta.servlet.DispatcherType
|
||||
import jakarta.servlet.ServletException
|
||||
|
@ -19,14 +20,14 @@ import org.eclipse.jetty.server.handler.AbstractHandler
|
|||
import org.eclipse.jetty.server.handler.ErrorHandler
|
||||
import spock.lang.Shared
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class JettyHandlerTest extends HttpServerTest<Server> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.eclipse.jetty.server.Request
|
||||
import org.eclipse.jetty.server.Response
|
||||
|
@ -20,14 +21,14 @@ import javax.servlet.ServletException
|
|||
import javax.servlet.http.HttpServletRequest
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class JettyHandlerTest extends HttpServerTest<Server> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -9,11 +9,12 @@ import io.ktor.server.engine.ApplicationEngine
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.LibraryTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
|
||||
class KtorHttpServerTest extends HttpServerTest<ApplicationEngine> implements LibraryTestTrait {
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ import io.opentelemetry.api.trace.SpanKind
|
|||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.context.Context
|
||||
import io.opentelemetry.extension.kotlin.asContextElement
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.*
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.*
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
|
@ -90,7 +90,7 @@ class TestServer {
|
|||
}
|
||||
|
||||
// Copy in HttpServerTest.controller but make it a suspending function
|
||||
private suspend fun controller(endpoint: HttpServerTest.ServerEndpoint, wrapped: suspend () -> Unit) {
|
||||
private suspend fun controller(endpoint: ServerEndpoint, wrapped: suspend () -> Unit) {
|
||||
assert(Span.current().spanContext.isValid, { "Controller should have a parent span. " })
|
||||
if (endpoint == NOT_FOUND) {
|
||||
wrapped()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.jboss.netty.bootstrap.ServerBootstrap
|
||||
import org.jboss.netty.buffer.ChannelBuffer
|
||||
|
@ -33,15 +34,15 @@ import org.jboss.netty.logging.InternalLoggerFactory
|
|||
import org.jboss.netty.logging.Slf4JLoggerFactory
|
||||
import org.jboss.netty.util.CharsetUtil
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.forPath
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.forPath
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.LOCATION
|
||||
|
@ -66,7 +67,7 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> implements Agent
|
|||
if (msg.getMessage() instanceof HttpRequest) {
|
||||
def request = msg.getMessage() as HttpRequest
|
||||
def uri = URI.create(request.getUri())
|
||||
HttpServerTest.ServerEndpoint endpoint = forPath(uri.path)
|
||||
ServerEndpoint endpoint = forPath(uri.path)
|
||||
ctx.sendDownstream controller(endpoint) {
|
||||
HttpResponse response
|
||||
ChannelBuffer responseContent = null
|
||||
|
|
|
@ -27,20 +27,21 @@ import io.netty.util.CharsetUtil
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE
|
||||
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR
|
||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class Netty40ServerTest extends HttpServerTest<EventLoopGroup> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -26,20 +26,21 @@ import io.netty.util.CharsetUtil
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH
|
||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE
|
||||
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR
|
||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class Netty41ServerTest extends HttpServerTest<EventLoopGroup> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@ import play.server.Server
|
|||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.function.Supplier
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static play.mvc.Http.Context.Implicit.request
|
||||
|
||||
class PlayAsyncServerTest extends PlayServerTest {
|
||||
|
|
|
@ -10,6 +10,7 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import play.mvc.Results
|
||||
|
@ -19,13 +20,13 @@ import play.server.Server
|
|||
import java.util.function.Supplier
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static play.mvc.Http.Context.Implicit.request
|
||||
|
||||
class PlayServerTest extends HttpServerTest<Server> implements AgentTestTrait {
|
||||
|
|
|
@ -18,13 +18,13 @@ import java.util.concurrent.CompletableFuture
|
|||
import java.util.concurrent.Executors
|
||||
import java.util.function.Supplier
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class PlayAsyncServerTest extends PlayServerTest {
|
||||
@Shared
|
||||
|
|
|
@ -10,6 +10,7 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import play.BuiltInComponents
|
||||
import play.Mode
|
||||
|
@ -21,13 +22,13 @@ import play.server.Server
|
|||
import java.util.function.Supplier
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class PlayServerTest extends HttpServerTest<Server> implements AgentTestTrait {
|
||||
@Override
|
||||
|
|
|
@ -9,14 +9,14 @@ import ratpack.error.ServerErrorHandler
|
|||
import ratpack.exec.Promise
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractRatpackAsyncHttpServerTest extends AbstractRatpackHttpServerTest {
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@ import ratpack.exec.Result
|
|||
import ratpack.exec.util.ParallelBatch
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractRatpackForkedHttpServerTest extends AbstractRatpackHttpServerTest {
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ package io.opentelemetry.instrumentation.ratpack.server
|
|||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import ratpack.error.ServerErrorHandler
|
||||
import ratpack.handling.Context
|
||||
|
@ -16,14 +17,14 @@ import ratpack.server.RatpackServer
|
|||
import ratpack.server.RatpackServerSpec
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractRatpackHttpServerTest extends HttpServerTest<RatpackServer> {
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ratpack.server
|
|||
|
||||
import io.opentelemetry.instrumentation.ratpack.RatpackTracing
|
||||
import io.opentelemetry.instrumentation.test.LibraryTestTrait
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import ratpack.server.RatpackServerSpec
|
||||
|
||||
class RatpackAsyncHttpServerTest extends AbstractRatpackAsyncHttpServerTest implements LibraryTestTrait {
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ratpack.server
|
|||
|
||||
import io.opentelemetry.instrumentation.ratpack.RatpackTracing
|
||||
import io.opentelemetry.instrumentation.test.LibraryTestTrait
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import ratpack.server.RatpackServerSpec
|
||||
|
||||
class RatpackForkedHttpServerTest extends AbstractRatpackForkedHttpServerTest implements LibraryTestTrait {
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ratpack.server
|
|||
|
||||
import io.opentelemetry.instrumentation.ratpack.RatpackTracing
|
||||
import io.opentelemetry.instrumentation.test.LibraryTestTrait
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import ratpack.server.RatpackServerSpec
|
||||
|
||||
class RatpackHttpServerTest extends AbstractRatpackHttpServerTest implements LibraryTestTrait {
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.restlet.v1_0
|
|||
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.restlet.Component
|
||||
import org.restlet.Context
|
||||
import org.restlet.Redirector
|
||||
|
@ -22,15 +23,15 @@ import org.restlet.data.Response
|
|||
import org.restlet.data.Status
|
||||
import org.restlet.util.Template
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractRestletServerTest extends HttpServerTest<Server> {
|
||||
|
||||
|
@ -156,6 +157,11 @@ abstract class AbstractRestletServerTest extends HttpServerTest<Server> {
|
|||
true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testErrorBody() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint) {
|
||||
switch (endpoint) {
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.restlet.v1_0
|
|||
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.util.resource.Resource
|
||||
import org.eclipse.jetty.webapp.WebAppContext
|
||||
|
@ -14,15 +15,15 @@ import org.restlet.Application
|
|||
import org.restlet.Restlet
|
||||
import org.restlet.Router
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractServletServerTest extends HttpServerTest<Server> {
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ import org.restlet.resource.Resource
|
|||
import org.restlet.resource.StringRepresentation
|
||||
import org.restlet.resource.Variant
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.controller
|
||||
|
||||
class RestletAppTestBase {
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.restlet.v2_0
|
|||
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.restlet.Component
|
||||
import org.restlet.Context
|
||||
import org.restlet.Request
|
||||
|
@ -22,15 +23,15 @@ import org.restlet.routing.Router
|
|||
import org.restlet.routing.Template
|
||||
import org.restlet.routing.VirtualHost
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractRestletServerTest extends HttpServerTest<Server> {
|
||||
|
||||
|
@ -169,6 +170,11 @@ abstract class AbstractRestletServerTest extends HttpServerTest<Server> {
|
|||
true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testErrorBody() {
|
||||
false
|
||||
}
|
||||
|
||||
@Override
|
||||
String expectedHttpRoute(ServerEndpoint endpoint) {
|
||||
switch (endpoint) {
|
||||
|
|
|
@ -11,14 +11,14 @@ import org.restlet.data.Status
|
|||
import org.restlet.resource.Get
|
||||
import org.restlet.resource.ServerResource
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.controller
|
||||
|
||||
class RestletAppTestBase {
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.eclipse.jetty.server.Server
|
||||
|
@ -16,15 +17,15 @@ import org.eclipse.jetty.servlet.ServletContextHandler
|
|||
import javax.servlet.http.HttpServletRequest
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class JettyServlet2Test extends HttpServerTest<Server> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
|
||||
import groovy.servlet.AbstractHttpServlet
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class TestServlet2 {
|
||||
|
||||
|
@ -22,7 +22,7 @@ class TestServlet2 {
|
|||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
req.getRequestDispatcher()
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
HttpServerTest.controller(endpoint) {
|
||||
resp.contentType = "text/plain"
|
||||
switch (endpoint) {
|
||||
|
|
|
@ -6,20 +6,21 @@
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
||||
|
||||
import javax.servlet.Servlet
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractServlet3Test<SERVER, CONTEXT> extends HttpServerTest<SERVER> implements AgentTestTrait {
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler
|
||||
|
@ -12,15 +13,15 @@ import javax.servlet.Servlet
|
|||
import javax.servlet.ServletException
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class JettyServlet3Test extends AbstractServlet3Test<Server, ServletContextHandler> {
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import org.eclipse.jetty.server.Server
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler
|
||||
|
@ -14,7 +15,7 @@ import javax.servlet.Servlet
|
|||
import javax.servlet.ServletException
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
|
||||
class JettyServletHandlerTest extends AbstractServlet3Test<Server, ServletHandler> {
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import groovy.servlet.AbstractHttpServlet
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import javax.servlet.RequestDispatcher
|
||||
import javax.servlet.ServletException
|
||||
import javax.servlet.annotation.WebServlet
|
||||
|
@ -13,14 +13,14 @@ import javax.servlet.http.HttpServletRequest
|
|||
import javax.servlet.http.HttpServletResponse
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class TestServlet3 {
|
||||
|
||||
|
@ -32,7 +32,7 @@ class TestServlet3 {
|
|||
if (servletPath == null) {
|
||||
servletPath = req.servletPath
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(servletPath)
|
||||
HttpServerTest.controller(endpoint) {
|
||||
resp.contentType = "text/plain"
|
||||
switch (endpoint) {
|
||||
|
@ -79,7 +79,7 @@ class TestServlet3 {
|
|||
static class Async extends AbstractHttpServlet {
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
def latch = new CountDownLatch(1)
|
||||
def context = req.startAsync()
|
||||
if (endpoint == EXCEPTION) {
|
||||
|
@ -157,7 +157,7 @@ class TestServlet3 {
|
|||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
def context = req.startAsync()
|
||||
try {
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
HttpServerTest.controller(endpoint) {
|
||||
resp.contentType = "text/plain"
|
||||
switch (endpoint) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse
|
||||
import org.apache.catalina.AccessLog
|
||||
import org.apache.catalina.Context
|
||||
|
@ -24,16 +25,16 @@ import java.nio.file.Files
|
|||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue
|
||||
|
||||
@Unroll
|
||||
|
|
|
@ -6,19 +6,20 @@
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
||||
import jakarta.servlet.Servlet
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class AbstractServlet5Test<SERVER, CONTEXT> extends HttpServerTest<SERVER> implements AgentTestTrait {
|
||||
@Override
|
||||
|
|
|
@ -11,15 +11,15 @@ import org.eclipse.jetty.server.handler.ErrorHandler
|
|||
import org.eclipse.jetty.servlet.ServletContextHandler
|
||||
import spock.lang.IgnoreIf
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
abstract class JettyServlet5Test extends AbstractServlet5Test<Object, Object> {
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import jakarta.servlet.Servlet
|
||||
import jakarta.servlet.ServletException
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import jakarta.servlet.RequestDispatcher
|
||||
import jakarta.servlet.ServletException
|
||||
import jakarta.servlet.annotation.WebServlet
|
||||
|
@ -13,14 +14,14 @@ import jakarta.servlet.http.HttpServletResponse
|
|||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class TestServlet5 {
|
||||
|
||||
|
@ -32,7 +33,7 @@ class TestServlet5 {
|
|||
if (servletPath == null) {
|
||||
servletPath = req.servletPath
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(servletPath)
|
||||
HttpServerTest.controller(endpoint) {
|
||||
resp.contentType = "text/plain"
|
||||
switch (endpoint) {
|
||||
|
@ -79,7 +80,7 @@ class TestServlet5 {
|
|||
static class Async extends HttpServlet {
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
def latch = new CountDownLatch(1)
|
||||
def context = req.startAsync()
|
||||
if (endpoint == EXCEPTION) {
|
||||
|
@ -157,7 +158,7 @@ class TestServlet5 {
|
|||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
def context = req.startAsync()
|
||||
try {
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
HttpServerTest.controller(endpoint) {
|
||||
resp.contentType = "text/plain"
|
||||
switch (endpoint) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse
|
||||
import jakarta.servlet.Servlet
|
||||
import jakarta.servlet.ServletException
|
||||
|
@ -24,16 +25,16 @@ import java.nio.file.Files
|
|||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue
|
||||
|
||||
@Unroll
|
||||
|
|
|
@ -7,17 +7,17 @@ package server.base
|
|||
|
||||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
|
||||
abstract class ControllerSpringWebFluxServerTest extends SpringWebFluxServerTest {
|
||||
@Override
|
||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method, HttpServerTest.ServerEndpoint endpoint) {
|
||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method, ServerEndpoint endpoint) {
|
||||
def handlerSpanName = "${ServerTestController.simpleName}.${endpoint.name().toLowerCase()}"
|
||||
if (endpoint == NOT_FOUND) {
|
||||
handlerSpanName = "ResourceWebHandler.handle"
|
||||
|
@ -41,7 +41,7 @@ abstract class ControllerSpringWebFluxServerTest extends SpringWebFluxServerTest
|
|||
}
|
||||
|
||||
@Override
|
||||
boolean hasHandlerAsControllerParentSpan(HttpServerTest.ServerEndpoint endpoint) {
|
||||
boolean hasHandlerAsControllerParentSpan(ServerEndpoint endpoint) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package server.base
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
@ -44,8 +44,7 @@ class DelayedControllerSpringWebFluxServerTest extends ControllerSpringWebFluxSe
|
|||
@RestController
|
||||
static class Controller extends ServerTestController {
|
||||
@Override
|
||||
protected <T> Mono<T> wrapControllerMethod(
|
||||
HttpServerTest.ServerEndpoint endpoint, Callable<T> handler) {
|
||||
protected <T> Mono<T> wrapControllerMethod(ServerEndpoint endpoint, Callable<T> handler) {
|
||||
|
||||
return Mono.just("")
|
||||
.delayElement(Duration.ofMillis(10))
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
|
||||
package server.base
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
@ -44,7 +45,7 @@ class DelayedHandlerSpringWebFluxServerTest extends HandlerSpringWebFluxServerTe
|
|||
static class RouteFactory extends ServerTestRouteFactory {
|
||||
|
||||
@Override
|
||||
protected Mono<ServerResponse> wrapResponse(HttpServerTest.ServerEndpoint endpoint, Mono<ServerResponse> response, Runnable spanAction) {
|
||||
protected Mono<ServerResponse> wrapResponse(ServerEndpoint endpoint, Mono<ServerResponse> response, Runnable spanAction) {
|
||||
return response.delayElement(Duration.ofMillis(10)).map({ original ->
|
||||
return controller(endpoint, {
|
||||
spanAction.run()
|
||||
|
@ -55,7 +56,7 @@ class DelayedHandlerSpringWebFluxServerTest extends HandlerSpringWebFluxServerTe
|
|||
}
|
||||
|
||||
@Override
|
||||
boolean hasHandlerAsControllerParentSpan(HttpServerTest.ServerEndpoint endpoint) {
|
||||
boolean hasHandlerAsControllerParentSpan(ServerEndpoint endpoint) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,17 @@ package server.base
|
|||
|
||||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
|
||||
abstract class HandlerSpringWebFluxServerTest extends SpringWebFluxServerTest {
|
||||
@Override
|
||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method, HttpServerTest.ServerEndpoint endpoint) {
|
||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method, ServerEndpoint endpoint) {
|
||||
def handlerSpanName = "${ServerTestRouteFactory.simpleName}.lambda"
|
||||
if (endpoint == NOT_FOUND) {
|
||||
handlerSpanName = "ResourceWebHandler.handle"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package server.base
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
@ -43,7 +43,7 @@ class ImmediateControllerSpringWebFluxServerTest extends ControllerSpringWebFlux
|
|||
@RestController
|
||||
static class Controller extends ServerTestController {
|
||||
@Override
|
||||
protected <T> Mono<T> wrapControllerMethod(HttpServerTest.ServerEndpoint endpoint, Callable<T> controllerMethod) {
|
||||
protected <T> Mono<T> wrapControllerMethod(ServerEndpoint endpoint, Callable<T> controllerMethod) {
|
||||
return Mono.just(controller(endpoint, controllerMethod))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package server.base
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
@ -42,7 +42,7 @@ class ImmediateHandlerSpringWebFluxServerTest extends HandlerSpringWebFluxServer
|
|||
static class RouteFactory extends ServerTestRouteFactory {
|
||||
|
||||
@Override
|
||||
protected Mono<ServerResponse> wrapResponse(HttpServerTest.ServerEndpoint endpoint, Mono<ServerResponse> response, Runnable spanAction) {
|
||||
protected Mono<ServerResponse> wrapResponse(ServerEndpoint endpoint, Mono<ServerResponse> response, Runnable spanAction) {
|
||||
return controller(endpoint, {
|
||||
spanAction.run()
|
||||
return response
|
||||
|
|
|
@ -7,11 +7,12 @@ package server.base
|
|||
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
|
||||
abstract class SpringWebFluxServerTest extends HttpServerTest<ConfigurableApplicationContext> implements AgentTestTrait {
|
||||
protected abstract Class<?> getApplicationClass();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package server.base;
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.Callable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
|
@ -9,7 +9,7 @@ import static org.springframework.web.reactive.function.server.RequestPredicates
|
|||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
|
|
@ -9,6 +9,7 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpData
|
||||
|
@ -19,13 +20,13 @@ import org.springframework.context.ConfigurableApplicationContext
|
|||
import org.springframework.web.servlet.view.RedirectView
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.LOGIN
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.LOGIN
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ import org.springframework.web.bind.annotation.RequestParam
|
|||
import org.springframework.web.bind.annotation.ResponseBody
|
||||
import org.springframework.web.servlet.view.RedirectView
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
@Controller
|
||||
class TestController {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package test.filter
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.http.HttpInputMessage
|
||||
|
@ -32,14 +33,14 @@ import javax.servlet.http.HttpServletRequest
|
|||
import javax.servlet.http.HttpServletResponse
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
@SpringBootApplication
|
||||
class FilteredAppConfig extends WebMvcConfigurerAdapter {
|
||||
|
@ -91,7 +92,7 @@ class FilteredAppConfig extends WebMvcConfigurerAdapter {
|
|||
void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest req = (HttpServletRequest) request
|
||||
HttpServletResponse resp = (HttpServletResponse) response
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
HttpServerTest.controller(endpoint) {
|
||||
resp.contentType = "text/plain"
|
||||
switch (endpoint) {
|
||||
|
|
|
@ -9,18 +9,19 @@ package test.filter
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
import test.boot.SecurityConfig
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class ServletFilterTest extends HttpServerTest<ConfigurableApplicationContext> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ 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.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import io.opentelemetry.struts.GreetingServlet
|
||||
|
@ -19,11 +20,11 @@ import org.eclipse.jetty.util.resource.FileResource
|
|||
import javax.servlet.DispatcherType
|
||||
|
||||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
|
||||
class Struts2ActionSpanTest extends HttpServerTest<Server> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.struts;
|
|||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
|
@ -17,46 +18,40 @@ public class GreetingAction extends ActionSupport {
|
|||
|
||||
public String success() {
|
||||
responseBody =
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.SUCCESS, HttpServerTest.ServerEndpoint.SUCCESS::getBody);
|
||||
HttpServerTest.controller(ServerEndpoint.SUCCESS, ServerEndpoint.SUCCESS::getBody);
|
||||
|
||||
return "greeting";
|
||||
}
|
||||
|
||||
public String redirect() {
|
||||
responseBody =
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.REDIRECT,
|
||||
HttpServerTest.ServerEndpoint.REDIRECT::getBody);
|
||||
HttpServerTest.controller(ServerEndpoint.REDIRECT, ServerEndpoint.REDIRECT::getBody);
|
||||
return "redirect";
|
||||
}
|
||||
|
||||
public String query_param() {
|
||||
responseBody =
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.QUERY_PARAM,
|
||||
HttpServerTest.ServerEndpoint.QUERY_PARAM::getBody);
|
||||
HttpServerTest.controller(ServerEndpoint.QUERY_PARAM, ServerEndpoint.QUERY_PARAM::getBody);
|
||||
return "greeting";
|
||||
}
|
||||
|
||||
public String error() {
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.ERROR, HttpServerTest.ServerEndpoint.ERROR::getBody);
|
||||
HttpServerTest.controller(ServerEndpoint.ERROR, ServerEndpoint.ERROR::getBody);
|
||||
return "error";
|
||||
}
|
||||
|
||||
public String exception() {
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.EXCEPTION,
|
||||
ServerEndpoint.EXCEPTION,
|
||||
() -> {
|
||||
throw new Exception(HttpServerTest.ServerEndpoint.EXCEPTION.getBody());
|
||||
throw new Exception(ServerEndpoint.EXCEPTION.getBody());
|
||||
});
|
||||
throw new AssertionError(); // should not reach here
|
||||
}
|
||||
|
||||
public String path_param() {
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.PATH_PARAM,
|
||||
ServerEndpoint.PATH_PARAM,
|
||||
() ->
|
||||
"this does nothing, as responseBody is set in setId, but we need this controller span nevertheless");
|
||||
return "greeting";
|
||||
|
@ -65,11 +60,11 @@ public class GreetingAction extends ActionSupport {
|
|||
public String indexed_child() {
|
||||
responseBody =
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.INDEXED_CHILD,
|
||||
ServerEndpoint.INDEXED_CHILD,
|
||||
() -> {
|
||||
HttpServerTest.ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(
|
||||
ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(
|
||||
(name) -> ServletActionContext.getRequest().getParameter(name));
|
||||
return HttpServerTest.ServerEndpoint.INDEXED_CHILD.getBody();
|
||||
return ServerEndpoint.INDEXED_CHILD.getBody();
|
||||
});
|
||||
return "greeting";
|
||||
}
|
||||
|
@ -80,8 +75,7 @@ public class GreetingAction extends ActionSupport {
|
|||
response.setHeader("X-Test-Response", request.getHeader("X-Test-Request"));
|
||||
responseBody =
|
||||
HttpServerTest.controller(
|
||||
HttpServerTest.ServerEndpoint.CAPTURE_HEADERS,
|
||||
HttpServerTest.ServerEndpoint.CAPTURE_HEADERS::getBody);
|
||||
ServerEndpoint.CAPTURE_HEADERS, ServerEndpoint.CAPTURE_HEADERS::getBody);
|
||||
return "greeting";
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import jakarta.servlet.ServletException
|
||||
import jakarta.servlet.annotation.WebServlet
|
||||
import jakarta.servlet.http.HttpServlet
|
||||
|
@ -14,19 +15,19 @@ import jakarta.servlet.http.HttpServletResponse
|
|||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
@WebServlet(asyncSupported = true)
|
||||
class AsyncServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
def latch = new CountDownLatch(1)
|
||||
def context = req.startAsync()
|
||||
if (endpoint == EXCEPTION) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -18,18 +19,18 @@ public class TestServlet extends HttpServlet {
|
|||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
String path = req.getServletPath();
|
||||
|
||||
HttpServerTest.ServerEndpoint serverEndpoint = HttpServerTest.ServerEndpoint.forPath(path);
|
||||
ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path);
|
||||
if (serverEndpoint != null) {
|
||||
HttpServerTest.controller(
|
||||
serverEndpoint,
|
||||
() -> {
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.EXCEPTION) {
|
||||
if (serverEndpoint == ServerEndpoint.EXCEPTION) {
|
||||
throw new Exception(serverEndpoint.getBody());
|
||||
}
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_HEADERS) {
|
||||
if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) {
|
||||
resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request"));
|
||||
}
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS) {
|
||||
if (serverEndpoint == ServerEndpoint.CAPTURE_PARAMETERS) {
|
||||
req.setCharacterEncoding("UTF8");
|
||||
String value = req.getParameter("test-parameter");
|
||||
if (!"test value õäöü".equals(value)) {
|
||||
|
@ -37,13 +38,13 @@ public class TestServlet extends HttpServlet {
|
|||
"request parameter does not have expected value " + value);
|
||||
}
|
||||
}
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.INDEXED_CHILD) {
|
||||
HttpServerTest.ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter);
|
||||
if (serverEndpoint == ServerEndpoint.INDEXED_CHILD) {
|
||||
ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter);
|
||||
}
|
||||
resp.getWriter().print(serverEndpoint.getBody());
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.REDIRECT) {
|
||||
if (serverEndpoint == ServerEndpoint.REDIRECT) {
|
||||
resp.sendRedirect(serverEndpoint.getBody());
|
||||
} else if (serverEndpoint == HttpServerTest.ServerEndpoint.ERROR) {
|
||||
} else if (serverEndpoint == ServerEndpoint.ERROR) {
|
||||
resp.sendError(serverEndpoint.getStatus(), serverEndpoint.getBody());
|
||||
} else {
|
||||
resp.setStatus(serverEndpoint.getStatus());
|
||||
|
|
|
@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import jakarta.servlet.Servlet
|
||||
import jakarta.servlet.ServletException
|
||||
import org.apache.catalina.Context
|
||||
|
@ -19,15 +20,15 @@ import spock.lang.Unroll
|
|||
|
||||
import java.nio.file.Files
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
@Unroll
|
||||
class TomcatAsyncTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||
|
|
|
@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.apache.catalina.Context
|
||||
import org.apache.catalina.connector.Request
|
||||
import org.apache.catalina.connector.Response
|
||||
|
@ -16,9 +17,9 @@ import org.apache.catalina.core.StandardHost
|
|||
import org.apache.catalina.startup.Tomcat
|
||||
import org.apache.catalina.valves.ErrorReportValve
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
|
||||
class TomcatHandlerTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -7,26 +7,26 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0
|
|||
|
||||
import groovy.servlet.AbstractHttpServlet
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import javax.servlet.ServletException
|
||||
import javax.servlet.annotation.WebServlet
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
@WebServlet(asyncSupported = true)
|
||||
class AsyncServlet extends AbstractHttpServlet {
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp) {
|
||||
HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath)
|
||||
ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath)
|
||||
def latch = new CountDownLatch(1)
|
||||
def context = req.startAsync()
|
||||
if (endpoint == EXCEPTION) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest;
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
@ -18,18 +19,18 @@ public class TestServlet extends HttpServlet {
|
|||
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
String path = req.getServletPath();
|
||||
|
||||
HttpServerTest.ServerEndpoint serverEndpoint = HttpServerTest.ServerEndpoint.forPath(path);
|
||||
ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path);
|
||||
if (serverEndpoint != null) {
|
||||
HttpServerTest.controller(
|
||||
serverEndpoint,
|
||||
() -> {
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.EXCEPTION) {
|
||||
if (serverEndpoint == ServerEndpoint.EXCEPTION) {
|
||||
throw new Exception(serverEndpoint.getBody());
|
||||
}
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_HEADERS) {
|
||||
if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) {
|
||||
resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request"));
|
||||
}
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS) {
|
||||
if (serverEndpoint == ServerEndpoint.CAPTURE_PARAMETERS) {
|
||||
req.setCharacterEncoding("UTF8");
|
||||
String value = req.getParameter("test-parameter");
|
||||
if (!"test value õäöü".equals(value)) {
|
||||
|
@ -37,13 +38,13 @@ public class TestServlet extends HttpServlet {
|
|||
"request parameter does not have expected value " + value);
|
||||
}
|
||||
}
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.INDEXED_CHILD) {
|
||||
HttpServerTest.ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter);
|
||||
if (serverEndpoint == ServerEndpoint.INDEXED_CHILD) {
|
||||
ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter);
|
||||
}
|
||||
resp.getWriter().print(serverEndpoint.getBody());
|
||||
if (serverEndpoint == HttpServerTest.ServerEndpoint.REDIRECT) {
|
||||
if (serverEndpoint == ServerEndpoint.REDIRECT) {
|
||||
resp.sendRedirect(serverEndpoint.getBody());
|
||||
} else if (serverEndpoint == HttpServerTest.ServerEndpoint.ERROR) {
|
||||
} else if (serverEndpoint == ServerEndpoint.ERROR) {
|
||||
resp.sendError(serverEndpoint.getStatus(), serverEndpoint.getBody());
|
||||
} else {
|
||||
resp.setStatus(serverEndpoint.getStatus());
|
||||
|
|
|
@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.apache.catalina.Context
|
||||
import org.apache.catalina.startup.Tomcat
|
||||
import org.apache.tomcat.JarScanFilter
|
||||
|
@ -19,15 +20,15 @@ import javax.servlet.Servlet
|
|||
import javax.servlet.ServletException
|
||||
import java.nio.file.Files
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
@Unroll
|
||||
class TomcatAsyncTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||
|
|
|
@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0
|
|||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import org.apache.catalina.Context
|
||||
import org.apache.catalina.connector.Request
|
||||
import org.apache.catalina.connector.Response
|
||||
|
@ -16,9 +17,9 @@ import org.apache.catalina.core.StandardHost
|
|||
import org.apache.catalina.startup.Tomcat
|
||||
import org.apache.catalina.valves.ErrorReportValve
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
|
||||
class TomcatHandlerTest extends HttpServerTest<Tomcat> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import io.undertow.Handlers
|
||||
import io.undertow.Undertow
|
||||
|
@ -13,12 +14,12 @@ import io.undertow.util.Headers
|
|||
import io.undertow.util.HttpString
|
||||
import io.undertow.util.StatusCodes
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class UndertowServerDispatchTest extends HttpServerTest<Undertow> implements AgentTestTrait {
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.opentelemetry.api.trace.SpanKind
|
|||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse
|
||||
import io.undertow.Handlers
|
||||
|
@ -17,13 +18,13 @@ import io.undertow.util.Headers
|
|||
import io.undertow.util.HttpString
|
||||
import io.undertow.util.StatusCodes
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
//TODO make test which mixes handlers and servlets
|
||||
class UndertowServerTest extends HttpServerTest<Undertow> implements AgentTestTrait {
|
||||
|
|
|
@ -23,7 +23,7 @@ import static VertxReactiveWebServer.TEST_REQUEST_ID_ATTRIBUTE
|
|||
import static VertxReactiveWebServer.TEST_REQUEST_ID_PARAMETER
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
|
||||
|
||||
class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
|
||||
package server
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.vertx.circuitbreaker.CircuitBreakerOptions
|
||||
import io.vertx.core.Promise
|
||||
import io.vertx.reactivex.circuitbreaker.CircuitBreaker
|
||||
import io.vertx.reactivex.core.AbstractVerticle
|
||||
import io.vertx.reactivex.ext.web.Router
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
||||
|
||||
|
@ -49,7 +49,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(endpoint.body)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
endpoint.collectSpanAttributes { ctx.request().params().get(it) }
|
||||
ctx.response().setStatusCode(endpoint.status).end()
|
||||
|
@ -76,7 +76,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(ctx.request().query())
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).putHeader("location", endpoint.body).end()
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(endpoint.body)
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(ctx.request().getParam("id"))
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status)
|
||||
.putHeader("X-Test-Response", ctx.request().getHeader("X-Test-Request"))
|
||||
|
@ -159,7 +159,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
boolean hasExceptionOnServerSpan(HttpServerTest.ServerEndpoint endpoint) {
|
||||
boolean hasExceptionOnServerSpan(ServerEndpoint endpoint) {
|
||||
return endpoint != EXCEPTION && super.hasExceptionOnServerSpan(endpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@ import io.vertx.reactivex.ext.web.Router
|
|||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class VertxRxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTrait {
|
||||
public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
|
|
|
@ -23,7 +23,7 @@ import static VertxReactiveWebServer.TEST_REQUEST_ID_ATTRIBUTE
|
|||
import static VertxReactiveWebServer.TEST_REQUEST_ID_PARAMETER
|
||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT
|
||||
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
|
||||
|
||||
class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
|
||||
package server
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.vertx.circuitbreaker.CircuitBreakerOptions
|
||||
import io.vertx.core.Future
|
||||
import io.vertx.reactivex.circuitbreaker.CircuitBreaker
|
||||
import io.vertx.reactivex.core.AbstractVerticle
|
||||
import io.vertx.reactivex.ext.web.Router
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
||||
|
||||
|
@ -49,7 +49,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(endpoint.body)
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
endpoint.collectSpanAttributes { ctx.request().params().get(it) }
|
||||
ctx.response().setStatusCode(endpoint.status).end()
|
||||
|
@ -76,7 +76,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(ctx.request().query())
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).putHeader("location", endpoint.body).end()
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(endpoint.body)
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status).end(ctx.request().getParam("id"))
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
if (it.failed()) {
|
||||
throw it.cause()
|
||||
}
|
||||
HttpServerTest.ServerEndpoint endpoint = it.result()
|
||||
ServerEndpoint endpoint = it.result()
|
||||
controller(endpoint) {
|
||||
ctx.response().setStatusCode(endpoint.status)
|
||||
.putHeader("X-Test-Response", ctx.request().getHeader("X-Test-Request"))
|
||||
|
@ -158,7 +158,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
boolean hasExceptionOnServerSpan(HttpServerTest.ServerEndpoint endpoint) {
|
||||
boolean hasExceptionOnServerSpan(ServerEndpoint endpoint) {
|
||||
return endpoint != EXCEPTION && super.hasExceptionOnServerSpan(endpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@ import io.vertx.reactivex.ext.web.Router
|
|||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
|
||||
class VertxRxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTrait {
|
||||
public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
package server;
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT;
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
|
||||
|
||||
import io.opentelemetry.instrumentation.test.base.HttpServerTest;
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
|
|
|
@ -5,54 +5,42 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.test.base
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry
|
||||
import io.opentelemetry.api.common.AttributeKey
|
||||
import io.opentelemetry.api.trace.Span
|
||||
import io.opentelemetry.api.trace.SpanId
|
||||
import io.opentelemetry.api.trace.SpanKind
|
||||
import io.opentelemetry.api.trace.StatusCode
|
||||
import io.opentelemetry.context.Context
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders
|
||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
||||
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
|
||||
import io.opentelemetry.instrumentation.testing.GlobalTraceUtil
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
|
||||
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions
|
||||
import io.opentelemetry.sdk.trace.data.SpanData
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpData
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpMethod
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpRequest
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpRequestBuilder
|
||||
import io.opentelemetry.testing.internal.armeria.common.MediaType
|
||||
import io.opentelemetry.testing.internal.armeria.common.QueryParams
|
||||
import io.opentelemetry.testing.internal.armeria.common.RequestHeaders
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Unroll
|
||||
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
||||
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
|
||||
import static java.util.Collections.singletonList
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue
|
||||
|
||||
@Unroll
|
||||
abstract class HttpServerTest<SERVER> extends InstrumentationSpecification implements HttpServerTestTrait<SERVER> {
|
||||
|
||||
static final String TEST_REQUEST_HEADER = "X-Test-Request"
|
||||
static final String TEST_RESPONSE_HEADER = "X-Test-Response"
|
||||
|
||||
def setupSpec() {
|
||||
setupServer()
|
||||
junitTest.setupOptions()
|
||||
junitTest.setTesting(testRunner(), client, port, address)
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
|
@ -60,9 +48,7 @@ abstract class HttpServerTest<SERVER> extends InstrumentationSpecification imple
|
|||
}
|
||||
|
||||
static CapturedHttpHeaders capturedHttpHeadersForTesting() {
|
||||
CapturedHttpHeaders.create(
|
||||
singletonList(TEST_REQUEST_HEADER),
|
||||
singletonList(TEST_RESPONSE_HEADER))
|
||||
return AbstractHttpServerTest.capturedHttpHeadersForTesting()
|
||||
}
|
||||
|
||||
String expectedServerSpanName(ServerEndpoint endpoint, String method) {
|
||||
|
@ -171,101 +157,9 @@ abstract class HttpServerTest<SERVER> extends InstrumentationSpecification imple
|
|||
] as Set
|
||||
}
|
||||
|
||||
enum ServerEndpoint {
|
||||
SUCCESS("success", 200, "success"),
|
||||
REDIRECT("redirect", 302, "/redirected"),
|
||||
ERROR("error-status", 500, "controller error"), // "error" is a special path for some frameworks
|
||||
EXCEPTION("exception", 500, "controller exception"),
|
||||
NOT_FOUND("notFound", 404, "not found"),
|
||||
CAPTURE_HEADERS("captureHeaders", 200, "headers captured"),
|
||||
CAPTURE_PARAMETERS("captureParameters", 200, "parameters captured"),
|
||||
|
||||
// TODO: add tests for the following cases:
|
||||
QUERY_PARAM("query?some=query", 200, "some=query"),
|
||||
// OkHttp never sends the fragment in the request, so these cases don't work.
|
||||
// FRAGMENT_PARAM("fragment#some-fragment", 200, "some-fragment"),
|
||||
// QUERY_FRAGMENT_PARAM("query/fragment?some=query#some-fragment", 200, "some=query#some-fragment"),
|
||||
PATH_PARAM("path/123/param", 200, "123"),
|
||||
AUTH_REQUIRED("authRequired", 200, null),
|
||||
LOGIN("login", 302, null),
|
||||
AUTH_ERROR("basicsecured/endpoint", 401, null),
|
||||
INDEXED_CHILD("child", 200, ""),
|
||||
|
||||
public static final String ID_ATTRIBUTE_NAME = "test.request.id"
|
||||
public static final String ID_PARAMETER_NAME = "id"
|
||||
|
||||
private final URI uriObj
|
||||
private final String path
|
||||
final String query
|
||||
final String fragment
|
||||
final int status
|
||||
final String body
|
||||
|
||||
ServerEndpoint(String uri, int status, String body) {
|
||||
this.uriObj = URI.create(uri)
|
||||
this.path = uriObj.path
|
||||
this.query = uriObj.query
|
||||
this.fragment = uriObj.fragment
|
||||
this.status = status
|
||||
this.body = body
|
||||
}
|
||||
|
||||
String getPath() {
|
||||
return "/$path"
|
||||
}
|
||||
|
||||
String rawPath() {
|
||||
return path
|
||||
}
|
||||
|
||||
URI resolvePath(URI address) {
|
||||
return address.resolve(path)
|
||||
}
|
||||
|
||||
URI resolve(URI address) {
|
||||
return address.resolve(uriObj)
|
||||
}
|
||||
|
||||
URI resolveWithoutFragment(URI address) {
|
||||
def uri = resolve(address)
|
||||
return new URI(uri.scheme, null, uri.host, uri.port, uri.path, uri.query, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates custom test attributes for the {@link HttpServerTest#controller} span (which must
|
||||
* be the current span when this is called) based on URL parameters. Required for
|
||||
* {@link #INDEXED_CHILD}.
|
||||
*/
|
||||
void collectSpanAttributes(UrlParameterProvider parameterProvider) {
|
||||
if (this == INDEXED_CHILD) {
|
||||
String value = parameterProvider.getParameter(ID_PARAMETER_NAME)
|
||||
|
||||
if (value != null) {
|
||||
Span.current().setAttribute(ID_ATTRIBUTE_NAME, value as long)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, ServerEndpoint> PATH_MAP = values().collectEntries { [it.path, it] }
|
||||
|
||||
static ServerEndpoint forPath(String path) {
|
||||
return PATH_MAP.get(path)
|
||||
}
|
||||
|
||||
// Static keyword required for Scala interop
|
||||
static interface UrlParameterProvider {
|
||||
String getParameter(String name)
|
||||
}
|
||||
}
|
||||
|
||||
String resolveAddress(ServerEndpoint uri) {
|
||||
def url = uri.resolvePath(address).toString()
|
||||
// Force HTTP/1 via h1c so upgrade requests don't show up as traces
|
||||
url = url.replace("http://", "h1c://")
|
||||
if (uri.query != null) {
|
||||
url += "?${uri.query}"
|
||||
}
|
||||
return url
|
||||
final String resolveAddress(ServerEndpoint endpoint) {
|
||||
return junitTest.resolveAddress(endpoint)
|
||||
}
|
||||
|
||||
AggregatedHttpRequest request(ServerEndpoint uri, String method) {
|
||||
|
@ -282,257 +176,141 @@ abstract class HttpServerTest<SERVER> extends InstrumentationSpecification imple
|
|||
}
|
||||
}
|
||||
|
||||
@Shared
|
||||
def junitTest = new AbstractHttpServerTest<Void>() {
|
||||
@Override
|
||||
protected Void setupServer() {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopServer(Void o) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpServerTestOptions options) {
|
||||
options.expectedServerSpanNameMapper = { endpoint, method ->
|
||||
HttpServerTest.this.expectedServerSpanName(endpoint, method)
|
||||
}
|
||||
options.expectedHttpRoute = { endpoint ->
|
||||
HttpServerTest.this.expectedHttpRoute(endpoint)
|
||||
}
|
||||
options.contextPath = getContextPath()
|
||||
options.httpAttributes = { endpoint ->
|
||||
HttpServerTest.this.httpAttributes(endpoint)
|
||||
}
|
||||
options.expectedExceptionClass = expectedExceptionClass()
|
||||
options.hasExceptionOnServerSpan = { endpoint ->
|
||||
HttpServerTest.this.hasExceptionOnServerSpan(endpoint)
|
||||
}
|
||||
|
||||
options.testRedirect = testRedirect()
|
||||
options.testError = testError()
|
||||
options.testErrorBody = testErrorBody()
|
||||
options.testException = testException()
|
||||
options.testNotFound = testNotFound()
|
||||
options.testPathParam = testPathParam()
|
||||
options.testCaptureHttpHeaders = testCapturedHttpHeaders()
|
||||
options.testCaptureRequestParameters = testCapturedRequestParameters()
|
||||
}
|
||||
|
||||
// Override trace assertion method. We can call java assertions from groovy but not the other
|
||||
// way around. As we have a bunch of groovy tests that do custom assertions we need to duplicate
|
||||
// the main trace assertion method to groovy to be able to call these assertions.
|
||||
@Override
|
||||
void assertTheTraces(
|
||||
int size,
|
||||
String traceId,
|
||||
String parentId,
|
||||
String method,
|
||||
ServerEndpoint endpoint,
|
||||
String errorMessage,
|
||||
AggregatedHttpResponse response) {
|
||||
HttpServerTest.this.assertTheTraces(size, traceId, parentId, method, endpoint, errorMessage, response)
|
||||
}
|
||||
|
||||
@Override
|
||||
void assertHighConcurrency(int count) {
|
||||
HttpServerTest.this.assertHighConcurrency(count)
|
||||
}
|
||||
}
|
||||
|
||||
def "test success with #count requests"() {
|
||||
setup:
|
||||
def request = request(SUCCESS, method)
|
||||
List<AggregatedHttpResponse> responses = (1..count).collect {
|
||||
return client.execute(request).aggregate().join()
|
||||
}
|
||||
|
||||
expect:
|
||||
responses.each { response ->
|
||||
assert response.status().code() == SUCCESS.status
|
||||
assert response.contentUtf8() == SUCCESS.body
|
||||
}
|
||||
|
||||
and:
|
||||
assertTheTraces(count, null, null, method, SUCCESS, null, responses[0])
|
||||
junitTest.successfulGetRequest(count)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
count << [1, 4, 50] // make multiple requests.
|
||||
}
|
||||
|
||||
def "test success with parent"() {
|
||||
setup:
|
||||
def traceId = "00000000000000000000000000000123"
|
||||
def parentId = "0000000000000456"
|
||||
def request = AggregatedHttpRequest.of(
|
||||
// intentionally sending mixed-case "tracePARENT" to make sure that TextMapGetters are not case-sensitive
|
||||
request(SUCCESS, method).headers().toBuilder()
|
||||
.set("tracePARENT", "00-" + traceId.toString() + "-" + parentId.toString() + "-01")
|
||||
.build())
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == SUCCESS.status
|
||||
response.contentUtf8() == SUCCESS.body
|
||||
|
||||
and:
|
||||
assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.successfulGetRequestWithParent()
|
||||
}
|
||||
|
||||
// make sure that TextMapGetters are not case-sensitive
|
||||
def "test success with uppercase TRACEPARENT header"() {
|
||||
setup:
|
||||
def traceId = "00000000000000000000000000000123"
|
||||
def parentId = "0000000000000456"
|
||||
def request = AggregatedHttpRequest.of(
|
||||
request(SUCCESS, method).headers().toBuilder()
|
||||
.set("TRACEPARENT", "00-" + traceId.toString() + "-" + parentId.toString() + "-01")
|
||||
.build())
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == SUCCESS.status
|
||||
response.contentUtf8() == SUCCESS.body
|
||||
|
||||
and:
|
||||
assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.tracingHeaderIsCaseInsensitive()
|
||||
}
|
||||
|
||||
def "test tag query string for #endpoint"() {
|
||||
setup:
|
||||
def request = request(endpoint, method)
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == endpoint.status
|
||||
response.contentUtf8() == endpoint.body
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, method, endpoint, null, response)
|
||||
junitTest.requestWithQueryString(endpoint)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
endpoint << [SUCCESS, QUERY_PARAM]
|
||||
}
|
||||
|
||||
def "test redirect"() {
|
||||
setup:
|
||||
assumeTrue(testRedirect())
|
||||
def request = request(REDIRECT, method)
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == REDIRECT.status
|
||||
response.headers().get("location") == REDIRECT.body ||
|
||||
new URI(response.headers().get("location")).normalize().toString() == "${address.resolve(REDIRECT.body)}"
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, method, REDIRECT, null, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.requestWithRedirect()
|
||||
}
|
||||
|
||||
def "test error"() {
|
||||
setup:
|
||||
assumeTrue(testError())
|
||||
def request = request(ERROR, method)
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == ERROR.status
|
||||
if (testErrorBody()) {
|
||||
response.contentUtf8() == ERROR.body
|
||||
}
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, method, ERROR, null, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.requestWithError()
|
||||
}
|
||||
|
||||
def "test exception"() {
|
||||
setup:
|
||||
assumeTrue(testException())
|
||||
def request = request(EXCEPTION, method)
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == EXCEPTION.status
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, method, EXCEPTION, EXCEPTION.body, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.requestWithException()
|
||||
}
|
||||
|
||||
def "test notFound"() {
|
||||
setup:
|
||||
def "test not found"() {
|
||||
assumeTrue(testNotFound())
|
||||
def request = request(NOT_FOUND, method)
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == NOT_FOUND.status
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, method, NOT_FOUND, null, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.requestForNotFound()
|
||||
}
|
||||
|
||||
def "test path param"() {
|
||||
setup:
|
||||
assumeTrue(testPathParam())
|
||||
def request = request(PATH_PARAM, method)
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == PATH_PARAM.status
|
||||
response.contentUtf8() == PATH_PARAM.body
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, method, PATH_PARAM, null, response)
|
||||
|
||||
where:
|
||||
method = "GET"
|
||||
junitTest.requestWithPathParameter()
|
||||
}
|
||||
|
||||
def "test captured HTTP headers"() {
|
||||
setup:
|
||||
assumeTrue(testCapturedHttpHeaders())
|
||||
|
||||
def request = AggregatedHttpRequest.of(request(CAPTURE_HEADERS, "GET").headers()
|
||||
.toBuilder()
|
||||
.add(TEST_REQUEST_HEADER, "test")
|
||||
.build())
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == CAPTURE_HEADERS.status
|
||||
response.contentUtf8() == CAPTURE_HEADERS.body
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, "GET", CAPTURE_HEADERS, null, response)
|
||||
junitTest.captureHttpHeaders()
|
||||
}
|
||||
|
||||
def "test captured request parameters"() {
|
||||
setup:
|
||||
assumeTrue(testCapturedRequestParameters())
|
||||
|
||||
QueryParams formBody = QueryParams.builder()
|
||||
.add("test-parameter", "test value õäöü")
|
||||
.build()
|
||||
def request = AggregatedHttpRequest.of(
|
||||
RequestHeaders.builder(HttpMethod.POST, resolveAddress(CAPTURE_PARAMETERS))
|
||||
.contentType(MediaType.FORM_DATA)
|
||||
.build(),
|
||||
HttpData.ofUtf8(formBody.toQueryString()))
|
||||
def response = client.execute(request).aggregate().join()
|
||||
|
||||
expect:
|
||||
response.status().code() == CAPTURE_PARAMETERS.status
|
||||
response.contentUtf8() == CAPTURE_PARAMETERS.body
|
||||
|
||||
and:
|
||||
assertTheTraces(1, null, null, "POST", CAPTURE_PARAMETERS, null, response)
|
||||
junitTest.captureRequestParameters()
|
||||
}
|
||||
|
||||
/*
|
||||
This test fires a bunch of parallel request to the fixed backend endpoint.
|
||||
That endpoint is supposed to create a new child span in the context of the SERVER span.
|
||||
That child span is expected to have an attribute called "test.request.id".
|
||||
The value of that attribute should be the value of request's parameter called "id".
|
||||
|
||||
This test then asserts that there is the correct number of traces (one per request executed)
|
||||
and that each trace has exactly three spans and both first and the last spans have "test.request.id"
|
||||
attribute with equal value. Server span is not going to have that attribute because it is not
|
||||
under the control of this test.
|
||||
|
||||
This way we verify that child span created by the server actually corresponds to the client request.
|
||||
*/
|
||||
|
||||
def "high concurrency test"() {
|
||||
setup:
|
||||
int count = 100
|
||||
expect:
|
||||
junitTest.highConcurrency()
|
||||
}
|
||||
|
||||
void assertHighConcurrency(int count) {
|
||||
def endpoint = INDEXED_CHILD
|
||||
|
||||
def latch = new CountDownLatch(count)
|
||||
|
||||
def propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator()
|
||||
def setter = { HttpRequestBuilder carrier, String name, String value ->
|
||||
carrier.header(name, value)
|
||||
}
|
||||
|
||||
when:
|
||||
count.times { index ->
|
||||
HttpRequestBuilder request = HttpRequest.builder()
|
||||
// Force HTTP/1 via h1c so upgrade requests don't show up as traces
|
||||
.get(endpoint.resolvePath(address).toString().replace("http://", "h1c://"))
|
||||
.queryParam(ServerEndpoint.ID_PARAMETER_NAME, "$index")
|
||||
runWithSpan("client " + index) {
|
||||
Span.current().setAttribute(ServerEndpoint.ID_ATTRIBUTE_NAME, index)
|
||||
propagator.inject(Context.current(), request, setter)
|
||||
client.execute(request.build()).aggregate().thenRun {
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
}
|
||||
latch.await()
|
||||
|
||||
then:
|
||||
assertTraces(count) {
|
||||
(0..count - 1).each {
|
||||
trace(it, hasHandlerSpan(endpoint) ? 4 : 3) {
|
||||
|
@ -548,7 +326,7 @@ abstract class HttpServerTest<SERVER> extends InstrumentationSpecification imple
|
|||
"${ServerEndpoint.ID_ATTRIBUTE_NAME}" requestId
|
||||
}
|
||||
}
|
||||
indexedServerSpan(it, span(0), requestId)
|
||||
indexedServerSpan(it, 1, span(0), requestId)
|
||||
|
||||
def controllerSpanIndex = 2
|
||||
|
||||
|
@ -619,13 +397,13 @@ abstract class HttpServerTest<SERVER> extends InstrumentationSpecification imple
|
|||
}
|
||||
|
||||
void controllerSpan(TraceAssert trace, int index, Object parent, String errorMessage = null, Class exceptionClass = Exception) {
|
||||
trace.span(index) {
|
||||
name "controller"
|
||||
if (errorMessage) {
|
||||
status StatusCode.ERROR
|
||||
errorEvent(exceptionClass, errorMessage)
|
||||
}
|
||||
childOf((SpanData) parent)
|
||||
trace.assertedIndexes.add(index)
|
||||
def spanData = trace.span(index)
|
||||
def assertion = junitTest.assertControllerSpan(OpenTelemetryAssertions.assertThat(spanData), errorMessage, exceptionClass)
|
||||
if (parent == null) {
|
||||
assertion.hasParentSpanId(SpanId.invalid)
|
||||
} else {
|
||||
assertion.hasParentSpanId(((SpanData) parent).spanId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -665,145 +443,37 @@ abstract class HttpServerTest<SERVER> extends InstrumentationSpecification imple
|
|||
}
|
||||
}
|
||||
|
||||
// parent span must be cast otherwise it breaks debugging classloading (junit loads it early)
|
||||
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
|
||||
def httpAttributes = this.httpAttributes(endpoint)
|
||||
trace.span(index) {
|
||||
name expectedServerSpanName(endpoint, method)
|
||||
kind SpanKind.SERVER // can't use static import because of SERVER type parameter
|
||||
if (endpoint.status >= 500) {
|
||||
status StatusCode.ERROR
|
||||
}
|
||||
if (parentID != null) {
|
||||
traceId traceID
|
||||
parentSpanId parentID
|
||||
} else {
|
||||
hasNoParent()
|
||||
}
|
||||
if (endpoint == EXCEPTION && hasExceptionOnServerSpan(endpoint)) {
|
||||
event(0) {
|
||||
eventName(SemanticAttributes.EXCEPTION_EVENT_NAME)
|
||||
attributes {
|
||||
"$SemanticAttributes.EXCEPTION_TYPE" { it == null || it == expectedExceptionClass().name }
|
||||
"$SemanticAttributes.EXCEPTION_MESSAGE" { it == null || it == endpoint.body }
|
||||
"$SemanticAttributes.EXCEPTION_STACKTRACE" { it == null || it instanceof String }
|
||||
}
|
||||
}
|
||||
}
|
||||
attributes {
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_TRANSPORT)) {
|
||||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_PEER_PORT)) {
|
||||
"$SemanticAttributes.NET_PEER_PORT" { (it instanceof Long && it.intValue() != port) }
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)) {
|
||||
"$SemanticAttributes.NET_PEER_IP" { it == peerIp(endpoint) }
|
||||
} else {
|
||||
// Optional
|
||||
"$SemanticAttributes.NET_PEER_IP" { it == null || it == peerIp(endpoint) }
|
||||
}
|
||||
|
||||
"$SemanticAttributes.HTTP_CLIENT_IP" { it == null || it == TEST_CLIENT_IP }
|
||||
"$SemanticAttributes.HTTP_METHOD" method
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" endpoint.status
|
||||
"$SemanticAttributes.HTTP_FLAVOR" { it == "1.1" || it == "2.0" }
|
||||
"$SemanticAttributes.HTTP_USER_AGENT" TEST_USER_AGENT
|
||||
|
||||
"$SemanticAttributes.HTTP_SCHEME" "http"
|
||||
"$SemanticAttributes.HTTP_HOST" { it == "localhost" || it == "localhost:${port}" }
|
||||
"$SemanticAttributes.HTTP_TARGET" endpoint.resolvePath(address).getPath() + "${endpoint == QUERY_PARAM ? "?${endpoint.body}" : ""}"
|
||||
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) {
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long
|
||||
} else {
|
||||
// Optional
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) {
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
} else {
|
||||
// Optional
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) {
|
||||
"$SemanticAttributes.HTTP_SERVER_NAME" String
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) {
|
||||
"$SemanticAttributes.HTTP_ROUTE" { it == expectedHttpRoute(endpoint) }
|
||||
}
|
||||
|
||||
if (endpoint == CAPTURE_HEADERS) {
|
||||
"http.request.header.x_test_request" { it == ["test"] }
|
||||
"http.response.header.x_test_response" { it == ["test"] }
|
||||
}
|
||||
if (endpoint == CAPTURE_PARAMETERS) {
|
||||
"servlet.request.parameter.test_parameter" { it == ["test value õäöü"] }
|
||||
}
|
||||
}
|
||||
trace.assertedIndexes.add(index)
|
||||
def spanData = trace.span(index)
|
||||
def assertion = junitTest.assertServerSpan(OpenTelemetryAssertions.assertThat(spanData), method, endpoint)
|
||||
if (parentID == null) {
|
||||
assertion.hasParentSpanId(SpanId.invalid)
|
||||
} else {
|
||||
assertion.hasParentSpanId(parentID)
|
||||
assertion.hasTraceId(traceID)
|
||||
}
|
||||
}
|
||||
|
||||
void indexedServerSpan(TraceAssert trace, Object parent, int requestId) {
|
||||
ServerEndpoint endpoint = INDEXED_CHILD
|
||||
def httpAttributes = this.httpAttributes(endpoint)
|
||||
trace.span(1) {
|
||||
name expectedServerSpanName(endpoint, "GET")
|
||||
kind SpanKind.SERVER // can't use static import because of SERVER type parameter
|
||||
childOf((SpanData) parent)
|
||||
attributes {
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_TRANSPORT)) {
|
||||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_PEER_PORT)) {
|
||||
"$SemanticAttributes.NET_PEER_PORT" { (it instanceof Long && it.intValue() != port) }
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)) {
|
||||
"$SemanticAttributes.NET_PEER_IP" { it == peerIp(endpoint) }
|
||||
} else {
|
||||
// Optional
|
||||
"$SemanticAttributes.NET_PEER_IP" { it == null || it == peerIp(endpoint) }
|
||||
}
|
||||
|
||||
"$SemanticAttributes.HTTP_CLIENT_IP" { it == null || it == TEST_CLIENT_IP }
|
||||
"$SemanticAttributes.HTTP_METHOD" "GET"
|
||||
"$SemanticAttributes.HTTP_STATUS_CODE" 200
|
||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||
"$SemanticAttributes.HTTP_USER_AGENT" TEST_USER_AGENT
|
||||
|
||||
"$SemanticAttributes.HTTP_HOST" { it == "localhost" || it == "localhost:${port}" }
|
||||
"$SemanticAttributes.HTTP_SCHEME" "http"
|
||||
"$SemanticAttributes.HTTP_TARGET" endpoint.resolvePath(address).getPath() + "?id=$requestId"
|
||||
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) {
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long
|
||||
} else {
|
||||
// Optional
|
||||
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) {
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long
|
||||
} else {
|
||||
// Optional
|
||||
"$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long }
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) {
|
||||
"$SemanticAttributes.HTTP_SERVER_NAME" String
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) {
|
||||
"$SemanticAttributes.HTTP_ROUTE" { it == expectedHttpRoute(endpoint) }
|
||||
}
|
||||
}
|
||||
void indexedServerSpan(TraceAssert trace, int index, Object parent, int requestId) {
|
||||
trace.assertedIndexes.add(index)
|
||||
def spanData = trace.span(index)
|
||||
def assertion = junitTest.assertIndexedServerSpan(OpenTelemetryAssertions.assertThat(spanData), requestId)
|
||||
if (parent == null) {
|
||||
assertion.hasParentSpanId(SpanId.invalid)
|
||||
} else {
|
||||
assertion.hasParentSpanId(((SpanData) parent).spanId)
|
||||
}
|
||||
}
|
||||
|
||||
void indexedControllerSpan(TraceAssert trace, int index, Object parent, int requestId) {
|
||||
trace.span(index) {
|
||||
name "controller"
|
||||
childOf((SpanData) parent)
|
||||
attributes {
|
||||
"${ServerEndpoint.ID_ATTRIBUTE_NAME}" requestId
|
||||
}
|
||||
trace.assertedIndexes.add(index)
|
||||
def spanData = trace.span(index)
|
||||
def assertion = junitTest.assertIndexedControllerSpan(OpenTelemetryAssertions.assertThat(spanData), requestId)
|
||||
if (parent == null) {
|
||||
assertion.hasParentSpanId(SpanId.invalid)
|
||||
} else {
|
||||
assertion.hasParentSpanId(((SpanData) parent).spanId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import ch.qos.logback.classic.Level
|
|||
import io.opentelemetry.instrumentation.test.RetryOnAddressAlreadyInUseTrait
|
||||
import io.opentelemetry.instrumentation.test.utils.LoggerUtils
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
|
||||
import io.opentelemetry.testing.internal.armeria.client.ClientFactory
|
||||
import io.opentelemetry.testing.internal.armeria.client.WebClient
|
||||
import io.opentelemetry.testing.internal.armeria.client.logging.LoggingClient
|
||||
|
@ -26,8 +27,8 @@ trait HttpServerTestTrait<SERVER> implements RetryOnAddressAlreadyInUseTrait {
|
|||
static {
|
||||
LoggerUtils.setLevel(SERVER_LOGGER, Level.DEBUG)
|
||||
}
|
||||
static final String TEST_CLIENT_IP = "1.1.1.1"
|
||||
static final String TEST_USER_AGENT = "test-user-agent"
|
||||
static final String TEST_CLIENT_IP = AbstractHttpServerTest.TEST_CLIENT_IP
|
||||
static final String TEST_USER_AGENT = AbstractHttpServerTest.TEST_USER_AGENT
|
||||
|
||||
// not using SERVER as type because it triggers a bug in groovy and java joint compilation
|
||||
static Object server
|
||||
|
|
|
@ -199,9 +199,7 @@ public abstract class AbstractHttpClientTest<REQUEST> {
|
|||
void verifyExtension() {
|
||||
if (testing == null) {
|
||||
throw new AssertionError(
|
||||
"Subclasses of AbstractHttpClientTest must register either "
|
||||
+ "HttpClientLibraryInstrumentationExtension or "
|
||||
+ "HttpClientAgentInstrumentationExtension");
|
||||
"Subclasses of AbstractHttpClientTest must register HttpClientInstrumentationExtension");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,695 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.testing.junit.http;
|
||||
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||
import io.opentelemetry.context.propagation.TextMapSetter;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||
import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner;
|
||||
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
|
||||
import io.opentelemetry.sdk.testing.assertj.TraceAssert;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.StatusData;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import io.opentelemetry.testing.internal.armeria.client.WebClient;
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest;
|
||||
import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse;
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpData;
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpMethod;
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpRequest;
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpRequestBuilder;
|
||||
import io.opentelemetry.testing.internal.armeria.common.MediaType;
|
||||
import io.opentelemetry.testing.internal.armeria.common.QueryParams;
|
||||
import io.opentelemetry.testing.internal.armeria.common.RequestHeaders;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Consumer;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public abstract class AbstractHttpServerTest<SERVER> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractHttpServerTest.class);
|
||||
|
||||
private static final String TEST_REQUEST_HEADER = "X-Test-Request";
|
||||
private static final String TEST_RESPONSE_HEADER = "X-Test-Response";
|
||||
|
||||
public static final String TEST_CLIENT_IP = "1.1.1.1";
|
||||
public static final String TEST_USER_AGENT = "test-user-agent";
|
||||
|
||||
private final HttpServerTestOptions options = new HttpServerTestOptions();
|
||||
private InstrumentationTestRunner testing;
|
||||
private SERVER server;
|
||||
public WebClient client;
|
||||
public int port;
|
||||
public URI address;
|
||||
|
||||
protected abstract SERVER setupServer();
|
||||
|
||||
protected abstract void stopServer(SERVER server);
|
||||
|
||||
@BeforeAll
|
||||
void setupOptions() {
|
||||
options.expectedServerSpanNameMapper = this::expectedServerSpanName;
|
||||
options.expectedHttpRoute = this::expectedHttpRoute;
|
||||
|
||||
configure(options);
|
||||
|
||||
if (address == null) {
|
||||
address = buildAddress();
|
||||
}
|
||||
|
||||
server = setupServer();
|
||||
if (server != null) {
|
||||
logger.info(
|
||||
getClass().getName()
|
||||
+ " http server started at: http://localhost:"
|
||||
+ port
|
||||
+ options.contextPath);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void cleanup() {
|
||||
if (server == null) {
|
||||
logger.info(getClass().getName() + " can't stop null server");
|
||||
return;
|
||||
}
|
||||
stopServer(server);
|
||||
server = null;
|
||||
logger.info(getClass().getName() + " http server stopped at: http://localhost:" + port + "/");
|
||||
}
|
||||
|
||||
protected URI buildAddress() {
|
||||
try {
|
||||
return new URI("http://localhost:" + port + options.contextPath + "/");
|
||||
} catch (URISyntaxException exception) {
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected void configure(HttpServerTestOptions options) {}
|
||||
|
||||
@BeforeEach
|
||||
void verifyExtension() {
|
||||
if (testing == null) {
|
||||
throw new AssertionError(
|
||||
"Subclasses of AbstractHttpServerTest must register HttpServerInstrumentationExtension");
|
||||
}
|
||||
}
|
||||
|
||||
public static CapturedHttpHeaders capturedHttpHeadersForTesting() {
|
||||
return CapturedHttpHeaders.create(
|
||||
singletonList(TEST_REQUEST_HEADER), singletonList(TEST_RESPONSE_HEADER));
|
||||
}
|
||||
|
||||
String resolveAddress(ServerEndpoint uri) {
|
||||
String url = uri.resolvePath(address).toString();
|
||||
// Force HTTP/1 via h1c so upgrade requests don't show up as traces
|
||||
url = url.replace("http://", "h1c://");
|
||||
if (uri.getQuery() != null) {
|
||||
url += "?" + uri.getQuery();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private AggregatedHttpRequest request(ServerEndpoint uri, String method) {
|
||||
return AggregatedHttpRequest.of(HttpMethod.valueOf(method), resolveAddress(uri));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {1, 4, 50})
|
||||
void successfulGetRequest(int count) {
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(SUCCESS, method);
|
||||
List<AggregatedHttpResponse> responses = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
responses.add(client.execute(request).aggregate().join());
|
||||
}
|
||||
|
||||
for (AggregatedHttpResponse response : responses) {
|
||||
assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody());
|
||||
}
|
||||
|
||||
assertTheTraces(count, null, null, method, SUCCESS, null, responses.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void successfulGetRequestWithParent() {
|
||||
String method = "GET";
|
||||
String traceId = "00000000000000000000000000000123";
|
||||
String parentId = "0000000000000456";
|
||||
AggregatedHttpRequest request =
|
||||
AggregatedHttpRequest.of(
|
||||
// intentionally sending mixed-case "tracePARENT" to make sure that TextMapGetters are
|
||||
// not case-sensitive
|
||||
request(SUCCESS, method).headers().toBuilder()
|
||||
.set("tracePARENT", "00-" + traceId + "-" + parentId + "-01")
|
||||
.build());
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody());
|
||||
|
||||
assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tracingHeaderIsCaseInsensitive() {
|
||||
String method = "GET";
|
||||
String traceId = "00000000000000000000000000000123";
|
||||
String parentId = "0000000000000456";
|
||||
AggregatedHttpRequest request =
|
||||
AggregatedHttpRequest.of(
|
||||
request(SUCCESS, method).headers().toBuilder()
|
||||
.set("TRACEPARENT", "00-" + traceId + "-" + parentId + "-01")
|
||||
.build());
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody());
|
||||
|
||||
assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(
|
||||
value = ServerEndpoint.class,
|
||||
names = {"SUCCESS", "QUERY_PARAM"})
|
||||
void requestWithQueryString(ServerEndpoint endpoint) {
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(endpoint, method);
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(endpoint.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(endpoint.getBody());
|
||||
|
||||
assertTheTraces(1, null, null, method, endpoint, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestWithRedirect() {
|
||||
assumeTrue(options.testRedirect);
|
||||
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(REDIRECT, method);
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(REDIRECT.getStatus());
|
||||
assertThat(response.headers().get("location"))
|
||||
.satisfiesAnyOf(
|
||||
location -> assertThat(location).isEqualTo(REDIRECT.getBody()),
|
||||
location ->
|
||||
assertThat(new URI(location).normalize().toString())
|
||||
.isEqualTo(address.resolve(REDIRECT.getBody()).toString()));
|
||||
|
||||
assertTheTraces(1, null, null, method, REDIRECT, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestWithError() {
|
||||
assumeTrue(options.testError);
|
||||
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(ERROR, method);
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(ERROR.getStatus());
|
||||
if (options.testErrorBody) {
|
||||
assertThat(response.contentUtf8()).isEqualTo(ERROR.getBody());
|
||||
}
|
||||
|
||||
assertTheTraces(1, null, null, method, ERROR, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestWithException() {
|
||||
assumeTrue(options.testException);
|
||||
|
||||
// async servlet tests may produce uncaught exceptions
|
||||
// awaitility rethrows uncaught exceptions while it is waiting on a condition
|
||||
Awaitility.doNotCatchUncaughtExceptionsByDefault();
|
||||
try {
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(EXCEPTION, method);
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(EXCEPTION.getStatus());
|
||||
|
||||
assertTheTraces(1, null, null, method, EXCEPTION, EXCEPTION.body, response);
|
||||
} finally {
|
||||
Awaitility.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestForNotFound() {
|
||||
assumeTrue(options.testNotFound);
|
||||
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(NOT_FOUND, method);
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(NOT_FOUND.getStatus());
|
||||
|
||||
assertTheTraces(1, null, null, method, NOT_FOUND, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestWithPathParameter() {
|
||||
assumeTrue(options.testPathParam);
|
||||
|
||||
String method = "GET";
|
||||
AggregatedHttpRequest request = request(PATH_PARAM, method);
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(PATH_PARAM.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(PATH_PARAM.getBody());
|
||||
|
||||
assertTheTraces(1, null, null, method, PATH_PARAM, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void captureHttpHeaders() {
|
||||
assumeTrue(options.testCaptureHttpHeaders);
|
||||
|
||||
AggregatedHttpRequest request =
|
||||
AggregatedHttpRequest.of(
|
||||
request(CAPTURE_HEADERS, "GET").headers().toBuilder()
|
||||
.add(TEST_REQUEST_HEADER, "test")
|
||||
.build());
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(CAPTURE_HEADERS.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(CAPTURE_HEADERS.getBody());
|
||||
|
||||
assertTheTraces(1, null, null, "GET", CAPTURE_HEADERS, null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void captureRequestParameters() {
|
||||
assumeTrue(options.testCaptureRequestParameters);
|
||||
|
||||
QueryParams formBody = QueryParams.builder().add("test-parameter", "test value õäöü").build();
|
||||
AggregatedHttpRequest request =
|
||||
AggregatedHttpRequest.of(
|
||||
RequestHeaders.builder(HttpMethod.POST, resolveAddress(CAPTURE_PARAMETERS))
|
||||
.contentType(MediaType.FORM_DATA)
|
||||
.build(),
|
||||
HttpData.ofUtf8(formBody.toQueryString()));
|
||||
AggregatedHttpResponse response = client.execute(request).aggregate().join();
|
||||
|
||||
assertThat(response.status().code()).isEqualTo(CAPTURE_PARAMETERS.getStatus());
|
||||
assertThat(response.contentUtf8()).isEqualTo(CAPTURE_PARAMETERS.getBody());
|
||||
|
||||
assertTheTraces(1, null, null, "POST", CAPTURE_PARAMETERS, null, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test fires a bunch of parallel request to the fixed backend endpoint. That endpoint is
|
||||
* supposed to create a new child span in the context of the SERVER span. That child span is
|
||||
* expected to have an attribute called "test.request.id". The value of that attribute should be
|
||||
* the value of request's parameter called "id".
|
||||
*
|
||||
* <p>This test then asserts that there is the correct number of traces (one per request executed)
|
||||
* and that each trace has exactly three spans and both first and the last spans have
|
||||
* "test.request.id" attribute with equal value. Server span is not going to have that attribute
|
||||
* because it is not under the control of this test.
|
||||
*
|
||||
* <p>This way we verify that child span created by the server actually corresponds to the client
|
||||
* request.
|
||||
*/
|
||||
@Test
|
||||
void highConcurrency() throws InterruptedException {
|
||||
int count = 100;
|
||||
ServerEndpoint endpoint = INDEXED_CHILD;
|
||||
CountDownLatch latch = new CountDownLatch(count);
|
||||
|
||||
TextMapPropagator propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator();
|
||||
TextMapSetter<HttpRequestBuilder> setter = HttpRequestBuilder::header;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int index = i;
|
||||
HttpRequestBuilder request =
|
||||
HttpRequest.builder()
|
||||
// Force HTTP/1 via h1c so upgrade requests don't show up as traces
|
||||
.get(endpoint.resolvePath(address).toString().replace("http://", "h1c://"))
|
||||
.queryParam(ServerEndpoint.ID_PARAMETER_NAME, index);
|
||||
|
||||
testing.runWithSpan(
|
||||
"client " + index,
|
||||
() -> {
|
||||
Span.current().setAttribute(ServerEndpoint.ID_ATTRIBUTE_NAME, index);
|
||||
propagator.inject(Context.current(), request, setter);
|
||||
client.execute(request.build()).aggregate().thenRun(latch::countDown);
|
||||
});
|
||||
}
|
||||
latch.await();
|
||||
|
||||
assertHighConcurrency(count);
|
||||
}
|
||||
|
||||
protected void assertHighConcurrency(int count) {
|
||||
ServerEndpoint endpoint = INDEXED_CHILD;
|
||||
List<Consumer<TraceAssert>> assertions = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
assertions.add(
|
||||
trace -> {
|
||||
SpanData rootSpan = trace.getSpan(0);
|
||||
// Traces can be in arbitrary order, let us find out the request id of the current one
|
||||
int requestId = Integer.parseInt(rootSpan.getName().substring("client ".length()));
|
||||
|
||||
List<Consumer<SpanDataAssert>> spanAssertions = new ArrayList<>();
|
||||
spanAssertions.add(
|
||||
span ->
|
||||
span.hasName(rootSpan.getName())
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
.hasNoParent()
|
||||
.hasAttributesSatisfying(
|
||||
attrs ->
|
||||
assertThat(attrs)
|
||||
.containsEntry(ServerEndpoint.ID_ATTRIBUTE_NAME, requestId)));
|
||||
spanAssertions.add(
|
||||
span -> assertIndexedServerSpan(span, requestId).hasParent(rootSpan));
|
||||
|
||||
if (options.hasHandlerSpan.test(endpoint)) {
|
||||
spanAssertions.add(
|
||||
span -> assertHandlerSpan(span, "GET", endpoint).hasParent(trace.getSpan(1)));
|
||||
}
|
||||
|
||||
int parentIndex = spanAssertions.size() - 1;
|
||||
spanAssertions.add(
|
||||
span ->
|
||||
assertIndexedControllerSpan(span, requestId)
|
||||
.hasParent(trace.getSpan(parentIndex)));
|
||||
|
||||
trace.hasSpansSatisfyingExactly(spanAssertions);
|
||||
});
|
||||
}
|
||||
testing.waitAndAssertTraces(assertions);
|
||||
}
|
||||
|
||||
// NOTE: this method does not currently implement asserting all the span types that groovy
|
||||
// HttpServerTest does
|
||||
protected void assertTheTraces(
|
||||
int size,
|
||||
String traceId,
|
||||
String parentId,
|
||||
String method,
|
||||
ServerEndpoint endpoint,
|
||||
String errorMessage,
|
||||
AggregatedHttpResponse response) {
|
||||
List<Consumer<TraceAssert>> assertions = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
assertions.add(
|
||||
trace -> {
|
||||
List<Consumer<SpanDataAssert>> spanAssertions = new ArrayList<>();
|
||||
spanAssertions.add(
|
||||
span -> {
|
||||
assertServerSpan(span, method, endpoint);
|
||||
if (parentId != null) {
|
||||
span.hasTraceId(traceId).hasParentSpanId(parentId);
|
||||
} else {
|
||||
span.hasNoParent();
|
||||
}
|
||||
});
|
||||
|
||||
if (options.hasHandlerSpan.test(endpoint)) {
|
||||
spanAssertions.add(
|
||||
span -> {
|
||||
assertHandlerSpan(span, method, endpoint);
|
||||
span.hasParent(trace.getSpan(0));
|
||||
});
|
||||
}
|
||||
|
||||
if (endpoint != NOT_FOUND) {
|
||||
int parentIndex = spanAssertions.size() - 1;
|
||||
spanAssertions.add(
|
||||
span -> {
|
||||
assertControllerSpan(span, errorMessage, options.expectedExceptionClass);
|
||||
span.hasParent(trace.getSpan(parentIndex));
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasResponseSpan.test(endpoint)) {
|
||||
int parentIndex = spanAssertions.size() - 1;
|
||||
spanAssertions.add(
|
||||
span -> {
|
||||
assertResponseSpan(span, method, endpoint);
|
||||
span.hasParent(trace.getSpan(parentIndex));
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasErrorPageSpans.test(endpoint)) {
|
||||
spanAssertions.addAll(errorPageSpanAssertions(method, endpoint));
|
||||
}
|
||||
|
||||
trace.hasSpansSatisfyingExactly(spanAssertions);
|
||||
});
|
||||
}
|
||||
|
||||
testing.waitAndAssertTraces(assertions);
|
||||
}
|
||||
|
||||
protected SpanDataAssert assertControllerSpan(
|
||||
SpanDataAssert span, String errorMessage, Class<? extends Throwable> exceptionClass) {
|
||||
span.hasName("controller").hasKind(SpanKind.INTERNAL);
|
||||
if (errorMessage != null) {
|
||||
span.hasStatus(StatusData.error());
|
||||
span.hasException(getExceptionInstance(exceptionClass, errorMessage));
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
protected SpanDataAssert assertHandlerSpan(
|
||||
SpanDataAssert span, String method, ServerEndpoint endpoint) {
|
||||
throw new UnsupportedOperationException(
|
||||
"assertHandlerSpan not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
protected SpanDataAssert assertResponseSpan(
|
||||
SpanDataAssert span, String method, ServerEndpoint endpoint) {
|
||||
throw new UnsupportedOperationException(
|
||||
"assertResponseSpan not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
protected List<Consumer<SpanDataAssert>> errorPageSpanAssertions(
|
||||
String method, ServerEndpoint endpoint) {
|
||||
throw new UnsupportedOperationException(
|
||||
"errorPageSpanAssertions not implemented in " + getClass().getName());
|
||||
}
|
||||
|
||||
protected SpanDataAssert assertServerSpan(
|
||||
SpanDataAssert span, String method, ServerEndpoint endpoint) {
|
||||
Set<AttributeKey<?>> httpAttributes = options.httpAttributes.apply(endpoint);
|
||||
|
||||
span.hasName(options.expectedServerSpanNameMapper.apply(endpoint, method))
|
||||
.hasKind(SpanKind.SERVER);
|
||||
if (endpoint.status >= 500) {
|
||||
span.hasStatus(StatusData.error());
|
||||
}
|
||||
|
||||
if (endpoint == EXCEPTION && options.hasExceptionOnServerSpan.test(endpoint)) {
|
||||
span.hasException(getExceptionInstance(options.expectedExceptionClass, endpoint.body));
|
||||
}
|
||||
|
||||
span.hasAttributesSatisfying(
|
||||
attrs -> {
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_TRANSPORT)) {
|
||||
assertThat(attrs)
|
||||
.containsEntry(
|
||||
SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP);
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_PEER_PORT)) {
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.NET_PEER_PORT,
|
||||
value ->
|
||||
assertThat(value)
|
||||
.isInstanceOf(Long.class)
|
||||
.isNotEqualTo(Long.valueOf(port)));
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)
|
||||
|| attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) {
|
||||
assertThat(attrs)
|
||||
.containsEntry(SemanticAttributes.NET_PEER_IP, options.peerIp.apply(endpoint));
|
||||
}
|
||||
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_CLIENT_IP,
|
||||
entry ->
|
||||
assertThat(entry)
|
||||
.satisfiesAnyOf(
|
||||
value -> assertThat(value).isNull(),
|
||||
value -> assertThat(value).isEqualTo(TEST_CLIENT_IP)));
|
||||
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_METHOD, method);
|
||||
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_STATUS_CODE, endpoint.status);
|
||||
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_FLAVOR, entry -> assertThat(entry).isIn("1.1", "2.0"));
|
||||
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_USER_AGENT, TEST_USER_AGENT);
|
||||
|
||||
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_SCHEME, "http");
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_HOST,
|
||||
entry -> assertThat(entry).isIn("localhost", "localhost:" + port));
|
||||
if (endpoint != INDEXED_CHILD) {
|
||||
assertThat(attrs)
|
||||
.containsEntry(
|
||||
SemanticAttributes.HTTP_TARGET,
|
||||
endpoint.resolvePath(address).getPath()
|
||||
+ (endpoint == QUERY_PARAM ? "?" + endpoint.body : ""));
|
||||
}
|
||||
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)
|
||||
|| attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) {
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
|
||||
entry -> assertThat(entry).isInstanceOf(Long.class));
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)
|
||||
|| attrs.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH) != null) {
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
|
||||
entry -> assertThat(entry).isInstanceOf(Long.class));
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) {
|
||||
assertThat(attrs)
|
||||
.hasEntrySatisfying(
|
||||
SemanticAttributes.HTTP_SERVER_NAME,
|
||||
entry -> assertThat(entry).isInstanceOf(String.class));
|
||||
}
|
||||
if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) {
|
||||
String expectedRoute = options.expectedHttpRoute.apply(endpoint);
|
||||
if (expectedRoute != null) {
|
||||
assertThat(attrs).containsEntry(SemanticAttributes.HTTP_ROUTE, expectedRoute);
|
||||
}
|
||||
}
|
||||
|
||||
if (endpoint == CAPTURE_HEADERS) {
|
||||
assertThat(attrs)
|
||||
.containsEntry("http.request.header.x_test_request", new String[] {"test"});
|
||||
assertThat(attrs)
|
||||
.containsEntry("http.response.header.x_test_response", new String[] {"test"});
|
||||
}
|
||||
if (endpoint == CAPTURE_PARAMETERS) {
|
||||
assertThat(attrs)
|
||||
.containsEntry(
|
||||
"servlet.request.parameter.test_parameter", new String[] {"test value õäöü"});
|
||||
}
|
||||
});
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
private static Throwable getExceptionInstance(Class<?> exceptionClass, String exceptionMessage) {
|
||||
try {
|
||||
Constructor<?> constructor = exceptionClass.getDeclaredConstructor(String.class);
|
||||
return (Throwable) constructor.newInstance(exceptionMessage);
|
||||
} catch (NoSuchMethodException
|
||||
| InstantiationException
|
||||
| IllegalAccessException
|
||||
| InvocationTargetException exception) {
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected SpanDataAssert assertIndexedServerSpan(SpanDataAssert span, int requestId) {
|
||||
ServerEndpoint endpoint = INDEXED_CHILD;
|
||||
String method = "GET";
|
||||
assertServerSpan(span, method, endpoint);
|
||||
|
||||
span.hasAttributesSatisfying(
|
||||
attrs ->
|
||||
assertThat(attrs)
|
||||
.containsEntry(
|
||||
SemanticAttributes.HTTP_TARGET,
|
||||
endpoint.resolvePath(address).getPath() + "?id=" + requestId));
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
protected SpanDataAssert assertIndexedControllerSpan(SpanDataAssert span, int requestId) {
|
||||
span.hasName("controller")
|
||||
.hasKind(SpanKind.INTERNAL)
|
||||
.hasAttributesSatisfying(
|
||||
attrs -> assertThat(attrs).containsEntry(ServerEndpoint.ID_ATTRIBUTE_NAME, requestId));
|
||||
return span;
|
||||
}
|
||||
|
||||
public String expectedServerSpanName(ServerEndpoint endpoint, String method) {
|
||||
String route = expectedHttpRoute(endpoint);
|
||||
return route == null ? "HTTP " + method : route;
|
||||
}
|
||||
|
||||
public String expectedHttpRoute(ServerEndpoint endpoint) {
|
||||
// no need to compute route if we're not expecting it
|
||||
if (!options.httpAttributes.apply(endpoint).contains(SemanticAttributes.HTTP_ROUTE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (endpoint) {
|
||||
case NOT_FOUND:
|
||||
return null;
|
||||
case PATH_PARAM:
|
||||
return options.contextPath + "/path/:id/param";
|
||||
default:
|
||||
return endpoint.resolvePath(address).getPath();
|
||||
}
|
||||
}
|
||||
|
||||
final void setTesting(InstrumentationTestRunner testing, WebClient client, int port) {
|
||||
setTesting(testing, client, port, null);
|
||||
}
|
||||
|
||||
final void setTesting(
|
||||
InstrumentationTestRunner testing, WebClient client, int port, URI address) {
|
||||
this.testing = testing;
|
||||
this.client = client;
|
||||
this.port = port;
|
||||
this.address = address;
|
||||
}
|
||||
}
|
|
@ -54,7 +54,7 @@ public final class HttpClientInstrumentationExtension extends InstrumentationExt
|
|||
|
||||
if (!(testInstance instanceof AbstractHttpClientTest)) {
|
||||
throw new AssertionError(
|
||||
"HttpClientLibraryInstrumentationExtension can only be applied to a subclass of "
|
||||
"HttpClientInstrumentationExtension can only be applied to a subclass of "
|
||||
+ "AbstractHttpClientTest");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.testing.junit.http;
|
||||
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.TEST_CLIENT_IP;
|
||||
import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.TEST_USER_AGENT;
|
||||
|
||||
import io.opentelemetry.instrumentation.test.utils.PortUtils;
|
||||
import io.opentelemetry.instrumentation.testing.AgentTestRunner;
|
||||
import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner;
|
||||
import io.opentelemetry.instrumentation.testing.LibraryTestRunner;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import io.opentelemetry.testing.internal.armeria.client.ClientFactory;
|
||||
import io.opentelemetry.testing.internal.armeria.client.WebClient;
|
||||
import io.opentelemetry.testing.internal.armeria.client.logging.LoggingClient;
|
||||
import io.opentelemetry.testing.internal.armeria.common.HttpHeaderNames;
|
||||
import java.time.Duration;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
/**
|
||||
* A {@link InstrumentationExtension} which sets up infrastructure, such as a test HTTP client, for
|
||||
* {@link AbstractHttpServerTest}.
|
||||
*/
|
||||
public final class HttpServerInstrumentationExtension extends InstrumentationExtension {
|
||||
|
||||
/**
|
||||
* Returns a {@link InstrumentationExtension} to be used with {@link AbstractHttpClientTest} for
|
||||
* javaagent instrumentation.
|
||||
*/
|
||||
public static InstrumentationExtension forAgent() {
|
||||
return new HttpServerInstrumentationExtension(AgentTestRunner.instance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link InstrumentationExtension} to be used with {@link AbstractHttpClientTest} for
|
||||
* library instrumentation.
|
||||
*/
|
||||
public static InstrumentationExtension forLibrary() {
|
||||
return new HttpServerInstrumentationExtension(LibraryTestRunner.instance());
|
||||
}
|
||||
|
||||
private final int port;
|
||||
private final WebClient client;
|
||||
|
||||
private HttpServerInstrumentationExtension(InstrumentationTestRunner runner) {
|
||||
super(runner);
|
||||
|
||||
port = PortUtils.findOpenPort();
|
||||
client =
|
||||
WebClient.builder()
|
||||
.responseTimeout(Duration.ofMinutes(1))
|
||||
.writeTimeout(Duration.ofMinutes(1))
|
||||
.factory(ClientFactory.builder().connectTimeout(Duration.ofMinutes(1)).build())
|
||||
.setHeader(HttpHeaderNames.USER_AGENT, TEST_USER_AGENT)
|
||||
.setHeader(HttpHeaderNames.X_FORWARDED_FOR, TEST_CLIENT_IP)
|
||||
.decorator(LoggingClient.newDecorator())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext extensionContext) throws Exception {
|
||||
super.beforeAll(extensionContext);
|
||||
Object testInstance = extensionContext.getRequiredTestInstance();
|
||||
|
||||
if (!(testInstance instanceof AbstractHttpServerTest)) {
|
||||
throw new AssertionError(
|
||||
"HttpServerInstrumentationExtension can only be applied to a subclass of "
|
||||
+ "AbstractHttpServerTest");
|
||||
}
|
||||
|
||||
((AbstractHttpServerTest) testInstance).setTesting(getTestRunner(), client, port);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.testing.junit.http;
|
||||
|
||||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class HttpServerTestOptions {
|
||||
|
||||
public static final Set<AttributeKey<?>> DEFAULT_HTTP_ATTRIBUTES =
|
||||
Collections.unmodifiableSet(
|
||||
new HashSet<>(
|
||||
Arrays.asList(
|
||||
SemanticAttributes.HTTP_ROUTE,
|
||||
SemanticAttributes.NET_TRANSPORT,
|
||||
SemanticAttributes.NET_PEER_PORT)));
|
||||
|
||||
public static final BiFunction<ServerEndpoint, String, String>
|
||||
DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER = (uri, method) -> "HTTP " + method;
|
||||
|
||||
Function<ServerEndpoint, Set<AttributeKey<?>>> httpAttributes = unused -> DEFAULT_HTTP_ATTRIBUTES;
|
||||
BiFunction<ServerEndpoint, String, String> expectedServerSpanNameMapper =
|
||||
DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER;
|
||||
Function<ServerEndpoint, String> expectedHttpRoute = unused -> null;
|
||||
Function<ServerEndpoint, String> peerIp = unused -> "127.0.0.1";
|
||||
String contextPath = "";
|
||||
Class<? extends Throwable> expectedExceptionClass = Exception.class;
|
||||
|
||||
Predicate<ServerEndpoint> hasHandlerSpan = unused -> false;
|
||||
Predicate<ServerEndpoint> hasResponseSpan = unused -> false;
|
||||
Predicate<ServerEndpoint> hasErrorPageSpans = unused -> false;
|
||||
|
||||
Predicate<ServerEndpoint> hasExceptionOnServerSpan = endpoint -> !hasHandlerSpan.test(endpoint);
|
||||
|
||||
boolean testRedirect = true;
|
||||
boolean testError = true;
|
||||
boolean testErrorBody = true;
|
||||
boolean testException = true;
|
||||
boolean testNotFound = true;
|
||||
boolean testPathParam = false;
|
||||
boolean testCaptureHttpHeaders = true;
|
||||
boolean testCaptureRequestParameters = false;
|
||||
|
||||
HttpServerTestOptions() {}
|
||||
|
||||
public HttpServerTestOptions setHttpAttributes(
|
||||
Function<ServerEndpoint, Set<AttributeKey<?>>> httpAttributes) {
|
||||
this.httpAttributes = httpAttributes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setExpectedServerSpanNameMapper(
|
||||
BiFunction<ServerEndpoint, String, String> expectedServerSpanNameMapper) {
|
||||
this.expectedServerSpanNameMapper = expectedServerSpanNameMapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setExpectedHttpRoute(
|
||||
Function<ServerEndpoint, String> expectedHttpRoute) {
|
||||
this.expectedHttpRoute = expectedHttpRoute;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setPeerIp(Function<ServerEndpoint, String> peerIp) {
|
||||
this.peerIp = peerIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setExpectedExceptionClass(
|
||||
Class<? extends Throwable> expectedExceptionClass) {
|
||||
this.expectedExceptionClass = expectedExceptionClass;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setHasHandlerSpan(Predicate<ServerEndpoint> hasHandlerSpan) {
|
||||
this.hasHandlerSpan = hasHandlerSpan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setHasResponseSpan(Predicate<ServerEndpoint> hasResponseSpan) {
|
||||
this.hasResponseSpan = hasResponseSpan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setHasErrorPageSpans(Predicate<ServerEndpoint> hasErrorPageSpans) {
|
||||
this.hasErrorPageSpans = hasErrorPageSpans;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setHasExceptionOnServerSpan(
|
||||
Predicate<ServerEndpoint> hasExceptionOnServerSpan) {
|
||||
this.hasExceptionOnServerSpan = hasExceptionOnServerSpan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestRedirect(boolean testRedirect) {
|
||||
this.testRedirect = testRedirect;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestError(boolean testError) {
|
||||
this.testError = testError;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestErrorBody(boolean testErrorBody) {
|
||||
this.testErrorBody = testErrorBody;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestException(boolean testException) {
|
||||
this.testException = testException;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestNotFound(boolean testNotFound) {
|
||||
this.testNotFound = testNotFound;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestPathParam(boolean testPathParam) {
|
||||
this.testPathParam = testPathParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestCaptureHttpHeaders(boolean testCaptureHttpHeaders) {
|
||||
this.testCaptureHttpHeaders = testCaptureHttpHeaders;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServerTestOptions setTestCaptureRequestParameters(
|
||||
boolean testCaptureRequestParameters) {
|
||||
this.testCaptureRequestParameters = testCaptureRequestParameters;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.testing.junit.http;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum ServerEndpoint {
|
||||
SUCCESS("success", 200, "success"),
|
||||
REDIRECT("redirect", 302, "/redirected"),
|
||||
ERROR("error-status", 500, "controller error"), // "error" is a special path for some frameworks
|
||||
EXCEPTION("exception", 500, "controller exception"),
|
||||
NOT_FOUND("notFound", 404, "not found"),
|
||||
CAPTURE_HEADERS("captureHeaders", 200, "headers captured"),
|
||||
CAPTURE_PARAMETERS("captureParameters", 200, "parameters captured"),
|
||||
|
||||
// TODO: add tests for the following cases:
|
||||
QUERY_PARAM("query?some=query", 200, "some=query"),
|
||||
// OkHttp never sends the fragment in the request, so these cases don't work.
|
||||
// FRAGMENT_PARAM("fragment#some-fragment", 200, "some-fragment"),
|
||||
// QUERY_FRAGMENT_PARAM("query/fragment?some=query#some-fragment", 200,
|
||||
// "some=query#some-fragment"),
|
||||
PATH_PARAM("path/123/param", 200, "123"),
|
||||
AUTH_REQUIRED("authRequired", 200, null),
|
||||
LOGIN("login", 302, null),
|
||||
AUTH_ERROR("basicsecured/endpoint", 401, null),
|
||||
INDEXED_CHILD("child", 200, "");
|
||||
|
||||
public static final String ID_ATTRIBUTE_NAME = "test.request.id";
|
||||
public static final String ID_PARAMETER_NAME = "id";
|
||||
|
||||
private final URI uriObj;
|
||||
private final String path;
|
||||
final String query;
|
||||
final String fragment;
|
||||
final int status;
|
||||
final String body;
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public String getFragment() {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
ServerEndpoint(String uri, int status, String body) {
|
||||
this.uriObj = URI.create(uri);
|
||||
this.path = uriObj.getPath();
|
||||
this.query = uriObj.getQuery();
|
||||
this.fragment = uriObj.getFragment();
|
||||
this.status = status;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return "/" + path;
|
||||
}
|
||||
|
||||
public String rawPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
URI resolvePath(URI address) {
|
||||
return address.resolve(path);
|
||||
}
|
||||
|
||||
URI resolve(URI address) {
|
||||
return address.resolve(uriObj);
|
||||
}
|
||||
|
||||
URI resolveWithoutFragment(URI address) throws URISyntaxException {
|
||||
URI uri = resolve(address);
|
||||
return new URI(
|
||||
uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates custom test attributes for the {@link
|
||||
* io.opentelemetry.instrumentation.test.base.HttpServerTest#controller} span (which must be the
|
||||
* current span when this is called) based on URL parameters. Required for {@link #INDEXED_CHILD}.
|
||||
*/
|
||||
public void collectSpanAttributes(ServerEndpoint.UrlParameterProvider parameterProvider) {
|
||||
if (this == INDEXED_CHILD) {
|
||||
String value = parameterProvider.getParameter(ID_PARAMETER_NAME);
|
||||
|
||||
if (value != null) {
|
||||
Span.current().setAttribute(ID_ATTRIBUTE_NAME, Long.parseLong(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, ServerEndpoint> PATH_MAP =
|
||||
Arrays.stream(values()).collect(Collectors.toMap(x -> x.getPath(), x -> x));
|
||||
|
||||
public static ServerEndpoint forPath(String path) {
|
||||
return PATH_MAP.get(path);
|
||||
}
|
||||
|
||||
public interface UrlParameterProvider {
|
||||
String getParameter(String name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue