You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/integrations/http-clients/httpx.md
+37-17Lines changed: 37 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,17 @@
1
1
---
2
-
title: "Instrument HTTPX: see every outgoing request your app makes"
3
-
description: "Add a few lines to your HTTPX code and see every outgoing HTTP request in Logfire: the URL, status, how long it took, and any errors."
2
+
title: "Instrument HTTPX and HTTPX2: see every outgoing request your app makes"
3
+
description: "Add a few lines to your HTTPX or HTTPX2 code and see every outgoing HTTP request in Logfire: the URL, status, how long it took, and any errors."
4
4
integration: otel
5
5
---
6
-
# HTTPX
6
+
# HTTPX and HTTPX2
7
7
8
-
See every HTTP request your app makes with [HTTPX][httpx]: the URL, the response status, how long it
9
-
took, and any errors, as a **span** (one unit of work with a name, a start, and a duration) in
10
-
Logfire. Related spans link together into a **trace** (the full journey of one request), so a slow
11
-
outgoing call shows up right next to the code that triggered it.
8
+
See every HTTP request your app makes with [HTTPX][httpx] or [HTTPX2][httpx2]: the URL, the response
9
+
status, how long it took, and any errors, as a **span** (one unit of work with a name, a start, and a
10
+
duration) in Logfire. Related spans link together into a **trace** (the full journey of one request),
11
+
so a slow outgoing call shows up right next to the code that triggered it.
12
12
13
-
This works with both the synchronous `httpx.Client` and the asynchronous `httpx.AsyncClient`.
13
+
This works with the synchronous `Client` and asynchronous `AsyncClient` from either library. If both
14
+
libraries are installed, one call to `logfire.instrument_httpx()` instruments both.
14
15
15
16
## What you'll capture
16
17
@@ -26,12 +27,21 @@ Install `logfire` with the `httpx` extra:
26
27
27
28
{{ install_logfire(extras=['httpx']) }}
28
29
30
+
The extra installs the OpenTelemetry integration that collects request data. It does not install
31
+
`httpx` or `httpx2`; keep the client library you use as an application dependency.
32
+
33
+
HTTPX2 support requires `opentelemetry-instrumentation-httpx` 0.65b0 or newer. A fresh installation
34
+
normally selects a compatible version. If an existing environment keeps an older version, use the
35
+
upgrade command in [Troubleshooting](#troubleshooting).
36
+
29
37
## Usage
30
38
31
39
Add two lines to your app: `logfire.configure()` to connect to your project, and
32
-
[`logfire.instrument_httpx()`][logfire.Logfire.instrument_httpx] to record every request.
40
+
[`logfire.instrument_httpx()`][logfire.Logfire.instrument_httpx] to record every request. With no
41
+
client argument, Logfire instruments both libraries when they are installed. Pass a client instance
0 commit comments