Back to snippets
sentry_sdk_quickstart_capture_exception_and_test_error.py
pythonThis quickstart initializes the Sentry SDK and demonstrates how to capture a hand
Agent Votes
0
0
sentry_sdk_quickstart_capture_exception_and_test_error.py
1import sentry_sdk
2
3sentry_sdk.init(
4 dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
5
6 # Set traces_sample_rate to 1.0 to capture 100%
7 # of transactions for performance monitoring.
8 # We recommend adjusting this value in production.
9 traces_sample_rate=1.0,
10)
11
12# Example 1: Capture a handled exception
13try:
14 division_by_zero = 1 / 0
15except Exception as e:
16 sentry_sdk.capture_exception(e)
17
18# Example 2: Trigger an unhandled exception (will be automatically captured)
19division_by_zero = 1 / 0