Remove unnecessary overrides (#1477)

This commit is contained in:
Trask Stalnaker 2020-10-25 21:46:14 -07:00 committed by GitHub
parent 3565775b00
commit 7244dbf188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 36 additions and 201 deletions

View File

@ -24,7 +24,7 @@ abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<Object>
// }
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "akka.request"
}
}

View File

@ -87,6 +87,7 @@ class DropwizardTest extends HttpServerTest<DropwizardTestSupport> {
}
}
// this override is needed because dropwizard reports peer ip as the client ip
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {

View File

@ -3,10 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
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.trace.Span.Kind.INTERNAL
import static io.opentelemetry.trace.Span.Kind.SERVER
import com.twitter.finatra.http.HttpServer
import com.twitter.util.Await
@ -15,7 +13,6 @@ import com.twitter.util.Duration
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import io.opentelemetry.sdk.trace.data.SpanData
import io.opentelemetry.trace.attributes.SemanticAttributes
import java.util.concurrent.TimeoutException
class FinatraServerTest extends HttpServerTest<HttpServer> {
@ -83,29 +80,4 @@ class FinatraServerTest extends HttpServerTest<HttpServer> {
}
}
}
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {
name endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.resolvePath(address).path
kind SERVER
errored endpoint.errored
if (parentID != null) {
traceId traceID
parentSpanId parentID
} else {
hasNoParent()
}
attributes {
"${SemanticAttributes.NET_PEER_PORT.key()}" Long
"${SemanticAttributes.NET_PEER_IP.key()}" { it == null || it == "127.0.0.1" } // Optional
"${SemanticAttributes.HTTP_URL.key()}" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
"${SemanticAttributes.HTTP_METHOD.key()}" method
"${SemanticAttributes.HTTP_STATUS_CODE.key()}" endpoint.status
"${SemanticAttributes.HTTP_FLAVOR.key()}" "HTTP/1.1"
"${SemanticAttributes.HTTP_USER_AGENT.key()}" TEST_USER_AGENT
"${SemanticAttributes.HTTP_CLIENT_IP.key()}" TEST_CLIENT_IP
}
}
}
}

View File

@ -205,7 +205,7 @@ class GrizzlyFilterchainServerTest extends HttpServerTest<HttpServer> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "HttpCodecFilter.handleRead"
}

View File

@ -96,7 +96,7 @@ class GrizzlyTest extends HttpServerTest<HttpServer> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "HttpCodecFilter.handleRead"
}

View File

@ -9,11 +9,8 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
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.trace.Span.Kind.SERVER
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import io.opentelemetry.trace.attributes.SemanticAttributes
import javax.servlet.DispatcherType
import javax.servlet.ServletException
import javax.servlet.http.HttpServletRequest
@ -110,30 +107,7 @@ class JettyHandlerTest extends HttpServerTest<Server> {
}
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {
name "TestHandler.handle"
kind SERVER
errored endpoint.errored
if (endpoint == EXCEPTION) {
errorEvent(Exception, EXCEPTION.body)
}
if (parentID != null) {
traceId traceID
parentSpanId parentID
} else {
hasNoParent()
}
attributes {
"${SemanticAttributes.NET_PEER_IP.key()}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key()}" Long
"${SemanticAttributes.HTTP_URL.key()}" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
"${SemanticAttributes.HTTP_METHOD.key()}" method
"${SemanticAttributes.HTTP_STATUS_CODE.key()}" endpoint.status
"${SemanticAttributes.HTTP_FLAVOR.key()}" "HTTP/1.1"
"${SemanticAttributes.HTTP_USER_AGENT.key()}" TEST_USER_AGENT
"${SemanticAttributes.HTTP_CLIENT_IP.key()}" TEST_CLIENT_IP
}
}
String expectedServerSpanName(ServerEndpoint endpoint) {
"TestHandler.handle"
}
}

View File

@ -141,7 +141,7 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "netty.request"
}

View File

@ -141,7 +141,7 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "netty.request"
}

View File

@ -113,7 +113,7 @@ class Netty40ServerTest extends HttpServerTest<EventLoopGroup> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "netty.request"
}

View File

@ -112,7 +112,7 @@ class Netty41ServerTest extends HttpServerTest<EventLoopGroup> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "netty.request"
}

View File

@ -46,7 +46,7 @@ class PlayServerTest extends HttpServerTest<TestServer> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "netty.request"
}
}

View File

@ -83,7 +83,7 @@ class PlayServerTest extends HttpServerTest<Server> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "netty.request"
}

View File

