You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/product/sentry-basics/integrate-backend/capturing-errors.mdx
+40-23Lines changed: 40 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,17 @@ If you're using your own source code, follow the instructions in [Getting Starte
14
14
15
15
## Unhandled Errors
16
16
17
-
The Sentry SDK will automatically capture and report any _unhandled error_ that happens in your application runtime without any additional configuration or explicit handling. Generally, unhandled errors are errors that aren't caught by any except (or try/catch) clause.
17
+
The Sentry SDK will automatically capture and report any _unhandled error_ that occurs in your application runtime without any additional configuration or explicit handling. Generally, unhandled errors are errors that aren't caught by a `try/except` clause.
18
18
19
-
1. In your browser, launch the local Django app in the following endpoint to trigger an unhandled error:`http://localhost:8000/unhandled`.
19
+
To trigger an unhandled error:
20
20
21
-
2. If you've set up an alert rule, you should be notified about the error. Otherwise, open the **Issues** page in your Sentry account.
21
+
1. Run the local Django app.
22
22
23
-
3. Notice the unhandled exception appears in the list of issues.
23
+
2. Point your browser to `http://localhost:8000/unhandled`.
24
+
25
+
2. If you've set up an [alert rule](/product/alerts/create-alerts/), you should be notified about the error. Otherwise, open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues/) page in your Sentry account.
26
+
27
+
3. You should see the unhandled exception in the list of issues.
24
28
25
29

26
30
@@ -30,9 +34,9 @@ The Sentry SDK will automatically capture and report any _unhandled error_ that
30
34
31
35
5. Notice that the event:
32
36
33
-
- Is tagged with the `environment` and `release` options we've set in the previous tutorial and `handled:no`, marking this event as an unhandled error
34
-
- Contains a suspect commit, made possible because of the committracking feature we enabled previously
35
-
- Contains the custom breadcrumb we added through the SDK
37
+
- Is tagged with the `environment` and `release` options we've set in the previous tutorial with the tag `handled:no`, marking this event as an unhandled error.
38
+
- Contains a suspect commit, made possible because of the commit-tracking feature we enabled earlier.
39
+
- Contains the custom breadcrumb we added through the SDK.
@@ -44,13 +48,23 @@ The Sentry SDK contains several methods that you can use to **explicitly** repor
44
48
45
49
1. Open the `views.py` file. Notice that we import `sentry_sdk` lib which contains the `capture_exception` method:
46
50
47
-
```python
48
-
import sentry_sdk
51
+
```python {filename: myapp/views.py}
52
+
import sentry_sdk
49
53
```
50
54
51
55
2. The method is used to capture the exception handled by the except clause in `HandledErrorView`:
52
56
53
-

57
+
```python {filename: myapp/views.py}
58
+
classHandledErrorView(APIView):
59
+
defget(self, request):
60
+
...
61
+
try:
62
+
'2'+2
63
+
exceptExceptionas err:
64
+
sentry_sdk.capture_exception(err)
65
+
66
+
return Response()
67
+
```
54
68
55
69
3. To try it out on your localhost, trigger the following endpoint: `http://localhost:8000/handled`.
56
70
@@ -70,22 +84,26 @@ Typically, `capture_message` is not emitted, but there are times when a develope
70
84
71
85
2. You can use it anywhere within your app. In our example, we've created a dedicated view class, `CaptureMessageView`, to trigger and capture a message we want to track:
72
86
73
-
```Python
74
-
sentry_sdk.capture_message("You caught me!")
87
+
```python {filename: myapp/views.py}
88
+
sentry_sdk.capture_message("You caught me!")
75
89
```
76
90
77
91
3. To try it out on your localhost, trigger the following endpoint: `http://localhost:8000/message`.
78
92
79
93
4. As before, open the new issue’s detail page from the **Issues** page.
94
+
<Alert>
95
+
You'll need to remove the `"issue.priority is high or medium"` filter from the "Custom Search" field on the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues/) page to see all the issue types in the list.
96
+
</Alert>
97
+
80
98
81
99

