-
Notifications
You must be signed in to change notification settings - Fork 867
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
Refactor AttributesExtractor so that it extracts route from Context #5288
Conversation
...api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java
Outdated
Show resolved
Hide resolved
set(attributes, SemanticAttributes.HTTP_SERVER_NAME, getter.serverName(request, response)); | ||
set(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context)); |
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.
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
.
I made it a draft PR for now -- if this looks acceptable I'll uncomment the |
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.
LGTM
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.
makes sense 👍
...pi/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java
Outdated
Show resolved
Hide resolved
…tion/api/instrumenter/http/HttpRouteHolder.java Co-authored-by: Trask Stalnaker <[email protected]>
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.
nice
Context currentContext = span == null ? context : context.with(span); | ||
netAttributesExtractor.onEnd(attributesBuilder, currentContext, endpoint, null, null); |
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.
using Context.root()
seems like it would be ok for this odd usage, but ok with this too
…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]>
I added the
Context
as a parameter to theAttributesExtractor
methods - some of the other interfaces already acceptContext
(e.g.SpanLinksExtractor
,RequestListener
) so it doesn't that look out of place. Still,onEnd()
now accepts 5 params...