@ -85,7 +85,7 @@ class PlayServerTest extends HttpServerTest<Server> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return "akka.request"
}

View File

@ -120,7 +120,7 @@ class RatpackHttpServerTest extends HttpServerTest<EmbeddedApp> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint.status == 404 ? "/" : endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.path
}
}

View File

@ -3,13 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static io.opentelemetry.trace.Span.Kind.SERVER
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import io.opentelemetry.trace.attributes.SemanticAttributes
import org.glassfish.embeddable.BootstrapProperties
import org.glassfish.embeddable.Deployer
import org.glassfish.embeddable.GlassFish
@ -69,39 +63,11 @@ class GlassFishServerTest extends HttpServerTest<GlassFish> {
true
}
// Simple class name plus method name of the entry point of the given servlet container.
// "Entry point" here means the first filter or servlet that accepts incoming requests.
// This will serve as a default name of the SERVER span created for this request.
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {
name entryPointName()
kind SERVER
errored endpoint.errored
if (parentID != null) {
traceId traceID
parentSpanId parentID
} else {
hasNoParent()
}
if (endpoint == EXCEPTION) {
errorEvent(Exception, EXCEPTION.body)
}
attributes {
"${SemanticAttributes.NET_PEER_IP.key()}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key()}" Long
"${SemanticAttributes.HTTP_STATUS_CODE.key()}" endpoint.status
"${SemanticAttributes.HTTP_METHOD.key()}" method
"${SemanticAttributes.HTTP_URL.key()}" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
"${SemanticAttributes.HTTP_FLAVOR.key()}" "HTTP/1.1"
"${SemanticAttributes.HTTP_USER_AGENT.key()}" TEST_USER_AGENT
"${SemanticAttributes.HTTP_CLIENT_IP.key()}" TEST_CLIENT_IP
}
}
}
//Simple class name plus method name of the entry point of the given servlet container.
//"Entry point" here means the first filter or servlet that accepts incoming requests.
//This will serve as a default name of the SERVER span created for this request.
protected String entryPointName() {
'HttpServlet.service'
String expectedServerSpanName(ServerEndpoint endpoint) {
"HttpServlet.service"
}
}

View File

