Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add capture of http.route to DjangoInstrumentor middleware #1226
Add capture of http.route to DjangoInstrumentor middleware #1226
Changes from 4 commits
12da4f6
7362f73
e3979de
f070259
9190a7d
5f7927b
d919de2
3bd216d
a5889bb
aa4e35b
afadb66
ad9dfa5
7348240
9170599
b65e384
3f93411
6a5c07f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
http.route
is supposed to be a route (usually templated or named) from an HTTP router. In django's case, that would be the string representation of a URL from urls.py. Looks like we are using the Python function/handler name. I'm not sure how useful this tag is but irrespective of whether we add it or not, it shouldn't be namedhttp.route
as it means something else entirely unless I'm mistaken.Spec: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions
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.
What we want is the
http.route
to be in the span attribute. But you are correct, the value should be populated from the request path (which will be a string from urls.py). I believe it should be within therequest
parameter.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.
See Opencensus
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.
@owais / @lzchen Thank you for your comments.
I chose to use the class/function name that the request is being routed to so that a developer would be able to go directly from the http.route as reported in AppInsights( and other tools) to the code. But I do see that this is not in accordance with the spec so I will make the change so that http.route is set to the "matched route (path template)".
However, I do not agree that the "matched route (path template)" is the request.path as opencensus uses. This is because the request.path is the actual path of the request, not the route or path template. One path template, you could see multiple paths because the parameters in the path will vary. For instance, the following paths from
request.path
:/api/1/financial-institutions/111/plaid_details/
/api/1/financial-institutions/444/plaid_details/
/api/1/financial-institutions/554/plaid_details/
would all map to one route:
^api/1/financial-institutions/(?P[^/.]+)/plaid_details/$'
I have only been able to find this route as being available from
request.resolver_match.route
andrequest.resolver_match
is none duringprocess_request()
but become available duringprocess_response
andprocess_exception
. So I think this value cannot be set just inprocess_request()
.I will go ahead and make the change to setting http.route to request.resolver_match.route and push up the change.
Please let me know what you think. Thanks!
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.
If you are trying to add this to enable your AppInsights scenario, I suggest doing it the same way OpenCensus is doing it. OpenCensus Python SDK is Microsoft's current solution for Python SDK to send telemetry to App Insights and so being consistent with it is important for back compat and to not break users. If you want to propose a new design, I think submitting a separate feature request (after merging this PR) would be good.
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.
@lzchen - I have change the code so that it uses request.path for the http.route value. I think this make the middleware equivalent to Opencensus.
As you suggested, I will submit a separate feature request around using the route template instead of the url path
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 think we should use templated path/route for this and stick with OpenTelemetry spec. If we decide to have same behavior of OC, we'll have same information duplicated in
http.target
andhttp.route
attributes. I don't think (may be I'm wrong) the breakage here is big enough to warrant going against Otel semantic conventions. OpenCensus users can still find their old value forhttp.route
in OpenTelemetry'shttp.target
so no data is lost after the migration, only renamed. WDYT?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.
@owais
I thought request.path represented the templated path/route, but if it isn't then that is my misunderstanding. But yes, I agree with what you are saying.
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.
Glad we are arriving at a consensus. I have switched the code back to using request.resolver_match.route which is the templated route. I also realized from looking at the OpenCensus implementation that though resolver_match is not set for process_request, it is available in process_view so I added that method.
Also http.path was being set in the OpenCensus implementation by not in the OpenTelemetry implementation so I also added that.
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.
Would doing this in
process_request
be enough and take care of both success/error cases?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 have only been able to find this route as being available from request.resolver_match.route and request.resolver_match is none during process_request() but become available during process_response and process_exception. So I think this value cannot be set just in process_request().