opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Route used in Django span name is resolved incorrectly and inefficiently
See the conversation in https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2624/files#r1646685931 corresponding to changes in https://github.com/open-telemetry/opentelemetry-python-contrib/commit/dc42bdd986cd136559fda6a3032061d4eed7e517#r1646685931
In summary, only using the route obtained in process_view is more reliably correct and more efficient than calling resolve(request.path) when the span is started. The only reason to do the latter is so that the span name contains the route when it's started so samplers can take this into account.
In my opinion, a better behaviour would be:
- Add a new attribute (e.g.
django.request.path_info) with the value ofrequest.path_info. This is expected to equalhttp.target(which BTW isn't set and should be) or maybe a suffix of it. Samplers can use this to resolve the route if they want. - Don't resolve the route when the span is started. Only use
http.methodas the initial span name. - After getting the route in
process_view, useSpan.update_nameto add the route to the span name.
If this change is undesirable, then at least resolve(request.path) should be changed to resolve(request.path_info).