From aa52e868347303ebb5a4df8d2227848eaf868b2b Mon Sep 17 00:00:00 2001 From: Shashank Patidar Date: Mon, 18 Mar 2024 16:40:15 +0530 Subject: [PATCH] spotless apply --- ...eAsyncClientInstrumentationModuleTest.java | 27 +++-- .../grpc/v1_6/GrpcInstrumentationTest.java | 39 +++--- ...tractNetty40ServerInstrumentationTest.java | 111 ++++++++++-------- .../NettyChannelPipelineInstrumentation.java | 9 +- .../HttpServerBlockingRequestHandler.java | 8 +- .../HttpServerRequestTracingHandler.java | 8 +- .../HttpServerResponseTracingHandler.java | 16 ++- ...tractNetty41ServerInstrumentationTest.java | 108 +++++++++-------- ...y41HttpServerCodecInstrumentationTest.java | 1 - .../Servlet30InstrumentationTest.java | 95 ++++++++------- .../reader/BufferedReaderInstrumentation.java | 3 +- .../v3_0/rw/ServletRWInstrumentationTest.java | 91 ++++++++------ .../src/test/java/rw/WrappingFilter.java | 2 - .../SparkJavaInstrumentationTest.java | 30 +++-- .../webflux/SpringWebfluxServerTest.java | 81 ++++++++----- .../struts/StrutsInstrumentationTest.java | 45 ++++--- .../v1_4/UndertowInstrumentationTest.java | 37 ++++-- .../vertx/ResponseBodyWrappingHandler.java | 4 +- .../vertx/VertxClientInstrumentationTest.java | 21 +++- .../vertx/VertxServerInstrumentationTest.java | 57 +++++---- .../agent/testing/AbstractHttpClientTest.java | 76 +++++------- .../testing/AbstractInstrumenterTest.java | 1 - .../agent/testing/TestOtlpReceiver.java | 25 ++-- .../mockfilter/MockFilterProvider.java | 4 +- 24 files changed, 515 insertions(+), 384 deletions(-) diff --git a/instrumentation/apache-httpasyncclient-4.1/src/test/java/io/opentelemetry/instrumentation/hypertrace/apachehttpasyncclient/ApacheAsyncClientInstrumentationModuleTest.java b/instrumentation/apache-httpasyncclient-4.1/src/test/java/io/opentelemetry/instrumentation/hypertrace/apachehttpasyncclient/ApacheAsyncClientInstrumentationModuleTest.java index a9df1de8..07b78454 100644 --- a/instrumentation/apache-httpasyncclient-4.1/src/test/java/io/opentelemetry/instrumentation/hypertrace/apachehttpasyncclient/ApacheAsyncClientInstrumentationModuleTest.java +++ b/instrumentation/apache-httpasyncclient-4.1/src/test/java/io/opentelemetry/instrumentation/hypertrace/apachehttpasyncclient/ApacheAsyncClientInstrumentationModuleTest.java @@ -16,6 +16,7 @@ package io.opentelemetry.instrumentation.hypertrace.apachehttpasyncclient; +import io.opentelemetry.proto.trace.v1.Span; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -29,8 +30,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; - -import io.opentelemetry.proto.trace.v1.Span; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -83,7 +82,8 @@ public void getJson() TEST_WRITER.waitForTraces(1); // exclude server spans - List> traces = TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + List> traces = + TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(2, traces.get(0).size()); Span clientSpan = traces.get(0).get(1); @@ -95,13 +95,14 @@ public void getJson() Assertions.assertEquals( "test-value", - TEST_WRITER.getAttributesMap(clientSpan) - .get("http.response.header.test-response-header").getStringValue()); + TEST_WRITER + .getAttributesMap(clientSpan) + .get("http.response.header.test-response-header") + .getStringValue()); Assertions.assertEquals( "bar", TEST_WRITER.getAttributesMap(clientSpan).get("http.request.header.foo").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body")); Assertions.assertEquals( GetJsonHandler.RESPONSE_BODY, @@ -138,7 +139,8 @@ public void postJsonEntity(HttpEntity entity) TEST_WRITER.waitForTraces(1); // exclude server spans - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(1, traces.get(0).size()); Span clientSpan = traces.get(0).get(0); @@ -146,13 +148,14 @@ public void postJsonEntity(HttpEntity entity) String requestBody = readInputStream(entity.getContent()); Assertions.assertEquals( "test-value", - TEST_WRITER.getAttributesMap(clientSpan) - .get("http.response.header.test-response-header").getStringValue()); + TEST_WRITER + .getAttributesMap(clientSpan) + .get("http.response.header.test-response-header") + .getStringValue()); Assertions.assertEquals( requestBody, TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(clientSpan).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(clientSpan).get("http.response.body")); } private static String readInputStream(InputStream inputStream) throws IOException { diff --git a/instrumentation/grpc-1.6/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcInstrumentationTest.java b/instrumentation/grpc-1.6/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcInstrumentationTest.java index c888e6d6..347c09a9 100644 --- a/instrumentation/grpc-1.6/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcInstrumentationTest.java +++ b/instrumentation/grpc-1.6/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/GrpcInstrumentationTest.java @@ -29,11 +29,10 @@ import io.grpc.Status; import io.grpc.StatusRuntimeException; import io.grpc.stub.MetadataUtils; +import io.opentelemetry.proto.trace.v1.Span; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeoutException; - -import io.opentelemetry.proto.trace.v1.Span; import org.hypertrace.agent.testing.AbstractInstrumenterTest; import org.hypertrace.example.GreeterGrpc; import org.hypertrace.example.GreeterGrpc.GreeterBlockingStub; @@ -162,14 +161,14 @@ public void serverRequestBlocking() throws TimeoutException, InterruptedExceptio if (spans.get(0).getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)) { serverSpan = spans.get(0); } - Assertions.assertNull( - TEST_WRITER.getAttributesMap(serverSpan).get("rpc.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(serverSpan).get("rpc.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(serverSpan).get("rpc.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(serverSpan).get("rpc.response.body")); Assertions.assertEquals( "true", - TEST_WRITER.getAttributesMap(serverSpan) - .get("rpc.request.metadata.mockblock").getStringValue()); + TEST_WRITER + .getAttributesMap(serverSpan) + .get("rpc.request.metadata.mockblock") + .getStringValue()); assertHttp2HeadersForSayHelloMethod(serverSpan); } @@ -180,30 +179,30 @@ private void assertBodiesAndHeaders(Span span, String requestJson, String respon responseJson, TEST_WRITER.getAttributesMap(span).get("rpc.response.body").getStringValue()); Assertions.assertEquals( "clientheader", - TEST_WRITER.getAttributesMap(span) - .get("rpc.request.metadata." + CLIENT_STRING_METADATA_KEY.name()).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("rpc.request.metadata." + CLIENT_STRING_METADATA_KEY.name()) + .getStringValue()); Assertions.assertEquals( "serverheader", - TEST_WRITER.getAttributesMap(span) - .get("rpc.response.metadata." + SERVER_STRING_METADATA_KEY.name()).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("rpc.response.metadata." + SERVER_STRING_METADATA_KEY.name()) + .getStringValue()); } private void assertHttp2HeadersForSayHelloMethod(Span span) { Assertions.assertEquals( "http", - TEST_WRITER.getAttributesMap(span) - .get("rpc.request.metadata.:scheme").getStringValue()); + TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:scheme").getStringValue()); Assertions.assertEquals( "POST", - TEST_WRITER.getAttributesMap(span) - .get("rpc.request.metadata.:method").getStringValue()); + TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:method").getStringValue()); Assertions.assertEquals( String.format("localhost:%d", SERVER.getPort()), - TEST_WRITER.getAttributesMap(span) - .get("rpc.request.metadata.:authority").getStringValue()); + TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:authority").getStringValue()); Assertions.assertEquals( "/org.hypertrace.example.Greeter/SayHello", - TEST_WRITER.getAttributesMap(span) - .get("rpc.request.metadata.:path").getStringValue()); + TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:path").getStringValue()); } } diff --git a/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java b/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java index 3adcf891..c5800d41 100644 --- a/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java +++ b/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java @@ -20,12 +20,11 @@ import static io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_0.server.NettyTestServer.RESPONSE_HEADER_NAME; import static io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_0.server.NettyTestServer.RESPONSE_HEADER_VALUE; +import io.opentelemetry.proto.trace.v1.Span; import java.io.IOException; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; - -import io.opentelemetry.proto.trace.v1.Span; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -71,7 +70,8 @@ public void get() throws IOException, TimeoutException, InterruptedException { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -79,16 +79,18 @@ public void get() throws IOException, TimeoutException, InterruptedException { Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER_NAME) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -108,7 +110,8 @@ public void postJson() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -116,12 +119,16 @@ public void postJson() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER_NAME) + .getStringValue()); Buffer requestBodyBuffer = new Buffer(); requestBody.writeTo(requestBodyBuffer); Assertions.assertEquals( @@ -148,7 +155,8 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -156,13 +164,13 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME)); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER.getAttributesMap(span).get("http.response.header." + RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); RequestBody requestBody = blockedRequestBody(true, 3000, 75); Request request2 = @@ -178,7 +186,9 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(2); - List> traces2 = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces2 = + TEST_WRITER.waitForSpans( + 2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(2, traces2.size()); List trace2 = traces2.get(1); Assertions.assertEquals(1, trace2.size()); @@ -186,13 +196,13 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span2) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2) - .get("http.response.header." + RESPONSE_HEADER_NAME)); + TEST_WRITER + .getAttributesMap(span2) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2).get("http.response.body")); + TEST_WRITER.getAttributesMap(span2).get("http.response.header." + RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.response.body")); } @Test @@ -212,7 +222,8 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -220,8 +231,10 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( "1st", TEST_WRITER.getAttributesMap(span).get("http.request.header.first").getStringValue()); @@ -230,10 +243,11 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup TEST_WRITER.getAttributesMap(span).get("http.request.header.connection").getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER_NAME) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); Assertions.assertEquals( RESPONSE_BODY, TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue()); @@ -254,7 +268,9 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup } TEST_WRITER.waitForTraces(2); - List> traces2 = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces2 = + TEST_WRITER.waitForSpans( + 2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(2, traces2.size()); List trace2 = traces2.get(1); Assertions.assertEquals(1, trace2.size()); @@ -262,22 +278,19 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup Assertions.assertEquals( "REQUEST_HEADER_VALUE", - TEST_WRITER.getAttributesMap(span2) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span2) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( "2nd", TEST_WRITER.getAttributesMap(span2).get("http.request.header.second").getStringValue()); Assertions.assertEquals( "keep-alive", - TEST_WRITER.getAttributesMap(span2) - .get("http.request.header.connection").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2).get("http.request.header.first")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2) - .get("http.response.header." + RESPONSE_HEADER_NAME)); + TEST_WRITER.getAttributesMap(span2).get("http.request.header.connection").getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.request.header.first")); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2) - .get("http.response.body")); + TEST_WRITER.getAttributesMap(span2).get("http.response.header." + RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.response.body")); } } diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/NettyChannelPipelineInstrumentation.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/NettyChannelPipelineInstrumentation.java index 97b10fd4..1e55f9a3 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/NettyChannelPipelineInstrumentation.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/NettyChannelPipelineInstrumentation.java @@ -39,7 +39,6 @@ import io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_1.server.HttpServerBlockingRequestHandler; import io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_1.server.HttpServerRequestTracingHandler; import io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_1.server.HttpServerResponseTracingHandler; -import io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_1.server.HttpServerTracingHandler; import io.opentelemetry.javaagent.instrumentation.netty.v4_1.NettyClientSingletons; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -102,14 +101,14 @@ public static void addHandler( if (handler instanceof HttpServerCodec) { pipeline.addLast( - HttpServerRequestTracingHandler.class.getName(), - new HttpServerRequestTracingHandler()); + HttpServerRequestTracingHandler.class.getName(), + new HttpServerRequestTracingHandler()); pipeline.addLast( HttpServerBlockingRequestHandler.class.getName(), new HttpServerBlockingRequestHandler()); pipeline.addLast( - HttpServerResponseTracingHandler.class.getName(), - new HttpServerResponseTracingHandler()); + HttpServerResponseTracingHandler.class.getName(), + new HttpServerResponseTracingHandler()); } else if (handler instanceof HttpRequestDecoder) { pipeline.addLast( HttpServerRequestTracingHandler.class.getName(), diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerBlockingRequestHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerBlockingRequestHandler.java index 7ef34cc0..33a1351c 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerBlockingRequestHandler.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerBlockingRequestHandler.java @@ -42,11 +42,9 @@ public class HttpServerBlockingRequestHandler extends ChannelInboundHandlerAdapt public void channelRead(ChannelHandlerContext ctx, Object msg) { Channel channel = ctx.channel(); Deque serverContexts = - channel - .attr( - io.opentelemetry.instrumentation.netty.v4_1.internal.AttributeKeys - .SERVER_CONTEXT) - .get(); + channel + .attr(io.opentelemetry.instrumentation.netty.v4_1.internal.AttributeKeys.SERVER_CONTEXT) + .get(); if (serverContexts == null || serverContexts.isEmpty()) { ctx.fireChannelRead(msg); return; diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java index 32970b94..9cc9c7c1 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java @@ -50,11 +50,9 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte public void channelRead(ChannelHandlerContext ctx, Object msg) { Channel channel = ctx.channel(); Deque serverContexts = - channel - .attr( - io.opentelemetry.instrumentation.netty.v4_1.internal.AttributeKeys - .SERVER_CONTEXT) - .get(); + channel + .attr(io.opentelemetry.instrumentation.netty.v4_1.internal.AttributeKeys.SERVER_CONTEXT) + .get(); if (serverContexts == null || serverContexts.isEmpty()) { ctx.fireChannelRead(msg); return; diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java index 9f32bb52..c68dacf8 100644 --- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java +++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java @@ -51,11 +51,10 @@ public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdap @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) { - Deque serverContexts = ctx.channel() - .attr( - io.opentelemetry.instrumentation.netty.v4_1.internal.AttributeKeys - .SERVER_CONTEXT) - .get(); + Deque serverContexts = + ctx.channel() + .attr(io.opentelemetry.instrumentation.netty.v4_1.internal.AttributeKeys.SERVER_CONTEXT) + .get(); if (serverContexts == null || serverContexts.isEmpty()) { ctx.write(msg, prm); return; @@ -95,7 +94,12 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) { try (Scope ignored = serverContexts.element().context().makeCurrent()) { ctx.write(msg, prm); } catch (Throwable throwable) { - NettyServerSingletons.instrumenter().end(serverContexts.element().context(), serverContexts.element().request(), null, throwable); + NettyServerSingletons.instrumenter() + .end( + serverContexts.element().context(), + serverContexts.element().request(), + null, + throwable); throw throwable; } if (msg instanceof HttpResponse) { diff --git a/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java b/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java index ba586518..597709e2 100644 --- a/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java +++ b/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java @@ -70,7 +70,8 @@ public void get() throws IOException, TimeoutException, InterruptedException { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -78,16 +79,18 @@ public void get() throws IOException, TimeoutException, InterruptedException { Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER_NAME) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -107,7 +110,8 @@ public void postJson() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -115,12 +119,16 @@ public void postJson() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER_NAME) + .getStringValue()); Buffer requestBodyBuffer = new Buffer(); requestBody.writeTo(requestBodyBuffer); Assertions.assertEquals( @@ -147,7 +155,8 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -155,13 +164,13 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME)); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER.getAttributesMap(span).get("http.response.header." + RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); RequestBody requestBody = blockedRequestBody(true, 3000, 75); Request request2 = @@ -177,7 +186,9 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(2); - List> traces2 = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces2 = + TEST_WRITER.waitForSpans( + 2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(2, traces2.size()); List trace2 = traces2.get(1); Assertions.assertEquals(1, trace2.size()); @@ -185,13 +196,13 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span2) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2) - .get("http.response.header." + RESPONSE_HEADER_NAME)); + TEST_WRITER + .getAttributesMap(span2) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2).get("http.response.body")); + TEST_WRITER.getAttributesMap(span2).get("http.response.header." + RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.response.body")); } @Test @@ -211,7 +222,8 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -219,8 +231,10 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( "1st", TEST_WRITER.getAttributesMap(span).get("http.request.header.first").getStringValue()); @@ -229,10 +243,11 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup TEST_WRITER.getAttributesMap(span).get("http.request.header.connection").getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER_NAME) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); Assertions.assertEquals( RESPONSE_BODY, TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue()); @@ -253,7 +268,9 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup } TEST_WRITER.waitForTraces(2); - List> traces2 = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces2 = + TEST_WRITER.waitForSpans( + 2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(2, traces2.size()); List trace2 = traces2.get(1); Assertions.assertEquals(1, trace2.size()); @@ -261,22 +278,19 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup Assertions.assertEquals( "REQUEST_HEADER_VALUE", - TEST_WRITER.getAttributesMap(span2) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span2) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( "2nd", TEST_WRITER.getAttributesMap(span2).get("http.request.header.second").getStringValue()); Assertions.assertEquals( "keep-alive", - TEST_WRITER.getAttributesMap(span2) - .get("http.request.header.connection").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2).get("http.request.header.first")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2) - .get("http.response.header." + RESPONSE_HEADER_NAME)); + TEST_WRITER.getAttributesMap(span2).get("http.request.header.connection").getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.request.header.first")); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span2) - .get("http.response.body")); + TEST_WRITER.getAttributesMap(span2).get("http.response.header." + RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.response.body")); } } diff --git a/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/Netty41HttpServerCodecInstrumentationTest.java b/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/Netty41HttpServerCodecInstrumentationTest.java index a9e89f7c..4636fdac 100644 --- a/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/Netty41HttpServerCodecInstrumentationTest.java +++ b/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/Netty41HttpServerCodecInstrumentationTest.java @@ -17,7 +17,6 @@ package io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_1.server; import io.netty.handler.codec.http.HttpServerCodec; -import java.util.Arrays; import java.util.Collections; public class Netty41HttpServerCodecInstrumentationTest diff --git a/instrumentation/servlet/servlet-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30InstrumentationTest.java b/instrumentation/servlet/servlet-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30InstrumentationTest.java index 75f3598d..0a50a495 100644 --- a/instrumentation/servlet/servlet-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30InstrumentationTest.java +++ b/instrumentation/servlet/servlet-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30InstrumentationTest.java @@ -30,6 +30,13 @@ import java.io.IOException; import java.util.EnumSet; import java.util.List; +import javax.servlet.DispatcherType; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.Request; @@ -43,13 +50,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import javax.servlet.DispatcherType; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; public class Servlet30InstrumentationTest extends AbstractInstrumenterTest { private static final String REQUEST_BODY = "hello"; @@ -215,19 +215,24 @@ public void portUrlEncoded() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( TestServlets.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + TestServlets.RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + TestServlets.RESPONSE_HEADER) + .getStringValue()); Assertions.assertEquals( "key1=value1&key2=value2", TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); @@ -249,23 +254,26 @@ public void getHello() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( TestServlets.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + TestServlets.RESPONSE_HEADER).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + TestServlets.RESPONSE_HEADER) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -282,18 +290,18 @@ public void block() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) + TEST_WRITER + .getAttributesMap(span) .get("http.response.header." + TestServlets.RESPONSE_HEADER)); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -311,18 +319,19 @@ public void blockBody() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) + TEST_WRITER + .getAttributesMap(span) .get("http.response.header." + TestServlets.RESPONSE_HEADER)); Assertions.assertEquals( "block=true", TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -340,18 +349,19 @@ public void blockBodyWrappedException() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) + TEST_WRITER + .getAttributesMap(span) .get("http.response.header." + TestServlets.RESPONSE_HEADER)); Assertions.assertEquals( "block=true", TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } public void postJson(String url) throws Exception { @@ -367,19 +377,24 @@ public void postJson(String url) throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( TestServlets.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + TestServlets.RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + TestServlets.RESPONSE_HEADER) + .getStringValue()); Assertions.assertEquals( REQUEST_BODY, TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); Assertions.assertEquals( diff --git a/instrumentation/servlet/servlet-rw/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/rw/reader/BufferedReaderInstrumentation.java b/instrumentation/servlet/servlet-rw/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/rw/reader/BufferedReaderInstrumentation.java index b260fdbb..121e4fee 100644 --- a/instrumentation/servlet/servlet-rw/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/rw/reader/BufferedReaderInstrumentation.java +++ b/instrumentation/servlet/servlet-rw/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/rw/reader/BufferedReaderInstrumentation.java @@ -210,7 +210,8 @@ public static CharBufferSpanPair enter(@Advice.This BufferedReader thizz) { @Advice.OnMethodExit(onThrowable = Throwable.class) public static void exit( - @Advice.Return String line, @Advice.Enter CharBufferSpanPair bufferSpanPair) throws IOException { + @Advice.Return String line, @Advice.Enter CharBufferSpanPair bufferSpanPair) + throws IOException { try { if (bufferSpanPair == null) { return; diff --git a/instrumentation/servlet/servlet-rw/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/rw/ServletRWInstrumentationTest.java b/instrumentation/servlet/servlet-rw/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/rw/ServletRWInstrumentationTest.java index 6b69f6d4..8adf756b 100644 --- a/instrumentation/servlet/servlet-rw/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/rw/ServletRWInstrumentationTest.java +++ b/instrumentation/servlet/servlet-rw/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/rw/ServletRWInstrumentationTest.java @@ -19,12 +19,12 @@ import io.opentelemetry.proto.trace.v1.Span; import java.util.EnumSet; import java.util.List; +import javax.servlet.DispatcherType; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -import rw.WrappingFilter; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.hypertrace.agent.testing.AbstractInstrumenterTest; @@ -32,7 +32,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import javax.servlet.DispatcherType; +import rw.WrappingFilter; public class ServletRWInstrumentationTest extends AbstractInstrumenterTest { private static final String REQUEST_BODY = "hello"; @@ -59,8 +59,10 @@ public static void startServer() throws Exception { handler.addServlet( TestServlets.EchoWriter_readLine_print_arr.class, "/echo_writer_readLine_print_arr"); handler.addServlet(TestServlets.EchoAsyncResponse_writer.class, "/echo_async_response_writer"); - handler.addServlet(TestServlets.EchoStream_read_large_array.class, "/echo_stream_read_large_array"); - handler.addServlet(TestServlets.EchoReader_read_large_array.class, "/echo_reader_read_large_array"); + handler.addServlet( + TestServlets.EchoStream_read_large_array.class, "/echo_stream_read_large_array"); + handler.addServlet( + TestServlets.EchoReader_read_large_array.class, "/echo_reader_read_large_array"); server.setHandler(handler); server.start(); serverPort = server.getConnectors()[0].getLocalPort(); @@ -135,19 +137,24 @@ public void portUrlEncoded() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( TestServlets.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + TestServlets.RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + TestServlets.RESPONSE_HEADER) + .getStringValue()); Assertions.assertEquals( "key1=value1&key2=value2", TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); @@ -169,23 +176,26 @@ public void getHello() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( TestServlets.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + TestServlets.RESPONSE_HEADER).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + TestServlets.RESPONSE_HEADER) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -202,18 +212,18 @@ public void block() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) + TEST_WRITER + .getAttributesMap(span) .get("http.response.header." + TestServlets.RESPONSE_HEADER)); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -231,18 +241,19 @@ public void blockBody() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) + TEST_WRITER + .getAttributesMap(span) .get("http.response.header." + TestServlets.RESPONSE_HEADER)); Assertions.assertEquals( "block=true", TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -260,18 +271,19 @@ public void blockBodyWrappedException() throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) + TEST_WRITER + .getAttributesMap(span) .get("http.response.header." + TestServlets.RESPONSE_HEADER)); Assertions.assertEquals( "block=true", TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } public void postJson(String url) throws Exception { @@ -287,19 +299,24 @@ public void postJson(String url) throws Exception { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( TestServlets.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + TestServlets.RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + TestServlets.RESPONSE_HEADER) + .getStringValue()); Assertions.assertEquals( REQUEST_BODY, TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); Assertions.assertEquals( diff --git a/instrumentation/servlet/servlet-rw/src/test/java/rw/WrappingFilter.java b/instrumentation/servlet/servlet-rw/src/test/java/rw/WrappingFilter.java index 7dafe90f..b5452e59 100644 --- a/instrumentation/servlet/servlet-rw/src/test/java/rw/WrappingFilter.java +++ b/instrumentation/servlet/servlet-rw/src/test/java/rw/WrappingFilter.java @@ -23,8 +23,6 @@ import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; diff --git a/instrumentation/spark-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/sparkjava/SparkJavaInstrumentationTest.java b/instrumentation/spark-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/sparkjava/SparkJavaInstrumentationTest.java index c6d5d70a..562707cd 100644 --- a/instrumentation/spark-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/sparkjava/SparkJavaInstrumentationTest.java +++ b/instrumentation/spark-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/sparkjava/SparkJavaInstrumentationTest.java @@ -84,7 +84,8 @@ public void postRequest() throws IOException, InterruptedException, TimeoutExcep } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); @@ -93,16 +94,20 @@ public void postRequest() throws IOException, InterruptedException, TimeoutExcep REQUEST_BODY, TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( RESPONSE_BODY, TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER) + .getStringValue()); } @Test @@ -116,22 +121,27 @@ public void exceptionInHandler() throws IOException, InterruptedException, Timeo try (Response response = httpClient.newCall(request).execute()) {} TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); Assertions.assertEquals( "

