diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy index 6ba1da5f2c82..5ad8a71bd797 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy @@ -5,6 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.apachecamel +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP + import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.RetryOnAddressAlreadyInUseTrait import io.opentelemetry.instrumentation.test.utils.PortUtils @@ -96,6 +98,8 @@ class RestCamelTest extends AgentInstrumentationSpecification implements RetryOn "$SemanticAttributes.HTTP_METHOD.key" "GET" "$SemanticAttributes.NET_PEER_IP.key" "127.0.0.1" "$SemanticAttributes.NET_PEER_PORT.key" Long + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } it.span(3) { diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy index 79d251e2a8f8..53b8f3990502 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy @@ -5,6 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.apachecamel +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP + import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.RetryOnAddressAlreadyInUseTrait import io.opentelemetry.instrumentation.test.utils.PortUtils @@ -131,6 +133,9 @@ class TwoServicesWithDirectClientCamelTest extends AgentInstrumentationSpecifica "$SemanticAttributes.NET_PEER_IP.key" "127.0.0.1" "$SemanticAttributes.HTTP_USER_AGENT.key" "Jakarta Commons-HttpClient/3.1" "$SemanticAttributes.HTTP_FLAVOR.key" "1.1" + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP + "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" Long } } it.span(5) { diff --git a/instrumentation/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy b/instrumentation/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy index 15e819cb45c6..1b8752f14f86 100644 --- a/instrumentation/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy +++ b/instrumentation/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy @@ -7,7 +7,6 @@ import io.dropwizard.Application import io.dropwizard.Configuration import io.dropwizard.setup.Bootstrap import io.dropwizard.setup.Environment - import javax.ws.rs.GET import javax.ws.rs.HeaderParam import javax.ws.rs.Path diff --git a/instrumentation/dropwizard-testing/src/test/groovy/DropwizardTest.groovy b/instrumentation/dropwizard-testing/src/test/groovy/DropwizardTest.groovy index 65f72bb08a19..652b3e87415d 100644 --- a/instrumentation/dropwizard-testing/src/test/groovy/DropwizardTest.groovy +++ b/instrumentation/dropwizard-testing/src/test/groovy/DropwizardTest.groovy @@ -9,6 +9,7 @@ import io.dropwizard.setup.Bootstrap import io.dropwizard.setup.Environment import io.dropwizard.testing.ConfigOverride import io.dropwizard.testing.DropwizardTestSupport +import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert @@ -25,7 +26,6 @@ import javax.ws.rs.QueryParam import javax.ws.rs.core.Response import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.api.trace.SpanKind.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 @@ -61,6 +61,21 @@ class DropwizardTest extends HttpServerTest implements Ag testSupport.after() } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + + // this override is needed because dropwizard reports peer ip as the client ip + @Override + String peerIp(ServerEndpoint endpoint) { + TEST_CLIENT_IP + } + @Override boolean hasHandlerSpan(ServerEndpoint endpoint) { endpoint != NOT_FOUND @@ -96,41 +111,6 @@ class DropwizardTest extends HttpServerTest implements Ag } } - // 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) { - name expectedServerSpanName(endpoint) - kind SERVER - if (endpoint.errored) { - status StatusCode.ERROR - } - if (parentID != null) { - traceId traceID - parentSpanId parentID - } else { - hasNoParent() - } - attributes { - // dropwizard reports peer ip as the client ip - "${SemanticAttributes.NET_PEER_IP.key}" TEST_CLIENT_IP - "${SemanticAttributes.NET_PEER_PORT.key}" Long - "${SemanticAttributes.HTTP_SCHEME.key}" "http" - "${SemanticAttributes.HTTP_HOST}" "localhost:${port}" - "${SemanticAttributes.HTTP_TARGET}" endpoint.resolvePath(address).getPath() + "${endpoint == QUERY_PARAM ? "?${endpoint.body}" : ""}" - "${SemanticAttributes.HTTP_METHOD.key}" method - "${SemanticAttributes.HTTP_STATUS_CODE.key}" endpoint.status - "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" - "${SemanticAttributes.HTTP_USER_AGENT.key}" TEST_USER_AGENT - "${SemanticAttributes.HTTP_CLIENT_IP.key}" TEST_CLIENT_IP - if (endpoint == ServerEndpoint.CAPTURE_HEADERS) { - "http.request.header.x_test_request" { it == ["test"] } - "http.response.header.x_test_response" { it == ["test"] } - } - } - } - } - static class TestApp extends Application { @Override void initialize(Bootstrap bootstrap) { diff --git a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy index b895cce23333..d39c6a782b3c 100644 --- a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy +++ b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy @@ -8,11 +8,13 @@ package test import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration import groovy.transform.CompileStatic +import io.opentelemetry.api.common.AttributeKey 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 io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.web.ServerProperties import org.springframework.context.ConfigurableApplicationContext @@ -53,6 +55,15 @@ class GrailsTest extends HttpServerTest implemen } } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override String expectedServerSpanName(ServerEndpoint endpoint) { if (endpoint == PATH_PARAM) { diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy index f348e43186e5..665477e69297 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy @@ -3,6 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP + +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 @@ -187,6 +190,14 @@ abstract class JaxRsHttpServerTest extends HttpServerTest implements Agent "failing" | "throw" | 500 | { it == "failure" } | true | "failure" } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasHandlerSpan(ServerEndpoint endpoint) { true @@ -281,6 +292,9 @@ abstract class JaxRsHttpServerTest extends HttpServerTest implements Agent "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" TEST_USER_AGENT "${SemanticAttributes.HTTP_CLIENT_IP.key}" TEST_CLIENT_IP + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP + "${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH}" { it == null || it instanceof Long } // Optional if (fullUrl.getPath().endsWith(ServerEndpoint.CAPTURE_HEADERS.getPath())) { "http.request.header.x_test_request" { it == ["test"] } "http.response.header.x_test_response" { it == ["test"] } diff --git a/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy b/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy index 42fefd6d5491..ed5a8ac75cf4 100644 --- a/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy +++ b/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy @@ -3,9 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +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.semconv.trace.attributes.SemanticAttributes import jakarta.servlet.DispatcherType import jakarta.servlet.ServletException import jakarta.servlet.http.HttpServletRequest @@ -60,6 +62,14 @@ class JettyHandlerTest extends HttpServerTest implements AgentTestTrait server.stop() } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasResponseSpan(ServerEndpoint endpoint) { endpoint == REDIRECT || endpoint == ERROR diff --git a/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy b/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy index 9b483f5d9838..954d2fcc217e 100644 --- a/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy +++ b/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy @@ -3,9 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +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.semconv.trace.attributes.SemanticAttributes import org.eclipse.jetty.server.Request import org.eclipse.jetty.server.Response import org.eclipse.jetty.server.Server @@ -61,6 +63,14 @@ class JettyHandlerTest extends HttpServerTest implements AgentTestTrait server.stop() } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasResponseSpan(ServerEndpoint endpoint) { endpoint == REDIRECT || endpoint == ERROR diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy index 46097dc64a42..e005c6ecdf3a 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP + import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.trace.attributes.SemanticAttributes @@ -96,6 +98,9 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP + "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" { it == null || it instanceof Long } // Optional } } span(1) { @@ -148,6 +153,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -196,6 +203,9 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP + "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" Long } } span(1) { @@ -253,6 +263,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 500 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -315,6 +327,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -358,6 +372,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -433,6 +449,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 500 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -477,6 +495,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } } diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy index 77607c3ef8b1..5c5188fde900 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP + import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.trace.attributes.SemanticAttributes @@ -93,6 +95,8 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -157,6 +161,8 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -200,6 +206,8 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -291,6 +299,8 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -368,6 +378,8 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 500 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { @@ -424,6 +436,8 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 404 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } span(1) { diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy index 4acc916a0683..74b7e001a0d4 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy @@ -3,10 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +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.sdk.trace.data.SpanData +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.ErrorHandler import org.eclipse.jetty.servlet.ServletContextHandler @@ -67,6 +69,14 @@ class JettyServlet2Test extends HttpServerTest implements AgentTestTrait return new URI("http://localhost:$port/$CONTEXT/") } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean testNotFound() { false diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy index 5394977dbf92..fd7fc52a238b 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy @@ -3,9 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +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.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import javax.servlet.Servlet @@ -56,6 +58,14 @@ abstract class AbstractServlet3Test extends HttpServerTest> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + boolean errorEndpointUsesSendError() { true } diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy index e3949177c0dd..4a96b20baccf 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy @@ -3,7 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse import org.apache.catalina.AccessLog import org.apache.catalina.Context @@ -37,6 +39,16 @@ import static org.junit.Assume.assumeTrue @Unroll abstract class TomcatServlet3Test extends AbstractServlet3Test { + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + + @Override Class expectedExceptionClass() { ServletException diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy index f524f8860850..9b48396aef1f 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy @@ -3,9 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +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.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import jakarta.servlet.Servlet @@ -59,6 +61,14 @@ abstract class AbstractServlet5Test extends HttpServerTest> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasResponseSpan(ServerEndpoint endpoint) { endpoint == REDIRECT || (endpoint == ERROR && errorEndpointUsesSendError()) diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy index 3ab836409bea..101209e2c78f 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy @@ -3,7 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse import jakarta.servlet.Servlet import jakarta.servlet.ServletException @@ -37,6 +39,15 @@ import static org.junit.Assume.assumeTrue @Unroll abstract class TomcatServlet5Test extends AbstractServlet5Test { + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override Class expectedExceptionClass() { ServletException diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesExtractor.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesExtractor.java index 5ff2ae3df941..ba29237720fd 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesExtractor.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletHttpAttributesExtractor.java @@ -49,12 +49,10 @@ protected List requestHeader(ServletRequestContext requestConte protected @Nullable Long requestContentLength( ServletRequestContext requestContext, @Nullable ServletResponseContext responseContext) { - /* int contentLength = accessor.getRequestContentLength(requestContext.request()); if (contentLength > -1) { return (long) contentLength; } - */ return null; } @@ -98,8 +96,7 @@ protected List requestHeader(ServletRequestContext requestConte protected @Nullable Long responseContentLength( ServletRequestContext requestContext, ServletResponseContext responseContext) { - /* - String contentLength = servletAccessor.getResponseHeader(responseContext.response(), "Content-Length"); + String contentLength = accessor.getResponseHeader(responseContext.response(), "Content-Length"); if (contentLength != null) { try { return Long.valueOf(contentLength); @@ -107,7 +104,6 @@ protected List requestHeader(ServletRequestContext requestConte // ignore } } - */ return null; } @@ -135,7 +131,6 @@ protected List responseHeader( protected @Nullable String serverName( ServletRequestContext requestContext, @Nullable ServletResponseContext responseContext) { - // return servletAccessor.getRequestServerName(requestContext.request()); - return null; + return accessor.getRequestServerName(requestContext.request()); } } diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java index ad40d42efdc9..0b1dab572367 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletNetAttributesExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; import io.opentelemetry.instrumentation.servlet.ServletAccessor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; public class ServletNetAttributesExtractor @@ -20,14 +21,12 @@ public ServletNetAttributesExtractor(ServletAccessor accessor @Override public @Nullable String transport(ServletRequestContext requestContext) { - // return SemanticAttributes.NetTransportValues.IP_TCP; - return null; + return SemanticAttributes.NetTransportValues.IP_TCP; } @Override public @Nullable String peerName(ServletRequestContext requestContext) { - // return accessor.getRequestRemoteHost(requestContext.request()); - return null; + return accessor.getRequestRemoteHost(requestContext.request()); } @Override diff --git a/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy b/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy index 93c24f4ed72a..b1665a6047ff 100644 --- a/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy +++ b/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP + import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.semconv.trace.attributes.SemanticAttributes @@ -55,6 +57,8 @@ class SparkJavaBasedTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String + "${SemanticAttributes.HTTP_SERVER_NAME}" String + "${SemanticAttributes.NET_TRANSPORT}" IP_TCP } } } diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy index da0924b599c7..f7d9d1f7b821 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy @@ -5,11 +5,13 @@ package test.boot +import io.opentelemetry.api.common.AttributeKey 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 io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import io.opentelemetry.testing.internal.armeria.common.HttpData import io.opentelemetry.testing.internal.armeria.common.MediaType @@ -51,6 +53,15 @@ class SpringBootBasedTest extends HttpServerTest return "/xyz" } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasHandlerSpan(ServerEndpoint endpoint) { true diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy index e6fcc2b4b08a..ceccaa1d70cf 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy @@ -5,10 +5,12 @@ package test.filter +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.sdk.trace.data.SpanData +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.springframework.boot.SpringApplication import org.springframework.context.ConfigurableApplicationContext import test.boot.SecurityConfig @@ -36,6 +38,15 @@ class ServletFilterTest extends HttpServerTest i ctx.close() } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasHandlerSpan(ServerEndpoint endpoint) { endpoint == NOT_FOUND diff --git a/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy b/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy index 7e1791c2c669..b05ea742db1c 100644 --- a/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy +++ b/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait @@ -28,6 +29,14 @@ import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEn class Struts2ActionSpanTest extends HttpServerTest implements AgentTestTrait { + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean testPathParam() { return true diff --git a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy index cb4986bc6176..cab0c2a390e0 100644 --- a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy +++ b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy @@ -5,9 +5,11 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0 +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.semconv.trace.attributes.SemanticAttributes import jakarta.servlet.Servlet import jakarta.servlet.ServletException import org.apache.catalina.Context @@ -97,6 +99,15 @@ class TomcatAsyncTest extends HttpServerTest implements AgentTestTrait { AsyncServlet } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean testException() { // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807 diff --git a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy index f8392155259b..4766b4ea4133 100644 --- a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy +++ b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy @@ -5,9 +5,11 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0 +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.semconv.trace.attributes.SemanticAttributes import org.apache.catalina.Context import org.apache.catalina.connector.Request import org.apache.catalina.connector.Response @@ -71,6 +73,15 @@ class TomcatHandlerTest extends HttpServerTest implements AgentTestTrait tomcat.getServer().stop() } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasResponseSpan(ServerEndpoint endpoint) { endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND diff --git a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy index 3a83c4ad2696..033678427cc1 100644 --- a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy +++ b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy @@ -5,9 +5,11 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0 +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.semconv.trace.attributes.SemanticAttributes import org.apache.catalina.Context import org.apache.catalina.startup.Tomcat import org.apache.tomcat.JarScanFilter @@ -97,6 +99,15 @@ class TomcatAsyncTest extends HttpServerTest implements AgentTestTrait { AsyncServlet } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean testException() { // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807 diff --git a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy index 073336a73a61..d7d9ce5fc04b 100644 --- a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy +++ b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy @@ -5,9 +5,11 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0 +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.semconv.trace.attributes.SemanticAttributes import org.apache.catalina.Context import org.apache.catalina.connector.Request import org.apache.catalina.connector.Response @@ -71,6 +73,15 @@ class TomcatHandlerTest extends HttpServerTest implements AgentTestTrait tomcat.getServer().stop() } + @Override + List> extraAttributes() { + [ + SemanticAttributes.HTTP_SERVER_NAME, + SemanticAttributes.NET_PEER_NAME, + SemanticAttributes.NET_TRANSPORT + ] + } + @Override boolean hasResponseSpan(ServerEndpoint endpoint) { endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesExtractor.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesExtractor.java index e29759a9e58f..5ee64e368113 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesExtractor.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatHttpAttributesExtractor.java @@ -44,11 +44,8 @@ protected List requestHeader(Request request, String name) { @Override protected @Nullable Long requestContentLength(Request request, @Nullable Response response) { - /* long contentLength = request.getContentLengthLong(); return contentLength != -1 ? contentLength : null; - */ - return null; } @Override @@ -76,11 +73,8 @@ protected List requestHeader(Request request, String name) { @Override protected @Nullable Long responseContentLength(Request request, Response response) { - /* long contentLength = response.getContentLengthLong(); return contentLength != -1 ? contentLength : null; - */ - return null; } @Override @@ -100,7 +94,6 @@ protected List responseHeader(Request request, Response response, String @Override protected @Nullable String serverName(Request request, @Nullable Response response) { - // return request.serverName().toString(); - return null; + return request.serverName().toString(); } } diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java index 366ea499083b..f598c661a695 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatNetAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.common; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.apache.coyote.ActionCode; import org.apache.coyote.Request; import org.apache.coyote.Response; @@ -15,17 +16,13 @@ public class TomcatNetAttributesExtractor extends NetServerAttributesExtractor extends InstrumentationSpecification imple false } + String peerIp(ServerEndpoint endpoint) { + "127.0.0.1" + } + boolean testNotFound() { true } @@ -602,7 +606,7 @@ abstract class HttpServerTest extends InstrumentationSpecification imple } attributes { "${SemanticAttributes.NET_PEER_PORT.key}" { it == null || it instanceof Long } - "${SemanticAttributes.NET_PEER_IP.key}" { it == null || it == "127.0.0.1" } // Optional + "${SemanticAttributes.NET_PEER_IP.key}" { it == null || it == peerIp(endpoint) } // Optional "${SemanticAttributes.HTTP_CLIENT_IP.key}" { it == null || it == TEST_CLIENT_IP } "${SemanticAttributes.HTTP_METHOD.key}" method "${SemanticAttributes.HTTP_STATUS_CODE.key}" endpoint.status @@ -620,9 +624,13 @@ abstract class HttpServerTest extends InstrumentationSpecification imple if (extraAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) { "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" Long + } else { + "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" { it == null || it instanceof Long } // Optional } if (extraAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) { "${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH}" Long + } else { + "${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH}" { it == null || it instanceof Long } // Optional } if (extraAttributes.contains(SemanticAttributes.HTTP_ROUTE)) { // TODO(anuraaga): Revisit this when applying instrumenters to more libraries, Armeria @@ -656,7 +664,7 @@ abstract class HttpServerTest extends InstrumentationSpecification imple childOf((SpanData) parent) attributes { "${SemanticAttributes.NET_PEER_PORT.key}" { it == null || it instanceof Long } - "${SemanticAttributes.NET_PEER_IP.key}" { it == null || it == "127.0.0.1" } // Optional + "${SemanticAttributes.NET_PEER_IP.key}" { it == null || it == peerIp(endpoint) } // Optional "${SemanticAttributes.HTTP_CLIENT_IP.key}" { it == null || it == TEST_CLIENT_IP } "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 @@ -674,9 +682,13 @@ abstract class HttpServerTest extends InstrumentationSpecification imple if (extraAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) { "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" Long + } else { + "${SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH}" { it == null || it instanceof Long } // Optional } if (extraAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) { "${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH}" Long + } else { + "${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH}" { it == null || it instanceof Long } // Optional } if (extraAttributes.contains(SemanticAttributes.HTTP_ROUTE)) { // TODO(anuraaga): Revisit this when applying instrumenters to more libraries, Armeria