-
Notifications
You must be signed in to change notification settings - Fork 516
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
Django integration: connect Javascript SDK #1171
Comments
Hey thanks for writing in. Apologies for the frustration, I agree that the documentation can be a lot better here. You can grab the current span using The method is called sentry-python/sentry_sdk/tracing.py Line 351 in 832263b
This will get you a information to continue a Sentry trace (this format is known as traceparent with other tracing/apm providers), hence the inconsistency with naming. The format is basically As such: # Some view I have
def some_view(request):
span = sentry_sdk.Hub.current.scope.span
return render(request, 'template.html', {'sentry-trace': span.to_traceparent()}) <!-- template.html -->
<meta name="sentry-trace" content="{{ sentry-trace }}" /> If you want to apply the meta tag onto every page, I would use |
I am also confused here. Spent a day reading up on this but still confused. But with this approach, don't you need to add the |
You'll need to create your own context processor, we don't offer anything out of the box. Could be something we consider as a feature request. The context processor should just have the logic of grabbing the current span and add it to the context. You'll also need to add the meta tag to every view, we recommend using a base html template with the meta tag, and then having your other templates extend that base template. |
@AbhiPrasad I think it'd valuable to have some documentation or examples with django. I'm equally curious. Thank you for your example at #1171 (comment) I am curious, what would be the difference between: def some_view(request):
with sentry_sdk.configure_scope() as scope:
span = scope.span
return render(request, 'template.html', {'sentry-trace': span.to_traceparent()}) and def some_view(request):
span = sentry_sdk.Hub.current.scope.span
return render(request, 'template.html', {'sentry-trace': span.to_traceparent()}) 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? |
@tony they're functionally equivalent but the first one ( |
@AbhiPrasad The "connecting services" section mentions that apart from the <html>
<head>
<meta name="sentry-trace" content="{{ span.toTraceparent() }}" />
<meta name="baggage" content="{{ serializeBaggage(span.getBaggage()) }}" />
<!-- ... -->
</head>
</html> I just tried and it looks like |
hey @tbrlpld sorry I haven't gotten around to documenting this, my bad! but there's a new helper you can simply inject now which will generate both those meta tags for you.
We will eventually probably auto-inject these into django/flask etc wherever possible so nobody has to think about this. |
@sl0thentr0py It looks like the |
@tbrlpld this helper exists since quite a few versions |
Wow, weird. I could swear I tested this with the latest version installed. Looks like my environment must have been off. It's all there. Thanks @sl0thentr0py. |
I'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:
Steps to Reproduce
<meta>
tag in my Django template, so I followed this: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
🙇♂️
The text was updated successfully, but these errors were encountered: