Implement HttpServerResponseCustomizer support for Grizzly (#8263)
This commit is contained in:
parent
66f4c80d35
commit
271c72b94a
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.grizzly;
|
||||
|
||||
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseMutator;
|
||||
import org.glassfish.grizzly.http.HttpResponsePacket;
|
||||
import org.glassfish.grizzly.http.util.DataChunk;
|
||||
import org.glassfish.grizzly.http.util.MimeHeaders;
|
||||
|
||||
public enum GrizzlyHttpResponseMutator implements HttpServerResponseMutator<HttpResponsePacket> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void appendHeader(HttpResponsePacket response, String name, String value) {
|
||||
MimeHeaders headers = response.getHeaders();
|
||||
DataChunk data = headers.getValue(name);
|
||||
if (data == null) {
|
||||
data = headers.addValue(name);
|
||||
}
|
||||
if (data.getLength() > 0) {
|
||||
data.setString(data.toString() + "," + value);
|
||||
} else {
|
||||
data.setString(value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
|
||||
import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||
|
@ -43,6 +44,15 @@ public class HttpServerFilterInstrumentation implements TypeInstrumentation {
|
|||
@SuppressWarnings("unused")
|
||||
public static class PrepareResponseAdvice {
|
||||
|
||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||
public static void onEnter(
|
||||
@Advice.Argument(0) FilterChainContext ctx,
|
||||
@Advice.Argument(2) HttpResponsePacket response) {
|
||||
Context context = GrizzlyStateStorage.getContext(ctx);
|
||||
HttpServerResponseCustomizerHolder.getCustomizer()
|
||||
.customize(context, response, GrizzlyHttpResponseMutator.INSTANCE);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
public static void onExit(
|
||||
@Advice.Argument(0) FilterChainContext ctx,
|
||||
|
|
|
@ -58,6 +58,11 @@ class GrizzlyTest extends HttpServerTest<HttpServer> implements AgentTestTrait {
|
|||
server.stop()
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean hasResponseCustomizer(ServerEndpoint endpoint) {
|
||||
true
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean testCapturedHttpHeaders() {
|
||||
false
|
||||
|
|
Loading…
Reference in New Issue