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

Refactor AttributesExtractor so that it extracts route from Context #5288

Conversation

mateuszrzeszutek
Copy link
Member

I added the Context as a parameter to the AttributesExtractor methods - some of the other interfaces already accept Context (e.g. SpanLinksExtractor, RequestListener) so it doesn't that look out of place. Still, onEnd() now accepts 5 params...

set(attributes, SemanticAttributes.HTTP_SERVER_NAME, getter.serverName(request, response));
set(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context));
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about adding a route(context, request, response) to the getter interface (with a default HttpRouteHolder implementation) but I decided against it: HttpRouteHolder not only stores the route, but also renames the server span whenever the route is updated; if we were to allow somebody to implement a route(context, request, response) method that overrode the default implementation (and skipped the HttpRouteHolder altogether), that instrumentation would not rename the server span after start -- and that would differ from how the HttpRouteHolder handles things.

In other words: using route(request) is fine, because the HttpSpanNameExtractor handles that, but if you want to set the route during/at the end of the request you have to use HttpRouteHolder.

@mateuszrzeszutek
Copy link
Member Author

I made it a draft PR for now -- if this looks acceptable I'll uncomment the @Deprecated annotations and fix all other attributes extractors.

Mateusz Rzeszutek added 2 commits February 1, 2022 16:14
Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

makes sense 👍

Mateusz Rzeszutek and others added 2 commits February 2, 2022 11:27
…tion/api/instrumenter/http/HttpRouteHolder.java

Co-authored-by: Trask Stalnaker <[email protected]>
@mateuszrzeszutek mateuszrzeszutek marked this pull request as ready for review February 2, 2022 11:27
@mateuszrzeszutek mateuszrzeszutek requested a review from a team February 2, 2022 11:27
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

nice

Comment on lines +203 to +204
Context currentContext = span == null ? context : context.with(span);
netAttributesExtractor.onEnd(attributesBuilder, currentContext, endpoint, null, null);
Copy link
Member

Choose a reason for hiding this comment

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

using Context.root() seems like it would be ok for this odd usage, but ok with this too

@mateuszrzeszutek mateuszrzeszutek merged commit 551418c into open-telemetry:main Feb 8, 2022
@mateuszrzeszutek mateuszrzeszutek deleted the http-route-attributes-extractor-refactor branch February 8, 2022 09:38
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
…pen-telemetry#5288)

* Refactor AttributesExtractor so that it extracts route from Context

* typo

* fix tests

* Update instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java

Co-authored-by: Trask Stalnaker <[email protected]>

* fix all AttributesExtractors

Co-authored-by: Trask Stalnaker <[email protected]>
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.

3 participants