500 Internal Error

", TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue()); Assertions.assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER) + .getStringValue()); } } diff --git a/instrumentation/spring/spring-webflux-5.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/spring/webflux/SpringWebfluxServerTest.java b/instrumentation/spring/spring-webflux-5.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/spring/webflux/SpringWebfluxServerTest.java index 9c493823..f4b93006 100644 --- a/instrumentation/spring/spring-webflux-5.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/spring/webflux/SpringWebfluxServerTest.java +++ b/instrumentation/spring/spring-webflux-5.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/spring/webflux/SpringWebfluxServerTest.java @@ -18,11 +18,10 @@ import io.opentelemetry.javaagent.instrumentation.hypertrace.spring.webflux.SpringWebFluxTestApplication.GreetingHandler; import io.opentelemetry.javaagent.instrumentation.hypertrace.spring.webflux.SpringWebfluxServerTest.ForceNettyAutoConfiguration; +import io.opentelemetry.proto.trace.v1.Span; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeoutException; - -import io.opentelemetry.proto.trace.v1.Span; import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; @@ -73,7 +72,12 @@ public void get() throws IOException, TimeoutException, InterruptedException { Assertions.assertEquals(200, response.code()); } - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); TEST_WRITER.waitForTraces(1); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); @@ -82,17 +86,18 @@ public void get() throws IOException, TimeoutException, InterruptedException { Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( SpringWebFluxTestApplication.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + SpringWebFluxTestApplication.RESPONSE_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + SpringWebFluxTestApplication.RESPONSE_HEADER_NAME) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } @Test @@ -121,7 +126,12 @@ public void getStream() throws IOException, TimeoutException, InterruptedExcepti Assertions.assertEquals(responseBodyStr.toString(), response.body().string()); } - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); TEST_WRITER.waitForTraces(1); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); @@ -146,7 +156,12 @@ public void post() throws IOException, TimeoutException, InterruptedException { Assertions.assertEquals(REQUEST_BODY, response.body().string()); } - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); TEST_WRITER.waitForTraces(1); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); @@ -155,13 +170,16 @@ public void post() throws IOException, TimeoutException, InterruptedException { Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( SpringWebFluxTestApplication.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + SpringWebFluxTestApplication.RESPONSE_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + SpringWebFluxTestApplication.RESPONSE_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( REQUEST_BODY, TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); Assertions.assertEquals( @@ -184,7 +202,12 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals("Hypertrace Blocked Request", response.body().string()); } - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); TEST_WRITER.waitForTraces(1); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); @@ -193,15 +216,17 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + SpringWebFluxTestApplication.RESPONSE_HEADER_NAME)); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + SpringWebFluxTestApplication.RESPONSE_HEADER_NAME)); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + GreetingHandler.DEFAULT_RESPONSE)); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + GreetingHandler.DEFAULT_RESPONSE)); } } diff --git a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java index 6c67cc60..8365e41f 100644 --- a/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java +++ b/instrumentation/struts-2.3/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/struts/StrutsInstrumentationTest.java @@ -18,13 +18,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import io.opentelemetry.proto.trace.v1.Span; import java.io.IOException; import java.util.EnumSet; import java.util.List; import java.util.concurrent.TimeoutException; import javax.servlet.DispatcherType; - -import io.opentelemetry.proto.trace.v1.Span; import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; @@ -84,7 +83,12 @@ public void postUrlEncoded() throws IOException, TimeoutException, InterruptedEx } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); assertEquals(1, traces.size()); List spans = traces.get(0); assertEquals(1, spans.size()); @@ -109,19 +113,28 @@ public void getHeaders() throws IOException, TimeoutException, InterruptedExcept } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); assertEquals(1, traces.size()); List spans = traces.get(0); assertEquals(1, spans.size()); Span span = spans.get(0); assertEquals( RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + RESPONSE_HEADER) + .getStringValue()); assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER) + .getStringValue()); } @Test @@ -137,17 +150,19 @@ public void block() throws IOException, TimeoutException, InterruptedException { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(1, traces.size()); List spans = traces.get(0); Assertions.assertEquals(1, spans.size()); Span span = spans.get(0); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get("http.response.header." + RESPONSE_HEADER)); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER.getAttributesMap(span).get("http.response.header." + RESPONSE_HEADER)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } } diff --git a/instrumentation/undertow/undertow-1.4/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/undertow/v1_4/UndertowInstrumentationTest.java b/instrumentation/undertow/undertow-1.4/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/undertow/v1_4/UndertowInstrumentationTest.java index d4bc5fab..bcaeb3af 100644 --- a/instrumentation/undertow/undertow-1.4/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/undertow/v1_4/UndertowInstrumentationTest.java +++ b/instrumentation/undertow/undertow-1.4/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/undertow/v1_4/UndertowInstrumentationTest.java @@ -108,7 +108,12 @@ void postUrlEncoded() throws InterruptedException, TimeoutException, IOException } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -134,17 +139,22 @@ void postUrlEncoded() throws InterruptedException, TimeoutException, IOException } TEST_WRITER.waitForTraces(2); - List> putTraces = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span1.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> putTraces = + TEST_WRITER.waitForSpans( + 2, + span1 -> + span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span1.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(2, putTraces.size()); List putTrace = putTraces.get(1); Assertions.assertEquals(1, putTrace.size()); Span putSpan = putTrace.get(0); assertEquals( "echo=bar&append=true", - TEST_WRITER.getAttributesMap(putSpan).get("http.response.body").getStringValue()); + TEST_WRITER.getAttributesMap(putSpan).get("http.response.body").getStringValue()); assertEquals( requestBody, - TEST_WRITER.getAttributesMap(putSpan).get("http.request.body").getStringValue()); + TEST_WRITER.getAttributesMap(putSpan).get("http.request.body").getStringValue()); // make a third request to an endpoint that should return JSON try (Response response = @@ -159,14 +169,19 @@ void postUrlEncoded() throws InterruptedException, TimeoutException, IOException } TEST_WRITER.waitForTraces(3); - final List> getJsonTraces = TEST_WRITER.waitForSpans(3, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span1.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + final List> getJsonTraces = + TEST_WRITER.waitForSpans( + 3, + span1 -> + span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span1.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(3, getJsonTraces.size()); final List getJsonTrace = getJsonTraces.get(2); Assertions.assertEquals(1, getJsonTrace.size()); final Span getJsonSpan = getJsonTrace.get(0); assertEquals( "{\"message\": \"Hello World\"}", - TEST_WRITER.getAttributesMap(getJsonSpan).get("http.response.body").getStringValue()); + TEST_WRITER.getAttributesMap(getJsonSpan).get("http.response.body").getStringValue()); // empty request body should not be captured assertNull(TEST_WRITER.getAttributesMap(getJsonSpan).get("http.request.body")); @@ -180,14 +195,18 @@ void postUrlEncoded() throws InterruptedException, TimeoutException, IOException } TEST_WRITER.waitForTraces(4); - final List> getHtmlTraces = TEST_WRITER.waitForSpans(4, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) || span1.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + final List> getHtmlTraces = + TEST_WRITER.waitForSpans( + 4, + span1 -> + span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span1.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(4, getHtmlTraces.size()); final List getHtmlTrace = getHtmlTraces.get(3); Assertions.assertEquals(1, getHtmlTrace.size()); final Span getHtmlSpan = getHtmlTrace.get(0); // HTML body should not be captured - assertNull( - TEST_WRITER.getAttributesMap(getHtmlSpan).get("http.response.body")); + assertNull(TEST_WRITER.getAttributesMap(getHtmlSpan).get("http.response.body")); // request body should not be captured assertNull(TEST_WRITER.getAttributesMap(getHtmlSpan).get("http.request.body")); } diff --git a/instrumentation/vertx/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/ResponseBodyWrappingHandler.java b/instrumentation/vertx/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/ResponseBodyWrappingHandler.java index 33996e83..2ee406c0 100644 --- a/instrumentation/vertx/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/ResponseBodyWrappingHandler.java +++ b/instrumentation/vertx/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/ResponseBodyWrappingHandler.java @@ -63,9 +63,7 @@ public void handle(Buffer event) { // Also add content type if present if (shouldCallGetAttribute && getAttribute == null) { try { - getAttribute = - span.getClass() - .getDeclaredMethod("getAttribute", AttributeKey.class); + getAttribute = span.getClass().getDeclaredMethod("getAttribute", AttributeKey.class); } catch (NoSuchMethodException e) { log.error("getAttribute method not found in SdkSpan class", e); } diff --git a/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxClientInstrumentationTest.java b/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxClientInstrumentationTest.java index 469e6c83..c760cbad 100644 --- a/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxClientInstrumentationTest.java +++ b/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxClientInstrumentationTest.java @@ -140,7 +140,12 @@ public void postJson_write_end() throws TimeoutException, InterruptedException { countDownLatch.await(); TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(1, traces.size()); Span clientSpan = traces.get(0).get(0); Assertions.assertEquals( @@ -168,7 +173,12 @@ public void postJson_write_end_string() throws TimeoutException, InterruptedExce countDownLatch.await(); TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(1, traces.size(), String.format("was: %d", traces.size())); Span clientSpan = traces.get(0).get(0); Assertions.assertEquals( @@ -196,7 +206,12 @@ public void postJson_write_end_buffer() throws TimeoutException, InterruptedExce countDownLatch.await(); TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER) || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); + List> traces = + TEST_WRITER.waitForSpans( + 1, + span -> + span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER) + || span.getKind().equals(Span.SpanKind.SPAN_KIND_INTERNAL)); Assertions.assertEquals(1, traces.size(), String.format("was: %d", traces.size())); Span clientSpan = traces.get(0).get(0); Assertions.assertEquals( diff --git a/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxServerInstrumentationTest.java b/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxServerInstrumentationTest.java index 4ec0d3e8..7f33390b 100644 --- a/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxServerInstrumentationTest.java +++ b/instrumentation/vertx/vertx-web-3.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/VertxServerInstrumentationTest.java @@ -108,24 +108,26 @@ public void get() throws IOException, TimeoutException, InterruptedException { } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); Span span = trace.get(0); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span).get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); Assertions.assertEquals( VertxWebServer.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + VertxWebServer.RESPONSE_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + VertxWebServer.RESPONSE_HEADER_NAME) + .getStringValue()); } @Test @@ -144,7 +146,8 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio } TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); Assertions.assertEquals(1, trace.size()); @@ -152,15 +155,15 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); - Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + VertxWebServer.RESPONSE_HEADER_NAME)); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertNull( - TEST_WRITER.getAttributesMap(span) - .get("http.response.body")); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + VertxWebServer.RESPONSE_HEADER_NAME)); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); } public void postJson(String url) throws IOException, TimeoutException, InterruptedException { @@ -175,7 +178,8 @@ public void postJson(String url) throws IOException, TimeoutException, Interrupt Assertions.assertEquals(VertxWebServer.RESPONSE_BODY, response.body().string()); } - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT)); TEST_WRITER.waitForTraces(1); Assertions.assertEquals(1, traces.size()); List trace = traces.get(0); @@ -185,15 +189,18 @@ public void postJson(String url) throws IOException, TimeoutException, Interrupt REQUEST_BODY, TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); Assertions.assertEquals( REQUEST_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get("http.request.header." + REQUEST_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.request.header." + REQUEST_HEADER_NAME) + .getStringValue()); Assertions.assertEquals( VertxWebServer.RESPONSE_BODY, TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue()); Assertions.assertEquals( VertxWebServer.RESPONSE_HEADER_VALUE, - TEST_WRITER.getAttributesMap(span) - .get( - "http.response.header." + VertxWebServer.RESPONSE_HEADER_NAME).getStringValue()); + TEST_WRITER + .getAttributesMap(span) + .get("http.response.header." + VertxWebServer.RESPONSE_HEADER_NAME) + .getStringValue()); } } diff --git a/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java b/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java index 32e024c9..1c04c0cf 100644 --- a/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java @@ -106,10 +106,14 @@ public void postJson_echo() List> traces; if (hasResponseBodySpan) { // exclude server spans - traces = TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + traces = + TEST_WRITER.waitForSpans( + 2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); } else { // exclude server spans - traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + traces = + TEST_WRITER.waitForSpans( + 1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); } Assertions.assertEquals(1, traces.size()); Span clientSpan = traces.get(0).get(0); @@ -144,9 +148,13 @@ public void postUrlEncoded_echo() TEST_WRITER.waitForTraces(1); List> traces; if (hasResponseBodySpan) { - traces = TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + traces = + TEST_WRITER.waitForSpans( + 2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); } else { - traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + traces = + TEST_WRITER.waitForSpans( + 1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); } Assertions.assertEquals(1, traces.size()); Span clientSpan = traces.get(0).get(0); @@ -177,7 +185,8 @@ public void postPlainText_echo() Assertions.assertEquals(body, response.body); TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(1, traces.get(0).size()); Span clientSpan = traces.get(0).get(0); @@ -197,7 +206,8 @@ public void getNoContent() Assertions.assertNull(response.body); TEST_WRITER.waitForTraces(1); - List> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + List> traces = + TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(1, traces.get(0).size()); Span clientSpan = traces.get(0).get(0); @@ -219,9 +229,13 @@ public void getJson() TEST_WRITER.waitForTraces(1); List> traces; if (hasResponseBodySpan) { - traces = TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + traces = + TEST_WRITER.waitForSpans( + 2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); } else { - traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + traces = + TEST_WRITER.waitForSpans( + 1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); } Assertions.assertEquals(1, traces.size()); @@ -233,10 +247,7 @@ public void getJson() clientSpan = traces.get(0).get(1); responseBodySpan = traces.get(0).get(0); } - Assertions.assertNull( - TEST_WRITER - .getAttributesMap(clientSpan) - .get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body")); Assertions.assertEquals( TestHttpServer.GetJsonHandler.RESPONSE_BODY, @@ -245,18 +256,12 @@ public void getJson() .get("http.response.body") .getStringValue()); } else { - Assertions.assertNull( - TEST_WRITER - .getAttributesMap(clientSpan) - .get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body")); Assertions.assertEquals(1, traces.get(0).size()); Assertions.assertEquals( TestHttpServer.GetJsonHandler.RESPONSE_BODY, - TEST_WRITER - .getAttributesMap(clientSpan) - .get("http.response.body") - .getStringValue()); + TEST_WRITER.getAttributesMap(clientSpan).get("http.response.body").getStringValue()); } } @@ -277,44 +282,25 @@ private void assertHeaders(Span span) { private void assertRequestAndResponseBody(Span span, String requestBody, String responseBody) { Assertions.assertEquals( - requestBody, - TEST_WRITER - .getAttributesMap(span) - .get("http.request.body") - .getStringValue()); + requestBody, TEST_WRITER.getAttributesMap(span).get("http.request.body").getStringValue()); Assertions.assertEquals( responseBody, - TEST_WRITER - .getAttributesMap(span) - .get("http.response.body") - .getStringValue()); + TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue()); } private void assertBodies( Span clientSpan, Span responseBodySpan, String requestBody, String responseBody) { Assertions.assertEquals( requestBody, - TEST_WRITER - .getAttributesMap(clientSpan) - .get("http.request.body") - .getStringValue()); + TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body").getStringValue()); Assertions.assertEquals( responseBody, - TEST_WRITER - .getAttributesMap(responseBodySpan) - .get("http.response.body") - .getStringValue()); + TEST_WRITER.getAttributesMap(responseBodySpan).get("http.response.body").getStringValue()); } private void assertNoBodies(Span span) { - Assertions.assertNull( - TEST_WRITER - .getAttributesMap(span) - .get("http.response.body")); - Assertions.assertNull( - TEST_WRITER - .getAttributesMap(span) - .get("http.request.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body")); + Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body")); } public static String readInputStream(InputStream inputStream) throws IOException { diff --git a/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractInstrumenterTest.java b/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractInstrumenterTest.java index f895a4ed..80139df5 100644 --- a/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractInstrumenterTest.java +++ b/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractInstrumenterTest.java @@ -18,7 +18,6 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; -import io.opentelemetry.api.trace.Tracer; import java.io.IOException; import java.util.Arrays; import java.util.concurrent.TimeUnit; diff --git a/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java b/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java index 952ee01a..e857dce0 100644 --- a/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java +++ b/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java @@ -26,15 +26,6 @@ import io.opentelemetry.proto.trace.v1.ResourceSpans; import io.opentelemetry.proto.trace.v1.ScopeSpans; import io.opentelemetry.proto.trace.v1.Span; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.handler.HandlerList; - -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; @@ -45,6 +36,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Predicate; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.server.handler.HandlerList; public class TestOtlpReceiver implements AutoCloseable { @@ -149,8 +148,7 @@ public void waitForTraces(int number) throws InterruptedException, TimeoutExcept waitForTraces(number, spans -> false); } - public List> waitForTraces( - int number, Predicate> excludes) + public List> waitForTraces(int number, Predicate> excludes) throws InterruptedException, TimeoutException { synchronized (tracesLock) { long remainingWaitMillis = TimeUnit.SECONDS.toMillis(20); @@ -188,7 +186,8 @@ public List> waitForSpans(int number) throws InterruptedException, Ti return waitForSpans(number, span -> false); } - public List> waitForSpans(int number, Predicate excludes) throws InterruptedException, TimeoutException { + public List> waitForSpans(int number, Predicate excludes) + throws InterruptedException, TimeoutException { synchronized (tracesLock) { long remainingWaitMillis = TimeUnit.SECONDS.toMillis(20); @@ -237,7 +236,7 @@ private List getFilteredSpans(List trace, Predicate excludeSpa } private List> getCompletedAndFilteredTraces( - Predicate> excludeTrace, Predicate excludeSpan) { + Predicate> excludeTrace, Predicate excludeSpan) { List> traces = new ArrayList<>(); for (List trace : getTraces()) { if (isCompleted(trace) && !excludeTrace.test(trace)) { diff --git a/tests-extension/src/main/java/org/hypertrace/javaagent/mockfilter/MockFilterProvider.java b/tests-extension/src/main/java/org/hypertrace/javaagent/mockfilter/MockFilterProvider.java index 56b1fffb..281ebb15 100644 --- a/tests-extension/src/main/java/org/hypertrace/javaagent/mockfilter/MockFilterProvider.java +++ b/tests-extension/src/main/java/org/hypertrace/javaagent/mockfilter/MockFilterProvider.java @@ -25,8 +25,8 @@ public class MockFilterProvider implements FilterProvider { /** - * This no-args constructor must be available for instantiation by the - * {@link java.util.ServiceLoader} API + * This no-args constructor must be available for instantiation by the {@link + * java.util.ServiceLoader} API */ @SuppressWarnings("unused") public MockFilterProvider() {}