Skip to content

Commit aaec02b

Browse files
authored
ref(crons): Simplify example, add async note (#9574)
1 parent fd0fab5 commit aaec02b

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

docs/platforms/python/crons/troubleshooting.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ Still having trouble? Reach out to [crons-feedback@sentry.io](mailto:crons-feedb
2727
### Why Are My Monitors Showing Up as Failed?
2828

2929
The SDK might be experiencing network issues. Learn more about <PlatformLink to="/troubleshooting/#network-issues">troubleshooting network issues</PlatformLink>.
30+
31+
### Can I Monitor Async Tasks as Well?
32+
33+
Yes, just make sure you're using SDK version `1.44.1` or higher since that's when support for monitoring async functions was added.

platform-includes/crons/setup/python.mdx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,32 @@ If you're using **Celery Beat** to run your periodic tasks, have a look at our [
66

77
Use the Python SDK to monitor and notify you if your periodic task is missed (or doesn't start when expected), if it fails due to a problem in the runtime (such as an error), or if it fails by exceeding its maximum runtime.
88

9+
Use the `monitor` decorator to wrap your tasks:
10+
911
```python
1012
import sentry_sdk
1113
from sentry_sdk.crons import monitor
1214

1315
# Add the @monitor decorator to your task
1416
@monitor(monitor_slug='<monitor-slug>')
15-
def tell_the_world(msg):
16-
# Scheduled task here...
17-
print(msg)
17+
def tell_the_world():
18+
print('My scheduled task...')
19+
```
20+
21+
Alternatively, `monitor` can be used as a context manager:
22+
23+
```python
24+
import sentry_sdk
25+
from sentry_sdk.crons import monitor
1826

19-
# monitor can also be used as a context manager
20-
def tell_the_world_contextmanager(msg):
27+
def tell_the_world():
2128
with monitor(monitor_slug='<monitor-slug>'):
22-
# Scheduled task here...
23-
print(msg)
29+
print('My scheduled task...')
2430
```
31+
32+
<Note>
33+
34+
Since version `1.44.1` of the SDK you can use `monitor` to annotate asynchronous
35+
functions as well.
36+
37+
</Note>

0 commit comments

Comments
 (0)