pyreqwest
Learn about the pyreqwest integration and how it adds support for the pyreqwest HTTP client.
The pyreqwest 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 sentry-sdk from PyPI:
Copied
pip install sentry-sdk
To enable the pyreqwest integration, add PyreqwestIntegration to your integrations:
Copied
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(),
],
)
Copied
import asyncio
from pyreqwest.client import ClientBuilder, SyncClientBuilder
sentry_sdk.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(name="pyreqwest async"):
asyncio.run(example_async())
with sentry_sdk.start_transaction(name="pyreqwest sync"):
example_sync()
This will create two transactions, pyreqwest async and pyreqwest sync, in the Traces section of sentry.io, and create spans for the outgoing HTTP requests.
It takes a couple of moments for the data to appear in sentry.io.
- pyreqwest: 0.11.6+
- Python: 3.11+
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").