Skip to content

Commit d39f886

Browse files
authored
Updated code snippets to include new scopes way and still keep deprecated SDK 1.x way (#11222)
1 parent 2e44a1e commit d39f886

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

platform-includes/enriching-events/add-attachment/python.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Because attachments live on the <PlatformLink to="/enriching-events/scopes/">Scope</PlatformLink>, the SDK sends all attachments on a given `Scope` with every non-transaction event captured within the `Scope`. It's also possible to send an attachment with all events, including transactions by setting the `add_to_transactions` option to `True`.
22

3-
```python
3+
```python {tabTitle:Python (SDK 2.x)}
4+
# Add an attachment
5+
import sentry_sdk
6+
7+
scope = sentry_sdk.get_current_scope()
8+
scope.add_attachment(bytes=b"Hello World!", filename="attachment.txt")
9+
scope.add_attachment(path="/path/to/attachment/file.txt")
10+
```
11+
12+
```python {tabTitle:Python (SDK 1.x)}
413
# Add an attachment
514
from sentry_sdk import Scope
615

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
```python
2-
from sentry_sdk import configure_scope
1+
```python {tabTitle:Python (SDK 2.x)}
2+
import sentry_sdk
33

4-
with configure_scope() as scope:
4+
scope = sentry_sdk.get_current_scope()
5+
scope.set_transaction_name("UserListView")
6+
```
7+
8+
```python {tabTitle:Python (SDK 1.x)}
9+
import sentry_sdk
10+
11+
with sentry_sdk.configure_scope() as scope:
512
scope.set_transaction_name("UserListView")
613
```

platform-includes/set-fingerprint/basic/python.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
```python
1+
```python {tabTitle:Python (SDK 2.x)}
2+
from sentry_sdk import new_scope, capture_exception
3+
4+
def make_request(method, path, options):
5+
try:
6+
return session.request(method, path, **options)
7+
except RequestError as err:
8+
with new_scope() as scope:
9+
# group errors together based on their request and response
10+
scope.fingerprint = [method, path, str(err.status_code)]
11+
capture_exception(err)
12+
```
13+
14+
```python {tabTitle:Python (SDK 1.x)}
215
from sentry_sdk import push_scope, capture_exception
316

417
def make_request(method, path, options):

platform-includes/set-fingerprint/static/python.mdx

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)