from opperai import Opper
opper = Opper(http_bearer="YOUR_API_KEY")
# List all traces with pagination
traces = opper.traces.list(limit=20, offset=0)
print(f"📊 Found {traces.meta.total_count} traces")
print(f"Showing {len(traces.data)} traces")
for trace in traces.data:
print(f"\n🔍 Trace: {trace.name}")
print(f" ID: {trace.id}")
print(f" Status: {trace.status}")
if trace.start_time and trace.end_time:
print(f" Duration: {trace.duration_ms}ms")
if trace.total_tokens:
print(f" Tokens: {trace.total_tokens:,}")
if trace.input:
print(f" Input: {trace.input[:50]}...")
if trace.output:
print(f" Output: {trace.output[:50]}...")
# Filter traces by name
print("\n🔎 Searching for 'question' traces...")
filtered_traces = opper.traces.list(name="question", limit=10)
print(f"Found {len(filtered_traces.data)} matching traces")
for trace in filtered_traces.data:
print(f" • {trace.name} - {trace.duration_ms}ms")
# Analytics example - analyze performance
print("\n📈 Performance Analysis:")
if traces.data:
durations = [t.duration_ms for t in traces.data if t.duration_ms]
tokens = [t.total_tokens for t in traces.data if t.total_tokens]
if durations:
avg_duration = sum(durations) / len(durations)
print(f"Average duration: {avg_duration:.0f}ms")
if tokens:
avg_tokens = sum(tokens) / len(tokens)
print(f"Average tokens: {avg_tokens:.0f}")
successful = len([t for t in traces.data if t.status == "success"])
print(
f"Success rate: {successful}/{len(traces.data)} ({successful / len(traces.data) * 100:.1f}%)"
){
"meta": {
"total_count": 1
},
"data": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"start_time": "2023-11-07T05:31:56Z",
"end_time": "2023-11-07T05:31:56Z",
"duration_ms": 123,
"status": "<string>",
"name": "<string>",
"input": "<string>",
"output": "<string>",
"total_tokens": 123
}
]
}List traces
from opperai import Opper
opper = Opper(http_bearer="YOUR_API_KEY")
# List all traces with pagination
traces = opper.traces.list(limit=20, offset=0)
print(f"📊 Found {traces.meta.total_count} traces")
print(f"Showing {len(traces.data)} traces")
for trace in traces.data:
print(f"\n🔍 Trace: {trace.name}")
print(f" ID: {trace.id}")
print(f" Status: {trace.status}")
if trace.start_time and trace.end_time:
print(f" Duration: {trace.duration_ms}ms")
if trace.total_tokens:
print(f" Tokens: {trace.total_tokens:,}")
if trace.input:
print(f" Input: {trace.input[:50]}...")
if trace.output:
print(f" Output: {trace.output[:50]}...")
# Filter traces by name
print("\n🔎 Searching for 'question' traces...")
filtered_traces = opper.traces.list(name="question", limit=10)
print(f"Found {len(filtered_traces.data)} matching traces")
for trace in filtered_traces.data:
print(f" • {trace.name} - {trace.duration_ms}ms")
# Analytics example - analyze performance
print("\n📈 Performance Analysis:")
if traces.data:
durations = [t.duration_ms for t in traces.data if t.duration_ms]
tokens = [t.total_tokens for t in traces.data if t.total_tokens]
if durations:
avg_duration = sum(durations) / len(durations)
print(f"Average duration: {avg_duration:.0f}ms")
if tokens:
avg_tokens = sum(tokens) / len(tokens)
print(f"Average tokens: {avg_tokens:.0f}")
successful = len([t for t in traces.data if t.status == "success"])
print(
f"Success rate: {successful}/{len(traces.data)} ({successful / len(traces.data) * 100:.1f}%)"
){
"meta": {
"total_count": 1
},
"data": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"start_time": "2023-11-07T05:31:56Z",
"end_time": "2023-11-07T05:31:56Z",
"duration_ms": 123,
"status": "<string>",
"name": "<string>",
"input": "<string>",
"output": "<string>",
"total_tokens": 123
}
]
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
The name of the trace to filter by, the name of a trace is the name of the root span of the trace
The offset to start the list from
x >= 0The number of traces to return
1 <= x <= 100Successful Response
List of items returned in the response
Show child attributes
The id of the trace
The start time of the trace
The end time of the trace
The duration of the trace
The status of the trace
The name of the trace, set to the name of the root span of the trace
The input of the trace, set to the input of the root span of the trace
The output of the trace, set to the output of the root span of the trace
The total tokens of the trace