Skip to content

Commit bdce0bc

Browse files
committed
docs for tracing
1 parent 45ea86a commit bdce0bc

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

docs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
"group": "Libraries",
391391
"pages": [
392392
"integrations/libraries",
393+
"integrations/libraries/openai-agents",
393394
"integrations/libraries/autogen",
394395
"integrations/libraries/dspy",
395396
"integrations/libraries/instructor",
@@ -409,7 +410,10 @@
409410
},
410411
{
411412
"group": "Tracing Providers",
412-
"pages": ["integrations/tracing-providers/arize"]
413+
"pages": [
414+
"integrations/tracing-providers/arize",
415+
"integrations/tracing-providers/logfire"
416+
]
413417
}
414418
]
415419
},
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: "OpenAI Agents"
3+
description: "OpenAI Agents are a powerful tool for building and deploying agents that can be used to automate tasks and workflows."
4+
---
5+
6+
## Tracing OpenAI Agents
7+
8+
Portkey provides an opentelemetry compatible backend to store and query your traces.
9+
10+
You can trace your OpenAI Agents using any OpenTelemetry compatible tracing library.
11+
12+
Here is an example of how to trace your OpenAI Agents using the [`logfire`](/integrations/tracing/logfire) library from Pydantic:
13+
14+
```python Python
15+
import logfire
16+
from pydantic import BaseModel
17+
from agents import Agent, Runner, function_tool
18+
import asyncio
19+
import os
20+
21+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://api.portkeydev.com/v1/logs/otel"
22+
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"x-portkey-api-key={YOUR_PORTKEY_API_KEY}"
23+
24+
class Weather(BaseModel):
25+
city: str
26+
temperature_range: str
27+
conditions: str
28+
29+
@function_tool
30+
def get_weather(city: str) -> Weather:
31+
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
32+
33+
agent = Agent(
34+
name="Hello world",
35+
instructions="You are a helpful agent.",
36+
tools=[get_weather]
37+
)
38+
39+
async def main():
40+
logfire.configure(
41+
service_name='my_agent_service',
42+
send_to_logfire=False,
43+
)
44+
logfire.instrument_openai_agents()
45+
result = await Runner.run(agent, input="What's the weather in Tokyo?")
46+
print(result.final_output)
47+
48+
if __name__ == "__main__":
49+
asyncio.run(main())
50+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "Pydantic Logfire"
3+
description: "Logfire is a tool for comprehensive observability of your LLM applications with OpenTelemetry."
4+
---
5+
6+
7+
[Logfire](https://pydantic.dev/logfire) and any opentelemetry compatible tracing library works out of the box with Portkey.
8+
9+
All you need to do is set the following environment variables in your application:
10+
11+
```sh
12+
OTEL_EXPORTER_OTLP_ENDPOINT = "https://api.portkeydev.com/v1/logs/otel"
13+
OTEL_EXPORTER_OTLP_HEADERS = "x-portkey-api-key={YOUR_PORTKEY_API_KEY}"
14+
```
15+
16+
17+

0 commit comments

Comments
 (0)