Skip to content

Commit 46e1603

Browse files
[Python] Added Ray integration getting started (#11029)
The Python SDK has a new integration for the Ray unified compute framework. This is the getting started for this. --------- Co-authored-by: Ivana Kellyer <[email protected]>
1 parent 6a74cf3 commit 46e1603

File tree

2 files changed

+104
-3
lines changed

2 files changed

+104
-3
lines changed

docs/platforms/python/integrations/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
5555
| <LinkWithPlatformIcon platform="python.celery" label="Celery" url="/platforms/python/integrations/celery" /> ||
5656
| <LinkWithPlatformIcon platform="python.huey" label="huey" url="/platforms/python/integrations/huey" /> ||
5757
| <LinkWithPlatformIcon platform="python.rq" label="RQ" url="/platforms/python/integrations/rq" /> ||
58+
| <LinkWithPlatformIcon platform="python.ray" label="Ray" url="/platforms/python/integrations/ray" /> | |
5859

5960
### Cloud Computing
6061

@@ -148,7 +149,6 @@ sentry_sdk.init(
148149
)
149150
```
150151

151-
152152
### Disabling Integrations
153153

154154
To disable an integration, use the [`disabled_integrations`](/platforms/python/configuration/options/#disabled-integrations) config option:
@@ -167,11 +167,11 @@ sentry_sdk.init(
167167

168168
It's also possible to disable all automatically-added integrations. There are two types:
169169

170-
* **Auto-enabled integrations** like `FlaskIntegration` are automatically added
170+
- **Auto-enabled integrations** like `FlaskIntegration` are automatically added
171171
if the SDK detects that you have a corresponding package (like Flask) installed.
172172
This happens when the [`auto_enabling_integrations`](/platforms/python/configuration/options/#auto-enabling-integrations) option is set to
173173
`True` (default).
174-
* **Default integrations** like `logging` or `excepthook` are always enabled,
174+
- **Default integrations** like `logging` or `excepthook` are always enabled,
175175
regardless of what packages you have installed, as long as the
176176
[`default_integrations`](/platforms/python/configuration/options/#default-integrations) option is `True` (default). They provide essential
177177
SDK functionality like error deduplication or event flushing at interpreter
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Ray
3+
description: "Learn how to import and use the Ray integration."
4+
---
5+
6+
The Ray integration adds support for the [Ray](https://www.ray.io/) unified compute framework.
7+
8+
## Install
9+
10+
To get started, install `sentry-sdk` from PyPI.
11+
12+
```bash
13+
pip install --upgrade sentry-sdk
14+
```
15+
16+
## Configure
17+
18+
Add `RayIntegration()` to your `integrations` list:
19+
20+
<SignInNote />
21+
22+
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also collect and analyze performance profiles from real users with [profiling](/product/explore/profiling/).
23+
24+
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
25+
26+
<OnboardingOptionButtons
27+
options={["error-monitoring", "performance", "profiling"]}
28+
/>
29+
30+
```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
31+
import ray
32+
33+
import sentry_sdk
34+
from sentry_sdk.integrations.ray import RayIntegration
35+
36+
def init_sentry():
37+
sentry_sdk.init(
38+
dsn="___PUBLIC_DSN___",
39+
# Set traces_sample_rate to 1.0 to capture 100%
40+
# of transactions for tracing.
41+
traces_sample_rate=1.0,
42+
# Set profiles_sample_rate to 1.0 to profile 100%
43+
# of sampled transactions.
44+
# We recommend adjusting this value in production.
45+
profiles_sample_rate=1.0,
46+
integrations=[
47+
RayIntegration(),
48+
],
49+
)
50+
51+
init_sentry()
52+
53+
ray.init(
54+
runtime_env={"worker_process_setup_hook": init_sentry},
55+
)
56+
```
57+
58+
Be sure to call `sentry_sdk.init()` before you call `ray.init()`.
59+
60+
By setting the `worker_process_setup_hook` we make sure that `sentry_sdk.init()` is called inside Ray worker processes during startup. This allows Sentry to connect code running in the worker with the calling code.
61+
62+
## Verify
63+
64+
Trigger an error in your code to verify that the integration is sending events to Sentry.
65+
66+
```python
67+
def init_sentry():
68+
sentry_sdk.init(...) # same as above
69+
70+
init_sentry()
71+
72+
ray.init(
73+
runtime_env={"worker_process_setup_hook": init_sentry},
74+
)
75+
76+
@ray.remote
77+
def divide(a, b):
78+
return a/b
79+
80+
with sentry_sdk.start_transaction(name="ray-test"):
81+
futures = [
82+
divide.remote(10, 5),
83+
divide.remote(10, 0),
84+
]
85+
print(ray.get(futures))
86+
```
87+
88+
Running this will create an error event (`ZeroDivisionError`) that will be sent to [sentry.io](https://sentry.io). Additionally, trace information will be created in the Performance section of [sentry.io](https://sentry.io).
89+
90+
## Behavior
91+
92+
- All unhandled exceptions will be captured and can be seen on [sentry.io](https://sentry.io).
93+
- Performance data will be captured and available in the Performance section of [sentry.io](https://sentry.io).
94+
- Performance data from [Ray Tasks](https://docs.ray.io/en/latest/ray-core/tasks.html) will be captured and linked to the calling code.
95+
- **Note**: Capturing performance data from [Ray Actors](https://docs.ray.io/en/latest/ray-core/actors.html) is currently **not supported**. (As always, [PRs are welcome](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md))
96+
97+
## Supported Versions
98+
99+
- Ray: 2.34+
100+
- Python: 3.8+
101+

0 commit comments

Comments
 (0)