@ -10,12 +10,10 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static io.opentelemetry.trace.Span.Kind.INTERNAL
import static io.opentelemetry.trace.Span.Kind.SERVER
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import io.opentelemetry.sdk.trace.data.SpanData
import io.opentelemetry.trace.attributes.SemanticAttributes
import javax.servlet.http.HttpServletRequest
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.handler.ErrorHandler
@ -84,32 +82,9 @@ class JettyServlet2Test extends HttpServerTest<Server> {
}
}
// 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) {
trace.span(index) {
name 'HttpServlet.service'
kind SERVER
errored endpoint.errored
if (parentID != null) {
traceId traceID
parentSpanId parentID
} else {
hasNoParent()
}
if (endpoint == EXCEPTION) {
errorEvent(Exception, EXCEPTION.body)
}
attributes {
"${SemanticAttributes.NET_PEER_IP.key()}" "127.0.0.1"
// No peer port
"${SemanticAttributes.HTTP_URL.key()}" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
"${SemanticAttributes.HTTP_METHOD.key()}" method
"${SemanticAttributes.HTTP_STATUS_CODE.key()}" endpoint.status
"${SemanticAttributes.HTTP_FLAVOR.key()}" "HTTP/1.1"
"${SemanticAttributes.HTTP_USER_AGENT.key()}" TEST_USER_AGENT
"${SemanticAttributes.HTTP_CLIENT_IP.key()}" TEST_CLIENT_IP
}
}
@Override
String expectedServerSpanName(ServerEndpoint endpoint) {
"HttpServlet.service"
}
/**

View File

@ -10,10 +10,7 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import io.opentelemetry.trace.Span
import io.opentelemetry.trace.attributes.SemanticAttributes
import javax.servlet.Servlet
import okhttp3.Request
import okhttp3.RequestBody
@ -57,38 +54,11 @@ abstract class AbstractServlet3Test<SERVER, CONTEXT> extends HttpServerTest<SERV
super.request(uri, method, body)
}
// Simple class name plus method name of the entry point of the given servlet container.
// "Entry point" here means the first filter or servlet that accepts incoming requests.
// This will serve as a default name of the SERVER span created for this request.
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {
name entryPointName()
kind Span.Kind.SERVER // can't use static import because of SERVER type parameter
errored endpoint.errored
if (parentID != null) {
traceId traceID
parentSpanId parentID
} else {
hasNoParent()
}
if (endpoint == EXCEPTION) {
errorEvent(Exception, EXCEPTION.body)
}
attributes {
"${SemanticAttributes.NET_PEER_IP.key()}" "127.0.0.1"
"${SemanticAttributes.NET_PEER_PORT.key()}" Long
"${SemanticAttributes.HTTP_URL.key()}" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
"${SemanticAttributes.HTTP_METHOD.key()}" method
"${SemanticAttributes.HTTP_STATUS_CODE.key()}" endpoint.status
"${SemanticAttributes.HTTP_FLAVOR.key()}" "HTTP/1.1"
"${SemanticAttributes.HTTP_USER_AGENT.key()}" TEST_USER_AGENT
"${SemanticAttributes.HTTP_CLIENT_IP.key()}" TEST_CLIENT_IP
}
}
}
//Simple class name plus method name of the entry point of the given servlet container.
//"Entry point" here means the first filter or servlet that accepts incoming requests.
//This will serve as a default name of the SERVER span created for this request.
protected String entryPointName() {
'HttpServlet.service'
String expectedServerSpanName(ServerEndpoint endpoint) {
"HttpServlet.service"
}
}

View File

@ -84,7 +84,7 @@ abstract class TomcatServlet3Test extends AbstractServlet3Test<Tomcat, Context>
}
@Override
protected String entryPointName() {
String expectedServerSpanName(ServerEndpoint endpoint) {
return 'ApplicationFilterChain.doFilter'
}

View File

@ -159,6 +159,8 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
}
}
// this override is needed because the exception is propagated up from the handler span
// to the server span, which is different from the the expectation of the super method
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {

View File

@ -10,13 +10,11 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn
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.trace.Span.Kind.INTERNAL
import static io.opentelemetry.trace.Span.Kind.SERVER
import com.google.common.collect.ImmutableMap
import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import io.opentelemetry.sdk.trace.data.SpanData
import io.opentelemetry.trace.attributes.SemanticAttributes
import org.springframework.boot.SpringApplication
import org.springframework.context.ConfigurableApplicationContext
import test.boot.SecurityConfig
@ -77,31 +75,8 @@ class ServletFilterTest extends HttpServerTest<ConfigurableApplicationContext> {
}
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {
name endpoint == PATH_PARAM ? "/path/{id}/param" : endpoint.resolvePath(address).path
kind SERVER
errored endpoint.errored
if (parentID != null) {
traceId traceID
parentSpanId parentID
} else {
hasNoParent()
}
if (endpoint == EXCEPTION) {
errorEvent(Exception, EXCEPTION.body)
}
attributes {
"${SemanticAttributes.NET_PEER_IP.key()}" { it == null || it == "127.0.0.1" } // Optional
"${SemanticAttributes.NET_PEER_PORT.key()}" Long
"${SemanticAttributes.HTTP_URL.key()}" { it == "${endpoint.resolve(address)}" || it == "${endpoint.resolveWithoutFragment(address)}" }
"${SemanticAttributes.HTTP_METHOD.key()}" method
"${SemanticAttributes.HTTP_STATUS_CODE.key()}" endpoint.status
"${SemanticAttributes.HTTP_FLAVOR.key()}" "HTTP/1.1"
"${SemanticAttributes.HTTP_USER_AGENT.key()}" TEST_USER_AGENT
"${SemanticAttributes.HTTP_CLIENT_IP.key()}" TEST_CLIENT_IP
}
}
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint == PATH_PARAM ? "/path/{id}/param" : endpoint.resolvePath(address).path
}
@Override

View File

@ -71,7 +71,7 @@ class VertxHttpServerTest extends HttpServerTest<Vertx> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.getPath()
}

View File

@ -74,7 +74,7 @@ class VertxRxHttpServerTest extends HttpServerTest<Vertx> {
}
@Override
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.getPath()
}

View File

@ -84,7 +84,7 @@ abstract class HttpServerTest<SERVER> extends AgentTestRunner {
abstract void stopServer(SERVER server)
String expectedServerSpanName(String method, ServerEndpoint endpoint) {
String expectedServerSpanName(ServerEndpoint endpoint) {
return endpoint == PATH_PARAM ? "/path/:id/param" : endpoint.resolvePath(address).path
}
@ -442,7 +442,7 @@ abstract class HttpServerTest<SERVER> extends AgentTestRunner {
// 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) {
trace.span(index) {
name expectedServerSpanName(method, endpoint)
name expectedServerSpanName(endpoint)
kind Span.Kind.SERVER // can't use static import because of SERVER type parameter
errored endpoint.errored
if (parentID != null) {