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
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,19 +51,27 @@ py-cli logfire projects new
51
51
52
52
(Or use an existing project with `logfire projects use`)
53
53
54
-
The last step is to add logfire to your code:
54
+
Then add logfire to your code:
55
55
56
56
```python {title="adding_logfire.py"}
57
57
import logfire
58
58
59
59
logfire.configure()
60
60
```
61
61
62
+
and enable instrumentation in your agent:
63
+
64
+
```python {title="instrument_agent.py"}
65
+
from pydantic_ai import Agent
66
+
67
+
agent = Agent('openai:gpt-4o', instrument=True)
68
+
```
69
+
62
70
The [logfire documentation](https://logfire.pydantic.dev/docs/) has more details on how to use logfire,
63
71
including how to instrument other libraries like [Pydantic](https://logfire.pydantic.dev/docs/integrations/pydantic/),
64
72
[HTTPX](https://logfire.pydantic.dev/docs/integrations/http-clients/httpx/) and [FastAPI](https://logfire.pydantic.dev/docs/integrations/web-frameworks/fastapi/).
65
73
66
-
Since Logfire is build on [OpenTelemetry](https://opentelemetry.io/), you can use the Logfire Python SDK to send data to any OpenTelemetry collector.
74
+
Since Logfire is built on [OpenTelemetry](https://opentelemetry.io/), you can use the Logfire Python SDK to send data to any OpenTelemetry collector.
67
75
68
76
Once you have logfire set up, there are two primary ways it can help you understand your application:
69
77
@@ -105,10 +113,10 @@ from pydantic_ai import Agent
105
113
logfire.configure()
106
114
logfire.instrument_httpx(capture_all=True) # (1)!
107
115
108
-
agent = Agent('openai:gpt-4o')
116
+
agent = Agent('openai:gpt-4o', instrument=True)
109
117
result = agent.run_sync('What is the capital of France?')
110
118
print(result.data)
111
-
#> The capital of France is Paris.
119
+
#> The capital of France is Paris.
112
120
```
113
121
114
122
1. Capture all of headers, request body, and response body.
0 commit comments