-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide ability to add HTTP server response headers, with Tomcat implementation #7990
Provide ability to add HTTP server response headers, with Tomcat implementation #7990
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
...pi/src/main/java/io/opentelemetry/javaagent/bootstrap/http/HttpServerResponseCustomizer.java
Outdated
Show resolved
Hide resolved
.../main/java/io/opentelemetry/javaagent/bootstrap/http/HttpServerResponseCustomizerHolder.java
Outdated
Show resolved
Hide resolved
.../main/java/io/opentelemetry/javaagent/bootstrap/http/HttpServerResponseCustomizerHolder.java
Outdated
Show resolved
Hide resolved
...in/java/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/Tomcat10ResponseMutator.java
Outdated
Show resolved
Hide resolved
@CanIgnoreReturnValue | ||
public HttpServerTestOptions setHasResponseCustomizer( | ||
Predicate<ServerEndpoint> hasResponseCustomizer) { | ||
this.hasResponseCustomizer = hasResponseCustomizer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there really a need for a Predicate
? Is there any scenario where a boolean
wouldn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be useful in cases where there is no specific support for an appserver directly, so some built-in error pages might not be handled, but we still expect the servlet fallback to handle it for most endpoints.
...r/src/main/java/io/opentelemetry/javaagent/testing/http/TestAgentHttpResponseCustomizer.java
Outdated
Show resolved
Hide resolved
I think this PR resolves #5353 the best way we can - since there is no standard (yet) for returning the trace information in HTTP server response, we let users implement it by themselves via extensions. |
This allows custom distributions of the agent to register
HttpServerResponseCustomizer
implementations. When a supported HTTP server instrumentation starts processing a response, theonStart
method of all registered implementations will be invoked with theContext
of the SERVER span, an instrumentation-specific response object andHttpServerResponseMutator
instance that allows appending headers to that response.The intent of this is to allow custom distributions to set a header containing span context information, such as the trace and span IDs. As such, the initial implementation only allows appending response headers and nothing else.
The
HttpServerResponseCustomizer
and related classes are currently in a subpackage of theio.opentelemetry.javaagent.bootstrap
package injavaagent-extension-api
. This makes them get loaded in the bootstrap classloader, thus directly accessible from instrumentations. I am not aware if there is an elegant way to put it in the agent classloader instead, yet have the same instance accessible from bothAgentInstaller
and instrumentations.This also includes Tomcat-specific implementation in order to be able to demonstrate that it works, and add automated testing of this to HttpServerTest including one implementation.