Skip to content

Commit 53cddc9

Browse files
colin-sentrylizokm
andauthored
feat(ai-monitoring): Add AI Monitoring docs (#9807)
* Add AI Monitoring docs Co-authored-by: Liza Mock <[email protected]>
1 parent 2024a8d commit 53cddc9

File tree

7 files changed

+145
-0
lines changed

7 files changed

+145
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: Set Up
3+
sidebar_order: 0
4+
description: "Learn how to set up Sentry AI Monitoring"
5+
---
6+
7+
Sentry AI Monitoring is easiest to use with the Python SDK and an official integration like OpenAI.
8+
9+
![AI Monitoring User Interface](../img/pipelines-view.png)
10+
11+
12+
To start sending AI data to Sentry, make sure you've created a Sentry project for your AI-enabled repository and follow one of the guides below:
13+
14+
## Official AI Integrations
15+
16+
- [OpenAI](/platforms/python/integrations/openai/)
17+
- [Langchain](/platforms/python/integrations/langchain/)
18+
19+
<Alert level="note" title="Don't see your platform?">
20+
21+
We'll be adding AI integrations continuously. You can also instrument AI manually with the Sentry Python SDK.
22+
23+
</Alert>
24+
25+
26+
## Pipelines and LLMs
27+
28+
The Sentry AI Monitoring feature relies on the fact that you have an orchestrator (like langchain) creating pipelines of one or more AI models (such as gpt-4). In the AI Monitoring dashboard, we show you a table of the AI pipelines and pull the token usage from your AI models.
29+
30+
If you're using OpenAI without langchain, you'll need to manually create pipelines with the `@ai_track` annotation. If you're using langchain without OpenAI, you might have to manually record token usage with `record_token_usage()`. Both manual helpers are documented below.
31+
32+
### Python SDK Decorators
33+
34+
The [Python SDK](/platforms/python) includes an `@ai_track` decorator which will mark functions as AI-related and
35+
cause them to show up in the AI Monitoring dashboard.
36+
37+
```python
38+
39+
import time
40+
from sentry_sdk.ai_monitoring import ai_track, record_token_usage
41+
import sentry_sdk
42+
import requests
43+
44+
@ai_track(description="AI tool")
45+
def some_workload_function():
46+
"""
47+
This function is an example of calling arbitrary code with @ai_track so that it shows up in the Sentry trace
48+
"""
49+
time.sleep(5)
50+
51+
@ai_track(description="LLM")
52+
def some_llm_call():
53+
"""
54+
This function is an example of calling an LLM provider that isn't officially supported by Sentry.
55+
"""
56+
with sentry_sdk.start_span(op="ai.chat_completions.create.examplecom", description="Example.com LLM") as span:
57+
result = requests.get('https://example.com/api/llm-chat?question=say+hello').json()
58+
# this annotates the tokens used by the LLM so that they show up in the graphs in the dashboard
59+
record_token_usage(span, total_tokens=result["usage"]["total_tokens"])
60+
return result["text"]
61+
62+
@ai_track(description="My AI pipeline")
63+
def some_pipeline():
64+
"""
65+
The topmost level function with @ai_track gets the operation "ai.pipeline", which makes it show up
66+
in the table of AI pipelines in the Sentry AI Monitoring dashboard.
67+
"""
68+
client = OpenAI()
69+
some_workload_function()
70+
some_llm_call()
71+
response = (
72+
client.chat.completions.create(
73+
model="some-model", messages=[{"role": "system", "content": "say hello"}]
74+
)
75+
.choices[0]
76+
.message.content
77+
)
78+
print(response)
79+
80+
with sentry_sdk.start_transaction(op="ai-inference", name="The result of the AI inference"):
81+
some_pipeline()
82+
83+
```
84+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: AI Monitoring Dashboard
3+
sidebar_order: 100
4+
description: "Learn how to use Sentry's AI Monitoring Dashboard."
5+
---
6+
7+
8+
Once you've [configured the Sentry SDK](/product/ai-monitoring/getting-started/) for your AI project, you'll start
9+
receiving data in the Sentry AI Monitoring dashboard.
10+
11+
![AI Monitoring Dashboard](../img/pipelines-view.png)
12+
13+
14+
## The Per-pipeline Dashboard
15+
In the example below, there are two LangChain pipelines (whose `.name` is the name that shows up in the table).
16+
One has used 58,000 tokens in the past hour, and the other has used 44,900 tokens. When you click one of the pipelines in the table, you can see details about that particular pipeline.
17+
18+
![AI Monitoring for a specific pipeline](../img/details-view.png)
19+
20+
As you can see in the example above, the "Ask Sentry" pipeline has used 59 thousand tokens and taken 3.2 seconds on average.
21+
22+
<Note>
23+
Creating an AI pipeline is different than calling an LLM. If you're creating AI pipelines by calling LLMs directly (without using a tool like LangChain), consider using [manual AI instrumentation](/product/ai-monitoring/getting-started/#manually-instrumenting-ai-workloads).
24+
</Note>
25+
26+
## Where AI Data Shows Up In the Trace View
27+
28+
If configured to include PII, the Sentry SDK will add prompts and responses to LLMs and other AI models to spans in the trace view.
29+
30+
![AI Monitoring trace example](../img/trace-view.png)
31+
32+
In the example above, you can see input messages and LLM responses related to the `ai.chat_completions.create.langchain` span. Other spans like `ai.chat_completions.create.openai` show the number of tokens used for that particular chat completion.
33+
34+
This view can show other data as well. For example, if you call your LLM from a webserver, the trace will include details about the webserver through other integrations, and you'll get a holistic view of all the related parts.
618 KB
Loading
520 KB
Loading
406 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: "AI Monitoring"
3+
sidebar_order: 62
4+
description: "Sentry AI monitoring helps you understand your LLM calls."
5+
---
6+
7+
<Include name="feature-stage-alpha.mdx" />
8+
9+
Sentry's AI Monitoring tools help you understand what's going on with your AI pipelines. They automatically collect information about prompts, tokens, and models from providers like OpenAI.
10+
11+
## Example AI Monitoring Use Cases
12+
13+
- Users are reporting issues with an AI workflow, and you want to investigate responses from the relevant large language models.
14+
- Workflows have been failing due to high token usage, and you want to understand the cause of the higher token usage.
15+
- Users report that AI workflows are taking longer than usual, and you want to understand what steps in a workflow are slowest.
16+
17+
To use AI Monitoring, you must have an existing Sentry account and project set up. If you don't have one, [create an account here](https://sentry.io/signup/).
18+
19+
![AI Monitoring User Interface](./img/details-view.png)
20+
21+
- Learn how to [set up Sentry's AI Monitoring](/product/ai-monitoring/getting-started/).

docs/product/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Giving Sentry visibility into your [**releases**](/product/releases/) makes it p
3737

3838
Releases are integrated with the rest of Sentry so you can directly see how an error or performance issue was affected by a release, in addition to being able to resolve release-specific issues.
3939

40+
### AI Monitoring
41+
42+
Our [**AI Monitoring**](/product/ai-monitoring/) feature gives you insights into your AI pipelines within the broader context of your app. When you `pip install sentry` into a project that's also using an AI provider like OpenAI, Sentry will automatically pick up useful metrics like token usage, prompts, and model IDs, and send them to our AI Monitoring dashboard.
43+
44+
45+
4046
### Recurring Job Monitoring
4147

4248
[**Cron Monitors**](/product/crons/) allows you to monitor the uptime and performance of any scheduled, recurring job in Sentry. Once implemented, it'll allow you to get alerts and metrics to help you solve errors, detect timeouts, and prevent disruptions to your service.

0 commit comments

Comments
 (0)