Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/platforms/python/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
| ------------------------------------------------------------------------------------------------------------------------------ | :--------------: |
| <LinkWithPlatformIcon platform="python.aiohttp" label="AIOHTTP" url="/platforms/python/integrations/aiohttp/aiohttp-client" /> | ✓ |
| <LinkWithPlatformIcon platform="python.httpx" label="HTTPX" url="/platforms/python/integrations/httpx" /> | ✓ |
| <LinkWithPlatformIcon platform="python" label="pyreqwest" url="/platforms/python/integrations/pyreqwest" /> | |
| Python standard HTTP client (in the [Default Integrations](default-integrations/#stdlib)) | ✓ |
| `Requests` HTTP instrumentation is done via the [Default Integrations](default-integrations/#stdlib). | ✓ |

Expand Down
73 changes: 73 additions & 0 deletions docs/platforms/python/integrations/pyreqwest/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: pyreqwest
description: "Learn about the pyreqwest integration and how it adds support for the pyreqwest HTTP client."
---

The [pyreqwest](https://markussintonen.github.io/pyreqwest/pyreqwest.html) integration instruments outgoing HTTP requests using either the sync or the async pyreqwest client.

Use this integration to create spans for outgoing requests and ensure traces are properly propagated to downstream services.

## Install

Install `sentry-sdk` from PyPI:

```bash {tabTitle:pip}
pip install sentry-sdk
```
```bash {tabTitle:uv}
uv add sentry-sdk
```

## Configure

To enable the pyreqwest integration, add `PyreqwestIntegration` to your `integrations`:

```python
import sentry_sdk
from sentry_sdk.integrations.pyreqwest import PyreqwestIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
PyreqwestIntegration(),
],
)
```

## Verify

```python
import asyncio

from pyreqwest.client import ClientBuilder, SyncClientBuilder

sentry_init(...) # same as above

async def example_async():
async with ClientBuilder().error_for_status(True).build() as client:
response = await client.get("http://example.com").build().send()

def example_sync():
with SyncClientBuilder().error_for_status(True).build() as client:
response = client.get("http://example.com").build().send()


with sentry_sdk.start_transaction("pyreqwest async"):
asyncio.run(example_async())

with sentry_sdk.start_transaction("pyreqwest sync"):
example_sync()

```

This will create two transactions, `pyreqwest async` and `pyreqwest sync`, in the Traces section of [sentry.io](https://sentry.io), and create spans for the outgoing HTTP requests.

It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## Supported Versions

- pyreqwest: 0.11.6+
- Python: 3.11+
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ Many integrations for popular frameworks automatically capture transactions. If
- AIOHTTP web apps
- Redis Queue (RQ)

See the full [list of available integrations](/platforms/python/integrations/).

Spans are instrumented for the following operations within a transaction:

- Database queries that use SQLAlchemy or the Django ORM
- HTTP requests made with HTTPX, requests, or the stdlib
- HTTP requests made with HTTPX, requests, the stdlib, AIOHTTP, or pyreqwest
- Spawned subprocesses
- Redis operations

Expand Down
Loading