dd-trace-py
dd-trace-py copied to clipboard
`ddtrace.config.django['trace_query_string'] = True` doesn't set query string as a tag
Thanks for taking the time for reporting an issue!
Before reporting an issue on dd-trace-py, please be sure to provide all necessary information.
If you're hitting a bug, make sure that you're using the latest version of this library.
Which version of dd-trace-py are you using?
0.55.4
Which version of pip are you using?
21.1.1
Which version of the libraries are you using?
algoliasearch==1.15.3
APScheduler==3.6.3
asn1crypto==0.24.0
attrs==21.2.0
auth0-python==3.7.0
awsebcli==3.12.3
blessed==1.14.2
boto3==1.17.109
botocore==1.20.109
cement==2.8.2
certifi==2018.1.18
cffi==1.12.2
chardet==3.0.4
chardet2==2.0.3
click==7.1.2
colorama==0.3.7
coreapi==2.3.3
coreschema==0.0.4
cryptography==2.6.1
Cython==0.29.21
ddtrace==0.55.4
decorator==4.4.2
Django==2.0.1
django-filter==1.0.4
django-ratelimit==2.0.0
django-redis==4.10.0
django-rest-swagger==2.2.0
djangorestframework==3.7.7
djangorestframework-jwt==1.11.0
dockerpty==0.4.1
docopt==0.6.2
docutils==0.16
drf-tracking==1.3.1
ecdsa==0.13
future==0.17.1
geographiclib==1.49
geopy==1.18.0
idna==2.6
importlib-metadata==4.0.1
inflect==2.1.0
intervaltree==3.1.0
itypes==1.1.0
Jinja2==2.10
jmespath==0.9.3
joblib==0.13.2
jsonschema==3.2.0
MarkupSafe==1.1.0
msgpack==1.0.0
nameparser==1.0.4
numpy==1.17.2
oauthlib==2.1.0
openapi-codec==1.3.2
packaging==21.2
pandas==0.25.1
pathspec==0.5.5
protobuf==3.12.4
psutil==5.8.0
psycopg2==2.7.5
pyasn1==0.4.5
pycparser==2.19
PyJWT==1.7.1
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.6.1
python-dotenv==0.10.1
python-jose==3.0.1
pytz==2017.3
PyYAML==3.13
redis==3.3.8
requests==2.9.1
requests-oauthlib==1.0.0
rsa==4.0
s3transfer==0.4.2
scikit-learn==0.21.3
scipy==1.3.1
semantic-version==2.5.0
sentry-sdk==0.14.1
simplejson==3.15.0
six==1.16.0
sklearn==0.0
slackclient==1.0.1
sortedcontainers==2.2.2
tabulate==0.7.5
tblib==1.7.0
tenacity==6.2.0
termcolor==1.1.0
typing-extensions==3.10.0.0
tzlocal==2.1
uritemplate==3.0.0
urllib3==1.25.4
wcwidth==0.1.7
websocket-client==0.47.0
zipp==3.4.1
How can we reproduce your problem?
We have a Django app that's deployed to AWS ElasticBeanstalk (so we use the patch_all() approach instead of calling ddtrace-run).
ddtrace-related configuration in our settings file:
from ddtrace import patch_all, tracer, config
tracer.configure(enabled=True)
config.env = 'dev'
config.service = 'app-name'
config.version = '0.1'
config.django['instrument_cache'] = True
config.django['instrument_databases'] = True
config.django['distributed_tracing_enabled'] = True
config.django['analytics_enabled'] = True
config.django['analytics_sample_rate'] = 0.5
ddtrace.config.django['trace_query_string'] = True
config.django['use_handler_resource_format'] = True # b/c our django version is < 2.2.0
patch_all(logging=True)
What is the result that you get?
With this setup, we were not getting any values under the http.query.string tag in APM.
However, when I switch ddtrace.config.django['trace_query_string'] = True to
config.http.trace_query_string = True, the tag starts showing up.
What is the result that you expected?
I would expect to be able to use ddtrace.config.django['trace_query_string'] = True for exposing the tag as described in the documentation: https://ddtrace.readthedocs.io/en/stable/integrations.html#django
hey @vrchen thanks for opening an issue.
I'll have to give this a try myself, I am not sure why setting config.http.trace_query_string = True would work but not ddtrace.config.django['trace_query_string'] = True.
The only thing I can think of based on the code is we only call our helper function to set additional request/response tags if we have a response object.
https://github.com/DataDog/dd-trace-py/blob/638d46b56c49f761bc4a70b9cafe576ca248b063/ddtrace/contrib/django/utils.py#L284-L293
Reviewing this specific bit of code, we should probably always call this helper even if we don't have a response object since we'll have request metadata to set (like method, url, query string, etc).
Do you think this is a possible cause of your issue? This would only make sense/be correlated if you see the tag on some spans but not all of them.
@brettlangdon are you asking if the traces that didn't have query string tag were also ones where there was no response returned for the request?
If so, then the answer is no. The requests I tested were successful requests that had json responses returned to me but using ddtrace.config.django['trace_query_string'] = True still didn't work.
@brettlangdon are you asking if the traces that didn't have a query string were also ones where there was no response returned as part of the request?
If so, then the answer is no. The requests I tested were successful requests that had json responses returned to me but using
ddtrace.config.django['trace_query_string'] = Truestill didn't work.
Yes I believe this does answer my question.
The other question I had, which I think I can guess the correct answer to.
Do any requests/endpoints show the query string when ddtrace.config.django['trace_query_string'] = True? (My guess based on what you've provided so far is "no", no requests show the query string regardless of endpoint)
@brettlangdon sorry for the delay. No, other endpoints didn't show query string when using ddtrace.config.django['trace_query_string'] = True.
However, when I switch ddtrace.config.django['trace_query_string'] = True to config.http.trace_query_string = True, the tag starts showing up.
Got the same behaviour on ddtrace==1.1.3
I've opened https://github.com/DataDog/dd-trace-py/pull/7477 resolving the inconsistency between documentation and actual behavior.