Skip to content

Commit 1ac8a16

Browse files
Merge pull request #338 from Portkey-AI/tracing
add docs for otel compatible tracing
2 parents 45ea86a + 3a54c60 commit 1ac8a16

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-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
},

integrations/agents/openai-agents.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,52 @@ Portkey provides access to over 200 LLMs through a unified interface, including:
819819
See the full list of LLM providers supported by Portkey
820820
</Card>
821821

822+
### 8. Tracing
823+
824+
Portkey provides an opentelemetry compatible backend to store and query your traces.
825+
826+
You can trace your OpenAI Agents using any OpenTelemetry compatible tracing library.
827+
828+
Here is an example of how to trace your OpenAI Agents using the [`logfire`](/integrations/tracing/logfire) library from Pydantic:
829+
830+
```python Python
831+
import logfire
832+
from pydantic import BaseModel
833+
from agents import Agent, Runner, function_tool
834+
import asyncio
835+
import os
836+
837+
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://api.portkey.com/v1/logs/otel"
838+
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"x-portkey-api-key={YOUR_PORTKEY_API_KEY}"
839+
840+
class Weather(BaseModel):
841+
city: str
842+
temperature_range: str
843+
conditions: str
844+
845+
@function_tool
846+
def get_weather(city: str) -> Weather:
847+
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
848+
849+
agent = Agent(
850+
name="Hello world",
851+
instructions="You are a helpful agent.",
852+
tools=[get_weather]
853+
)
854+
855+
async def main():
856+
logfire.configure(
857+
service_name='my_agent_service',
858+
send_to_logfire=False,
859+
)
860+
logfire.instrument_openai_agents()
861+
result = await Runner.run(agent, input="What's the weather in Tokyo?")
862+
print(result.final_output)
863+
864+
if __name__ == "__main__":
865+
asyncio.run(main())
866+
```
867+
822868

823869
## Tool Use in OpenAI Agents
824870

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.portkey.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)