Comments (12)
I can't get this to work. @kamilogorek What should be in the urls.py ?
from sentry-docs.
cc @mitsuhiko
from sentry-docs.
@fcpauldiaz i am not entirely sure what you are asking. Can you clarify what you mean with "can't get this to work"?
from sentry-docs.
@mitsuhiko The request.sentry object is still not available in my 500.html
This is my urls.py
from main import views as main_views
from django.conf.urls import handler500
handler500 = main_views.server_error
And tried this on the views.py
def server_error(request, template_name='500.html'):
"""500 error handler using RequestContext."""
try:
template = loader.get_template(template_name)
except TemplateDoesNotExist:
if template_name != '500.html':
# Reraise if it's a missing custom template.
raise
return http.HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')
return http.HttpResponseServerError(template.render(None, request, status=500))
This is the templates/500.html
{% extends 'base.html' %}
{% block title %} Error {% endblock %}
{% block content %}
{% load raven %}
<div class="row container">
<div class="col l10 offset-l3 s12 m8 offset-m2">
<h3 class=lue-paypal-text center>You've encountered an error, oh noes!</h3>
{{request.sentry}}
{% if request.sentry.id %}
<p>If you need assistance, you may reference this error as
<strong>{{ request.sentry.id }}</strong>.</p>
{% endif %}
</div>
</div>
{% endblock %}
{% block js %}
<script>Raven.config('{% sentry_public_dsn %}').install()</script>
{% if request.sentry.id %}
<script>
Raven.showReportDialog({
eventId: '{{ request.sentry.id }}',
// use the public DSN (dont include your secret!)
dsn: 'dns_here'
});
</script>
{% endif %}
{% endblock %}
from sentry-docs.
@fcpauldiaz im not sure if template.render
ensures RequestContext is used, but its important that 'request' is made available to the template. If thats not happening this will never work. Additionally, if for some reason the 'Sentry' middleware isn't being installed, it also may not be available.
from sentry-docs.
This is my middleware config
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware'
]
And the template processors
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'debug': DEBUG,
},
},
]
from sentry-docs.
@fcpauldiaz I dont know what Django does with your template.render
call, so you need to verify that 'request' is actually being passed to the template. In older versions of Django that would not happen, and I dont know if the API has since changed (and dont have time to dig into their docs/implementation right now). That owuld be my best guess at whats wrong here.
from sentry-docs.
@dcramer That's exactly why started this issue: request
is not passed to the template, so you need to use a custom server_error()
view. My example works with Django 1.8 and Sentry in production.
from sentry-docs.
Yeah sorry was ignoring the originally issue. I'm not sure why we built the docs the way we did (oversight?), but there's a reasonable example in our generic docs:
https://docs.sentry.io/learn/user-feedback/
It's also important to note that Sentry should monkey-patch in a middleware which ensures some things happen. Without that none of this will work either. I can't imagine that isn't working so its likely just getting down to a fully functional custom_error function.
I'd also +1 shipping with this server_handler function, and possibly overwriting Django's default (though that might be a concern for future versions).
Alternatively, we can create a template tag so you dont need a custom function, and can simply {% load sentry %} {{ sentry.event_id }}
from sentry-docs.
Shipping Raven with a custom server_error()
view sounds like an excellent idea. But why not leaving it up to the user if they want to use it by setting handler500
instead of monkey-patching Django? This would make it easier to handle changes to Django's server_error()
view.
The setup instructions for Raven could explain that you either have to configure something like this in your urls.py
or to use your own function.
from raven.views import server_error
handler500 = server_error
If Django's server_error()
view is updated to pass the request to the template context only this part of the documentation has to be updated, but not the software itself.
Hope my explanation is clear enough to be understood…
from sentry-docs.
In Django 2.0.4 using this custom handler500 worked for me:
@requires_csrf_token
def sentry_server_error(request, template_name=ERROR_500_TEMPLATE_NAME):
"""
500 error handler.
Templates: :template:`500.html`
Context: None
"""
try:
template = loader.get_template(template_name)
except TemplateDoesNotExist:
if template_name != ERROR_500_TEMPLATE_NAME:
# Reraise if it's a missing custom template.
raise
return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')
#return HttpResponseServerError(template.render(RequestContext(request)))
return HttpResponseServerError(template.render(context=None, request=request))
from sentry-docs.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Accepted
, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
from sentry-docs.
Related Issues (20)
- Document how to setup source context in Rust
- Document sourcemaps debugging modal HOT 5
- Improve ownership rule documentation for "module" and "path" HOT 5
- Metrics onboarding docs for Dart/Flutter
- Update Changelog HOT 8
- Improve 404 page HOT 2
- Reorder guide sidebar HOT 1
- Redirects for `:guide` does not exist
- (WIP) Docs structure for JavaScript
- Restructure Troubleshooting pages to be better consumable HOT 3
- Feedback: Additional Micro Frontend Context HOT 3
- sentry/capacitor replay set-up references unknown replayIntegration function HOT 1
- Update CLI configuration page to clarify Crons doesn't support org-based authentication
- .NET platform menu wraps line due to long names HOT 1
- Crons docs for PowerShell HOT 1
- To add commonly asked questions under every platform guides. HOT 5
- Document Python SDK's `set_tags` function
- Document policy violation: js-profiling is not allowed in this document in reactjs application HOT 4
- "What are Artifact Bundles" is no longer accessible from Javascript's docs page HOT 2
- Remix users context HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentry-docs.