82
100
83
-
> By default captured messages are marked with a severity level tag `level:info`, as reflected in the tags section. However, the `capture_message` methods accept an **optional** severity level parameter.
101
+
> By default, captured messages are marked with a severity level tag `level:info`, as reflected in the tags section. However, the `capture_message` methods accept an **optional** severity level parameter.
84
102
85
103
5. In the `views.py` file, change the `capture_message` method to:
6. Save the changes and trigger the `/message` endpoint again. Changes should be applied immediately through `StateReloader`.
@@ -94,28 +112,27 @@ Typically, `capture_message` is not emitted, but there are times when a develope
94
112
95
113
## Enriching your Event Data
96
114
97
-
You can enrich your event and error data through the Sentry SDK by adding custom tags and user context attributes. In addition to providing more context to your errors, those will expand your options to search, filter, and query through your event metadata. Learn more about the advantages of enriching your data in [Event Data](/product/sentry-basics/enrich-data/).
115
+
You can enrich your event and error data through the Sentry SDK by adding custom tags and user context attributes. In addition to providing more context to your errors, enriched data will expand your options to search, filter, and query through your event metadata. Learn more about the advantages of enriching your data in [Event Data](/product/sentry-basics/enrich-data/).
98
116
99
117
To enrich the data of the message events we've captured with `capture_message`:
100
118
101
119
1. In the `views.py` file, locate the line that triggers `sentry_sdk.capture_message`.
> We're using the `push_scope` method that allows us to send data with one specific event on a local scope. We're setting a custom tag, user context attribute (email), and extra data on the local scope to enrich the data on the message event.
115
132
116
133
3. Save your changes and trigger the `/message` endpoint again.
117
134
118
-
4. Open the issue’s detail page from the **Issues** page.
135
+
4. Open the issue’s detail page from the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues/) page.
Copy file name to clipboardExpand all lines: docs/product/sentry-basics/integrate-backend/configuration-options.mdx
+36-28Lines changed: 36 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -4,84 +4,92 @@ sidebar_order: 2
4
4
description: "Learn how to configure releases, breadcrumbs, and environments to enhance the SDK's functionality."
5
5
---
6
6
7
-
Sentry has various configuration options to help enhance the SDK functionality. The options can help provide additional data needed to debug issues even faster or help control what is sent to Sentry by filtering. Learn more in [Configuration](/platforms/python/configuration/).
7
+
Sentry has various configuration options to help enhance the SDK functionality. The options can help provide additional data needed to debug issues even faster or to help control what's sent to Sentry by filtering. Learn more in [Configuration](/platforms/python/configuration/).
8
8
9
9
## Releases
10
10
11
-
A _release_ is a version of your code that is deployed to an environment. Configuring the release helps you figure out if there is a regression in your code, create accountability, resolve issues within Sentry, and stay up to date with your deployments. Releases need to be configured within your SDK and then managed through the [sentry-cli](/product/cli/).
11
+
A _release_ is a version of your code that's deployed to an environment. Configuring the release helps you figure out if there's a regression in your code, ensure accountability, resolve issues within Sentry, and stay up-to-date with your deployments. Releases need to be configured within your SDK and then managed through the [sentry-cli](/product/cli/).
12
12
13
13
Sentry currently supports integrations with GitHub, Bitbucket, Azure DevOps, GitLab, and others. For a complete list of our integrations, check out our [Integrations documentation](/organization/integrations/).
14
14
15
15
To set up the release in this project:
16
16
17
17
1. Open the file `settings.py`. Notice that we add the `release` configuration option when initializing the SDK:
18
18
19
-
```python
20
-
release=os.environ.get("VERSION"),
19
+
```python {filename: myproject/settings.py}
20
+
sentry_sdk.init(
21
+
...
22
+
release=os.environ.get("VERSION"),
23
+
...
24
+
)
21
25
```
22
26
23
27
2. Open the `Makefile` you ran in the previous tutorial.
24
28
25
29

26
30
27
-
3. Notice that we're setting the release version name as an environment variable that is then used in the application's runtime. We're letting the CLI propose a release version name, but you'd probably want to apply your naming conventions:
31
+
3. Notice that we're setting the release version name as an environment variable that's then used in the application's runtime. We're letting the CLI propose a release version name, but you probably want to apply your own naming conventions:
28
32
29
-
```bash
33
+
```Makefile {filename: Makefile}
30
34
VERSION=`sentry-cli releases propose-version`
31
35
```
32
36
33
-
4.Then we create the new release for our project with the proposed or selected name.
37
+
4.We then create a new release for our project with the proposed or selected name.
34
38
35
-
```bash
36
-
>create_release:
37
-
sentry-cli releases -o $(SENTRY_ORG) new -p $(SENTRY_PROJECT)$(VERSION)
39
+
```Makefile {filename: Makefile}
40
+
create_release:
41
+
sentry-cli releases -o $(SENTRY_ORG) new -p $(SENTRY_PROJECT) $(VERSION)
38
42
```
39
43
40
44
5. In the previous tutorial, we configured the GitHub integration and added the code repository for commit tracking. Now we can associate commits from that repository to the new release by running the command:
_Breadcrumbs_ are the trail of events that led up to the error. They can be quite useful when trying to reproduce an issue. Depending on the platform, the SDK will track various types of breadcrumbs by default (for backend SDKs those are DB queries, network events, logging, and others), and you can add custom breadcrumbs as well.
54
+
_Breadcrumbs_ are the trail of events that led up to an error. They're very useful for reproducing an issue. Depending on the platform, the SDK will track various types of breadcrumbs by default (for backend SDKs these are DB queries, network events, logging, and others). You can also add your own custom breadcrumbs.
51
55
52
56
To add breadcrumbs to our app:
53
57
54
58
1. Open the file `myapp > view.py`.
55
59
56
-
2. Notice we import `add_breadcrumb` from the SDK lib.
60
+
2. Notice that we import the `sentry_sdk` lib, which contains the `add_breadcrumb` method:
57
61
58
-
```python
59
-
from sentry_sdk importadd_breadcrumb
62
+
```python {filename: myapp/views.py}
63
+
importsentry_sdk
60
64
```
61
65
62
-
3. We create a custom breadcrumb for each methodhandler in the view classes. This breadcrumb will be added to the trail of breadcrumbs associated with any error triggered through these method call flows. For instance, under `HandledErrorView:get`:
66
+
3. We then create a custom breadcrumb for each method-handler in the view classes. This breadcrumb gets added to the trail of breadcrumbs associated with any error triggered through these method call flows. For instance, under `HandledErrorView.get`:
63
67
64
-
```python
65
-
add_breadcrumb(
66
-
category='URL Endpoints',
67
-
message='In the handled function',
68
-
level='info',
68
+
```python {filename: myapp/views.py}
69
+
sentry_sdk.add_breadcrumb(
70
+
category='URL Endpoints',
71
+
message='In the handled function',
72
+
level='info',
69
73
)
70
74
```
71
75
72
76
## Environment
73
77
74
-
_Environment_ is a powerful configuration option that enables developers using Sentry to perform various workflows, such as filtering issues and triggering alerts, in the context of the deployment environment in which the errors occurred.
78
+
_Environment_ is a powerful configuration option that enables developers using Sentry to perform various workflows, (such as filtering issues and triggering alerts) in the context of the deployment environment in which the errors occurred.
75
79
76
80
1. Open the `settings.py` file.
77
81
78
82
2. Notice that we initialize the SDK with the `environment` configuration option. Any event that's subsequently captured by the SDK will be tagged with the configured environment value.
79
83
80
-
```python
81
-
environment:"Production"
84
+
```python {filename: myproject/settings.py}
85
+
sentry_sdk.init(
86
+
...
87
+
environment="Production"
88
+
...
89
+
)
82
90
```
83
91
84
-
> Environment values are freeform strings. Neither the Sentry SDK nor [sentry.io](https://sentry.io) will not limit you to any specific value or format. In this example, we hardcoded the value. In a real-life app, the value would probably be determined dynamically through a properties file, system, or environment variable.
92
+
> Environment values are freeform strings. Neither the Sentry SDK nor [sentry.io](https://sentry.io) will limit you to any specific value or format. In this example, we hardcoded the value. In a real-life app, the value would probably be determined dynamically through a properties file, system, or environment variable.
0 commit comments