105 lines
3.3 KiB
Groovy
105 lines
3.3 KiB
Groovy
/*
|
|
* Copyright 2020, OpenTelemetry Authors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
import io.opentelemetry.auto.instrumentation.akkahttp.AkkaHttpServerDecorator
|
|
import io.opentelemetry.auto.instrumentation.api.MoreTags
|
|
import io.opentelemetry.auto.instrumentation.api.SpanTypes
|
|
import io.opentelemetry.auto.instrumentation.api.Tags
|
|
import io.opentelemetry.auto.test.asserts.TraceAssert
|
|
import io.opentelemetry.auto.test.base.HttpServerTest
|
|
import spock.lang.Retry
|
|
|
|
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
|
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
|
import static io.opentelemetry.trace.Span.Kind.SERVER
|
|
|
|
abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<Object, AkkaHttpServerDecorator> {
|
|
|
|
@Override
|
|
AkkaHttpServerDecorator decorator() {
|
|
return AkkaHttpServerDecorator.DECORATE
|
|
}
|
|
|
|
@Override
|
|
boolean testExceptionBody() {
|
|
false
|
|
}
|
|
|
|
// FIXME: This doesn't work because we don't support bindAndHandle.
|
|
// @Override
|
|
// def startServer(int port) {
|
|
// AkkaHttpTestWebServer.start(port)
|
|
// }
|
|
//
|
|
// @Override
|
|
// void stopServer(Object ignore) {
|
|
// AkkaHttpTestWebServer.stop()
|
|
// }
|
|
|
|
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", ServerEndpoint endpoint = SUCCESS) {
|
|
trace.span(index) {
|
|
operationName expectedOperationName(method)
|
|
spanKind SERVER
|
|
errored endpoint.errored
|
|
if (parentID != null) {
|
|
traceId traceID
|
|
parentId parentID
|
|
} else {
|
|
parent()
|
|
}
|
|
tags {
|
|
"$MoreTags.SPAN_TYPE" SpanTypes.HTTP_SERVER
|
|
"$Tags.COMPONENT" serverDecorator.getComponentName()
|
|
"$Tags.HTTP_URL" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
|
|
"$Tags.HTTP_METHOD" method
|
|
"$Tags.HTTP_STATUS" endpoint.status
|
|
if (endpoint.errored) {
|
|
"error.msg" { it == null || it == EXCEPTION.body }
|
|
"error.type" { it == null || it == Exception.name }
|
|
"error.stack" { it == null || it instanceof String }
|
|
}
|
|
if (endpoint.query) {
|
|
"$MoreTags.HTTP_QUERY" endpoint.query
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class AkkaHttpServerInstrumentationTestSync extends AkkaHttpServerInstrumentationTest {
|
|
@Override
|
|
def startServer(int port) {
|
|
AkkaHttpTestSyncWebServer.start(port)
|
|
}
|
|
|
|
@Override
|
|
void stopServer(Object ignore) {
|
|
AkkaHttpTestSyncWebServer.stop()
|
|
}
|
|
}
|
|
|
|
@Retry(mode = Retry.Mode.SETUP_FEATURE_CLEANUP)
|
|
class AkkaHttpServerInstrumentationTestAsync extends AkkaHttpServerInstrumentationTest {
|
|
@Override
|
|
def startServer(int port) {
|
|
AkkaHttpTestAsyncWebServer.start(port)
|
|
}
|
|
|
|
@Override
|
|
void stopServer(Object ignore) {
|
|
AkkaHttpTestAsyncWebServer.stop()
|
|
}
|
|
}
|