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/logfire.md
+48-9Lines changed: 48 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Monitoring and Performance
1
+
# Debugging and Monitoring
2
2
3
3
Applications that use LLMs have some challenges that are well known and understood: LLMs are **slow**, **unreliable** and **expensive**.
4
4
@@ -15,10 +15,10 @@ LLM Observability tools that just let you understand how your model is performin
15
15
16
16
## Pydantic Logfire
17
17
18
-
[Pydantic Logfire](https://pydantic.dev/logfire) is an observability platform from the developers of Pydantic and PydanticAI, that aims to let you understand your entire application: Gen AI, classic predictive AI, HTTP traffic, database queries and everything else a modern application needs.
18
+
[Pydantic Logfire](https://pydantic.dev/logfire) is an observability platform developed by the team who created and maintain Pydantic and PydanticAI. Logfire aims to let you understand your entire application: Gen AI, classic predictive AI, HTTP traffic, database queries and everything else a modern application needs.
19
19
20
20
!!! tip "Pydantic Logfire is a commercial product"
21
-
Logfire is a commercially supported, hosted platform with an extremely generous and perpetual free tier.
21
+
Logfire is a commercially supported, hosted platform with an extremely generous and perpetual [free tier](https://pydantic.dev/pricing/).
22
22
You can sign up and start using Logfire in a couple of minutes.
23
23
24
24
PydanticAI has built-in (but optional) support for Logfire via the [`logfire-api`](https://github.com/pydantic/logfire/tree/main/logfire-api) no-op package.
@@ -29,14 +29,53 @@ Here's an example showing details of running the [Weather Agent](examples/weathe
To use logfire, you'll need a logfire [account](https://logfire.pydantic.dev), and logfire installed:
35
35
36
-
## Debugging
36
+
```bash
37
+
pip/uv-add 'pydantic-ai[logfire]'
38
+
```
37
39
38
-
TODO
40
+
Then authenticate your local environment with logfire:
39
41
40
-
## Monitoring Performance
42
+
```bash
43
+
py-cli logfire auth
44
+
```
41
45
42
-
TODO
46
+
And configure a project to send data to:
47
+
48
+
```bash
49
+
py-cli logfire projects new
50
+
```
51
+
52
+
(Or use an existing project with `logfire projects use`)
53
+
54
+
The last step is to add logfire to your code:
55
+
56
+
```python title="adding_logfire.py"
57
+
import logfire
58
+
59
+
logfire.configure()
60
+
```
61
+
62
+
The [logfire documentation](https://logfire.pydantic.dev/docs/) has more details on how to use logfire, including how to instrument other libraries like Pydantic, HTTPX and FastAPI.
63
+
64
+
Since Logfire is build on [OpenTelemetry](https://opentelemetry.io/), you can use the Logfire Python SDK to send data to any OpenTelemetry collector.
65
+
66
+
Once you have logfire set up, there are two primary ways it can help you understand your application:
67
+
68
+
***Debugging** — Using the live view to see what's happening in your application in real-time.
69
+
***Monitoring** — Using SQL and dashboards to observe the behavior of your application, Logfire is effectively a SQL database that stores information about how your application is running.
70
+
71
+
### Debugging
72
+
73
+
To demonstrate how Logfire can let you visualise the flow of a PydanticAI run, here's the view you get from Logfire while running the [chat app examples](examples/chat-app.md):
We can also query data with SQL in Logfire to monitor the performance of an application. Here's a real world example of using Logfire to monitor PydanticAI runs inside Logfire itself:
0 commit comments