-
Notifications
You must be signed in to change notification settings - Fork 808
Description
Sorry, but I'm slightly confused whether I should create an issue in this repository or https://github.com/open-telemetry/opentelemetry-python-contrib. If it's the other one, i'll gladly reopen it there.
Is your feature request related to a problem?
According to the docs and the implementation, you can use OTEL_PYTHON_DJANGO_TRACED_REQUEST_ATTRS to specify what request attributes should be traced.
The middleware uses these options during process_request in https://github.com/open-telemetry/opentelemetry-python/blob/master/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py#L147
The problem is that some of the request attributes that one could wish to trace are available only after some other middlewares run. For example (pretty common setups):
django.contrib.auth.middleware.AuthenticationMiddlewareadds theuserattributedjango.contrib.sites.middleware.CurrentSiteMiddlewareadds thesiteattribute
Of course, we cannot mess with the middleware order, but these attributes are available in the process_response part of the middleware.
Describe the solution you'd like
It would be nice if we could specify attributes that would be extracted in the process_response, so that we can extract these as well using the instrumentation library.
I do not have a preference, and I am describing the options that come to my mind in the next section.
Describe alternatives you've considered
- Extract all attributes in
process_responseinstead ofprocess_request - Include additional configuration variable so that we somehow distinguish between the two extraction places.
- Try extracting the attributes in
process_requestas well asprocess_response(maybe only try to extract the unextracted ones again?)
Additional context
I am willing to create a PR for this upon the decision to do it one way or another.
Thanks.