Skip to content

Commit 0ecd146

Browse files
authored
Fix http pipelining test on Netty 4.1 (#8412)
1 parent 83a4054 commit 0ecd146

File tree

7 files changed

+18
-33
lines changed

7 files changed

+18
-33
lines changed

instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/io/opentelemetry/javaagent/instrumentation/finatra/FinatraServerLatestTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class FinatraServerLatestTest extends AbstractHttpServerTest[HttpServer] {
5555
override def test(endpoint: ServerEndpoint): Boolean =
5656
endpoint != ServerEndpoint.NOT_FOUND
5757
})
58-
options.setTestHttpPipelining(false)
5958
}
6059

6160
override protected def assertHandlerSpan(

instrumentation/finatra-2.9/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/finatra/FinatraServerTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class FinatraServerTest extends AbstractHttpServerTest[HttpServer] {
5656
override def test(endpoint: ServerEndpoint): Boolean =
5757
endpoint != ServerEndpoint.NOT_FOUND
5858
})
59-
options.setTestHttpPipelining(false)
6059
}
6160

6261
override protected def assertHandlerSpan(

instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/internal/server/HttpServerResponseTracingHandler.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static io.opentelemetry.instrumentation.netty.v4_1.internal.server.HttpServerRequestTracingHandler.HTTP_SERVER_REQUEST;
99

10-
import io.netty.channel.Channel;
1110
import io.netty.channel.ChannelFuture;
1211
import io.netty.channel.ChannelHandlerContext;
1312
import io.netty.channel.ChannelOutboundHandlerAdapter;
@@ -69,18 +68,18 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) thr
6968
if (msg instanceof FullHttpResponse) {
7069
// Headers and body all sent together, we have the response information in the msg.
7170
beforeCommitHandler.handle(context, (HttpResponse) msg);
71+
contextAttr.set(null);
72+
HttpRequestAndChannel request = ctx.channel().attr(HTTP_SERVER_REQUEST).getAndSet(null);
7273
writePromise.addListener(
73-
future -> end(ctx.channel(), (FullHttpResponse) msg, writePromise));
74+
future -> end(context, request, (FullHttpResponse) msg, writePromise));
7475
} else {
7576
// Body sent after headers. We stored the response information in the context when
7677
// encountering HttpResponse (which was not FullHttpResponse since it's not
7778
// LastHttpContent).
78-
writePromise.addListener(
79-
future ->
80-
end(
81-
ctx.channel(),
82-
ctx.channel().attr(HTTP_SERVER_RESPONSE).getAndSet(null),
83-
writePromise));
79+
contextAttr.set(null);
80+
HttpRequestAndChannel request = ctx.channel().attr(HTTP_SERVER_REQUEST).getAndSet(null);
81+
HttpResponse response = ctx.channel().attr(HTTP_SERVER_RESPONSE).getAndSet(null);
82+
writePromise.addListener(future -> end(context, request, response, writePromise));
8483
}
8584
} else {
8685
writePromise = prm;
@@ -94,20 +93,24 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) thr
9493
try (Scope ignored = context.makeCurrent()) {
9594
super.write(ctx, msg, writePromise);
9695
} catch (Throwable throwable) {
97-
end(ctx.channel(), null, throwable);
96+
contextAttr.set(null);
97+
HttpRequestAndChannel request = ctx.channel().attr(HTTP_SERVER_REQUEST).getAndSet(null);
98+
end(context, request, null, throwable);
9899
throw throwable;
99100
}
100101
}
101102

102-
private void end(Channel channel, HttpResponse response, ChannelFuture future) {
103+
private void end(
104+
Context context, HttpRequestAndChannel request, HttpResponse response, ChannelFuture future) {
103105
Throwable error = future.isSuccess() ? null : future.cause();
104-
end(channel, response, error);
106+
end(context, request, response, error);
105107
}
106108

107-
// make sure to remove the server context on end() call
108-
private void end(Channel channel, @Nullable HttpResponse response, @Nullable Throwable error) {
109-
Context context = channel.attr(AttributeKeys.SERVER_CONTEXT).getAndSet(null);
110-
HttpRequestAndChannel request = channel.attr(HTTP_SERVER_REQUEST).getAndSet(null);
109+
private void end(
110+
Context context,
111+
HttpRequestAndChannel request,
112+
@Nullable HttpResponse response,
113+
@Nullable Throwable error) {
111114
error = NettyErrorHolder.getOrDefault(context, error);
112115
instrumenter.end(context, request, response, error);
113116
}

instrumentation/netty/netty-4.1/testing/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/AbstractNetty41ServerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ protected void configure(HttpServerTestOptions options) {
6262
unused ->
6363
Sets.difference(
6464
DEFAULT_HTTP_ATTRIBUTES, Collections.singleton(SemanticAttributes.HTTP_ROUTE)));
65-
options.setTestHttpPipelining(false);
6665
}
6766

6867
@Override

instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class VertxRxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTr
6868
return false
6969
}
7070

71-
@Override
72-
boolean testHttpPipelining() {
73-
false
74-
}
75-
7671
protected Class<AbstractVerticle> verticle() {
7772
return VertxReactiveWebServer
7873
}

instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ class VertxRxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTr
6262
return true
6363
}
6464

65-
@Override
66-
boolean testHttpPipelining() {
67-
false
68-
}
69-
7065
@Override
7166
boolean verifyServerSpanEndTime() {
7267
// server spans are ended inside of the controller spans

instrumentation/vertx/vertx-web-3.0/javaagent/src/latestDepTest/groovy/server/VertxLatestHttpServerTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,4 @@ class VertxLatestHttpServerTest extends AbstractVertxHttpServerTest {
1313
protected Class<? extends AbstractVerticle> verticle() {
1414
return VertxLatestWebServer
1515
}
16-
17-
@Override
18-
boolean testHttpPipelining() {
19-
false
20-
}
2116
}

0 commit comments

Comments
 (0)