Skip to content

Commit 93e845b

Browse files
authored
Docs for updated HuggingFace Hub Python integration (#14909)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR We updated the HuggingFace Hub integration in the Python SDK to work with the AI Agents insights module. This are the docs for it. Preview: https://sentry-docs-git-antonpirker-pythonhuggingfacehub.sentry.dev/platforms/python/integrations/huggingface_hub/ ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [x] Urgent deadline (GA date, etc.): 2025-09-15 - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 890c511 commit 93e845b

File tree

2 files changed

+142
-8
lines changed

2 files changed

+142
-8
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: Hugging Face Hub
3+
description: "Learn about using Sentry for Hugging Face Hub."
4+
---
5+
6+
This integration connects Sentry with [Hugging Face Hub](https://github.com/huggingface/huggingface_hub) in Python.
7+
8+
Once you've installed this SDK, you can use Sentry AI Agents Monitoring, a Sentry dashboard that helps you understand what's going on with your AI requests. Sentry AI Monitoring will automatically collect information about prompts, tools, tokens, and models. Learn more about the [AI Agents Dashboard](/product/insights/ai/agents).
9+
10+
## Install
11+
12+
Install `sentry-sdk` from PyPI with the `huggingface_hub` extra:
13+
14+
```bash {tabTitle:pip}
15+
pip install "sentry-sdk[huggingface_hub]"
16+
```
17+
18+
```bash {tabTitle:uv}
19+
uv add "sentry-sdk[huggingface_hub]"
20+
```
21+
22+
## Configure
23+
24+
If you have the `huggingface_hub` package in your dependencies, the Hugging Face Hub integration will be enabled automatically when you initialize the Sentry SDK.
25+
26+
```python
27+
import sentry_sdk
28+
29+
sentry_sdk.init(
30+
dsn="___PUBLIC_DSN___",
31+
environment="local",
32+
traces_sample_rate=1.0,
33+
send_default_pii=True,
34+
)
35+
```
36+
37+
## Verify
38+
39+
Verify that the integration works by initializing a transaction and invoking an agent. In these examples, we're providing a function tool to roll a die.
40+
41+
```python
42+
import random
43+
import sentry_sdk
44+
from huggingface_hub import InferenceClient
45+
46+
def roll_die(sides):
47+
"""Roll a die with a given number of sides"""
48+
return f"Rolled a {random.randint(1, sides)} on a {sides}-sided die."
49+
50+
HF_TOKEN = "..."
51+
TOOLS = [{
52+
"type": "function",
53+
"function": {
54+
"name": "roll_die",
55+
"description": "Roll a die with a given number of sides",
56+
"parameters": {
57+
"type": "object",
58+
"properties": {
59+
"sides": {
60+
"type": "int",
61+
"description": "The number of sides of the die"
62+
}
63+
},
64+
"required": ["sides"],
65+
},
66+
}
67+
}]
68+
69+
def main():
70+
sentry_sdk.init(...) # same as above
71+
72+
client = InferenceClient(token=HF_TOKEN)
73+
74+
with sentry_sdk.start_transaction(name="testing_sentry"):
75+
response = client.chat_completion(
76+
model="Qwen/Qwen2.5-72B-Instruct",
77+
messages=[{
78+
"role": "user",
79+
"content": "Greet the user and use the die roll tool to roll a 6-sided die."
80+
}],
81+
tools=TOOLS,
82+
tool_choice="auto",
83+
)
84+
85+
if __name__ == "__main__":
86+
main()
87+
```
88+
89+
90+
After running this script, the resulting data should show up in the `"AI Spans"` tab on the `"Explore" > "Traces"` page on Sentry.io, and in the [AI Agents Dashboard](/product/insights/ai/agents).
91+
92+
It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io).
93+
94+
## Behavior
95+
96+
- The Hugging Face Hub integration will connect Sentry with all supported Hugging Face Hub methods automatically.
97+
98+
- All exceptions are reported.
99+
100+
- Sentry considers LLM and tokenizer inputs/outputs as PII (Personally identifiable information) and doesn't include PII data by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts and outputs despite `send_default_pii=True`, configure the integration with `include_prompts=False` as shown in the [Options section](#options) below.
101+
102+
## Options
103+
104+
By adding `HuggingfaceHubIntegration` to your `sentry_sdk.init()` call explicitly, you can set options for `HuggingfaceHubIntegration` to change its behavior:
105+
106+
```python
107+
import sentry_sdk
108+
from sentry_sdk.integrations.huggingface_hub import HuggingfaceHubIntegration
109+
110+
sentry_sdk.init(
111+
# ...
112+
# Add data like inputs and responses;
113+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
114+
send_default_pii=True,
115+
integrations=[
116+
HuggingfaceHubIntegration(
117+
include_prompts=False, # LLM inputs/outputs will be not sent to Sentry, despite send_default_pii=True
118+
),
119+
],
120+
)
121+
```
122+
123+
You can pass the following keyword arguments to `HuggingfaceHubIntegration()`:
124+
125+
- `include_prompts`
126+
127+
Whether LLM and tokenizer inputs and outputs should be sent to Sentry. Sentry considers this data personal identifiable data (PII) by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts and outputs despite `send_default_pii=True`, configure the integration with `include_prompts=False`.
128+
129+
The default is `True`.
130+
131+
## Supported Versions
132+
133+
- Python: 3.8+
134+
- huggingface_hub: 0.22+

docs/platforms/python/integrations/index.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
3838

3939
### AI
4040

41-
| | **Auto-enabled** |
42-
| ------------------------------------------------------------------------------------------------------------------------------ | :--------------: |
43-
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> ||
44-
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> ||
45-
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
46-
| <LinkWithPlatformIcon platform="langchain" label="LangChain" url="/platforms/python/integrations/langchain" /> | |
47-
| <LinkWithPlatformIcon platform="langchain" label="LangGraph" url="/platforms/python/integrations/langgraph" /> ||
48-
41+
| | **Auto-enabled** |
42+
| ---------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
43+
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> ||
44+
| <LinkWithPlatformIcon platform="huggingface_hub" label="Hugging Face Hub" url="/platforms/python/integrations/huggingface_hub" /> ||
45+
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> | |
46+
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
47+
| <LinkWithPlatformIcon platform="langchain" label="LangChain" url="/platforms/python/integrations/langchain" /> ||
48+
| <LinkWithPlatformIcon platform="langchain" label="LangGraph" url="/platforms/python/integrations/langgraph" /> ||
4949

5050
### Data Processing
5151

0 commit comments

Comments
 (0)