Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Added Ray integration getting started #11029

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/platforms/python/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
| <LinkWithPlatformIcon platform="python.celery" label="Celery" url="/platforms/python/integrations/celery" /> | ✓ |
| <LinkWithPlatformIcon platform="python.huey" label="huey" url="/platforms/python/integrations/huey" /> | ✓ |
| <LinkWithPlatformIcon platform="python.rq" label="RQ" url="/platforms/python/integrations/rq" /> | ✓ |
| <LinkWithPlatformIcon platform="python.ray" label="Ray" url="/platforms/python/integrations/ray" /> | |

### Cloud Computing

Expand Down Expand Up @@ -148,7 +149,6 @@ sentry_sdk.init(
)
```


### Disabling Integrations

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

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

* **Auto-enabled integrations** like `FlaskIntegration` are automatically added
- **Auto-enabled integrations** like `FlaskIntegration` are automatically added
if the SDK detects that you have a corresponding package (like Flask) installed.
This happens when the [`auto_enabling_integrations`](/platforms/python/configuration/options/#auto-enabling-integrations) option is set to
`True` (default).
* **Default integrations** like `logging` or `excepthook` are always enabled,
- **Default integrations** like `logging` or `excepthook` are always enabled,
regardless of what packages you have installed, as long as the
[`default_integrations`](/platforms/python/configuration/options/#default-integrations) option is `True` (default). They provide essential
SDK functionality like error deduplication or event flushing at interpreter
Expand Down
101 changes: 101 additions & 0 deletions docs/platforms/python/integrations/ray/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Ray
description: "Learn how to import and use the Ray integration."
---

The Ray integration adds support for the [Ray](https://www.ray.io/) unified compute framework.

## Install

To get started, install `sentry-sdk` from PyPI.

```bash
pip install --upgrade sentry-sdk
```

## Configure

Add `RayIntegration()` to your `integrations` list:

<SignInNote />

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/).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

<OnboardingOptionButtons
options={["error-monitoring", "performance", "profiling"]}
/>

```python {"onboardingOptions": {"performance": "9-11", "profiling": "12-15"}}
import ray

import sentry_sdk
from sentry_sdk.integrations.ray import RayIntegration

def init_sentry():
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
integrations=[
RayIntegration(),
],
)

init_sentry()

ray.init(
runtime_env={"worker_process_setup_hook": init_sentry},
)
```

Be sure to call `sentry_sdk.init()` before you call `ray.init()`.

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.

## Verify

Trigger an error in your code to verify that the integration is sending events to Sentry.

```python
def init_sentry():
sentry_sdk.init(...) # same as above

init_sentry()

ray.init(
runtime_env={"worker_process_setup_hook": init_sentry},
)

@ray.remote
def divide(a, b):
return a/b

with sentry_sdk.start_transaction(name="ray-test"):
futures = [
divide.remote(10, 5),
divide.remote(10, 0),
]
print(ray.get(futures))
```

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).

## Behavior

- All unhandled exceptions will be captured and can be seen on [sentry.io](https://sentry.io).
- Performance data will be captured and available in the Performance section of [sentry.io](https://sentry.io).
- Performance data from [Ray Tasks](https://docs.ray.io/en/latest/ray-core/tasks.html) will be captured and linked to the calling code.
- **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))

## Supported Versions

- Ray: 2.34+
- Python: 3.8+

Loading