13.1.sentry实现错误日志监控
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
文档请参考:https://docs.sentry.io/platforms/python/guides/django/
Install our Python SDK using pip
:
pip install --upgrade sentry-sdk
Configuration should happen as early as possible in your application's lifecycle.
Initialize the Python SDK with the Django integration in your settings.py
file. Once this is done, the SDK captures all unhandled exceptions and transactions.
settings.py
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
integrations=[DjangoIntegration()],
# Set traces_sample_rate to 1.0 to capture 100%
Additional configuration for DjangoIntegration
can be found under integration configuration.
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:
from django.urls import path
def trigger_error(request):
division_by_zero = 1 / 0
urlpatterns = [
path('sentry-debug/', trigger_error),
# ...
]