Skip to content
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

Conversation

agoallikmaa
Copy link
Contributor

This allows custom distributions of the agent to register HttpServerResponseCustomizer implementations. When a supported HTTP server instrumentation starts processing a response, the onStart method of all registered implementations will be invoked with the Context of the SERVER span, an instrumentation-specific response object and HttpServerResponseMutator 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 the io.opentelemetry.javaagent.bootstrap package in javaagent-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 both AgentInstaller 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.

@agoallikmaa agoallikmaa requested a review from a team as a code owner March 7, 2023 02:05
Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@CanIgnoreReturnValue
public HttpServerTestOptions setHasResponseCustomizer(
Predicate<ServerEndpoint> hasResponseCustomizer) {
this.hasResponseCustomizer = hasResponseCustomizer;
Copy link
Member

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?

Copy link
Contributor Author

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.

@mateuszrzeszutek
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants