Django integration: connect Javascript SDK
See original GitHub issueI’m completely stuck with connecting the Python SDK (I’m using Django) and the Javascript SDK. I’ve installed sentry-python
and it sends events to my onPrem Sentry installation. Now I want to connect it with the Frontend using Sentry SDK.
I followed the docs and I think I need to add the trace_id
as a <meta>
tag in my template. Either I’m too dumb or the docs could be improved, but I’ve spent 3+hrs trying to get it done with no success.
Environment
How do you use Sentry?
Sentry onPrem, version 21.8.0, installed with the recommended Docker service using install.sh
. Sentry seems to work, I can receive errors.
Which SDK and version? Backend: Python 3.8.5, Django 3.2.6 using sentry-sdk, version 1.3.1 Frontend: Basic HTML, Bootstrap, nothing fancy
Python virtual environment:
asgiref==3.4.1
certifi==2021.5.30
Django==3.2.6
django-appconf==1.0.4
django-compressor==2.4.1
django-debug-toolbar==3.2.2
django-extensions==3.1.3
django-honeypot==1.0.1
psycopg2-binary==2.9.1
pytz==2021.1
rcssmin==1.0.6
rjsmin==1.1.0
sentry-sdk==1.3.1
six==1.16.0
sqlparse==0.4.1
urllib3==1.26.6
Steps to Reproduce
- Set up the Django integration following the official docs. Unhandled errors in Django are working and being sent to my Sentry instance, so I guess this part is not in question.
- Following Connecting Services, I decided it would be easiest to add a
<meta>
tag in my Django template, so I followed this:
<meta name="sentry-trace" content="{{ span.toSentryTrace() }}" />
I understand that the docs are not Django-specific and I can’t call a function within a template in Django. So I’ve tried a lot of different things, but I don’t seem to have the trace_id
available in my template, nor in the Python environment.
Do I need to add it using a custom template tag? Or is there a middleware I’m not aware of? I’ve googled for “Django Sentry trace_id” and a lot of other things, searched Github for examples, but didn’t find anything that worked.
How do I get that to work? I suspect other Django developers are struggling with that as well, and I hoped it was in the documentation, especially because Django is listed as an integration. I’m willing to contribute this to the docs if appreciated and someone can tell me a recommended way 😃
Expected Result
Docs including best-practice Instructions for connecting Django templates.
Actual Result
🙇♂️
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@tony they’re functionally equivalent but the first one (
configure_scope
) is more ‘canonical’ usage and is what we do internally in integrations as well.Hub.current
always takes the current thread into account and is cloned per thread.@AbhiPrasad I think it’d valuable to have some documentation or examples with django. I’m equally curious.
Thank you for your example at https://github.com/getsentry/sentry-python/issues/1171#issuecomment-906687493
I am curious, what would be the difference between:
and
Are there any risks from grabbing it via sentry_sdk.Hub.current.scope.span? Could that potentially cause issues if it was running on a server with multiple threads/workers/etc?