GET
/
spans
/
{span_id}
from datetime import datetime, timezone
from opperai import Opper

opper = Opper(http_bearer="YOUR_API_KEY")

# First, create a span to have a real ID to work with
created_span = opper.spans.create(
    name="example_api_call",
    start_time=datetime.now(timezone.utc),
    type="request",
    input="Getting weather for New York",
    meta={"user_id": "user_123", "session_id": "session_456", "endpoint": "/weather"},
)

print(f"Created span with ID: {created_span.id}")

# Get the span by its ID
span = opper.spans.get(span_id=created_span.id)

print(f"Span Details:")
print(f"  Name: {span.name}")
print(f"  Type: {span.type}")
print(f"  ID: {span.id}")
print(f"  Trace ID: {span.trace_id}")
print(f"  Start Time: {span.start_time}")

if span.end_time:
    duration = (span.end_time - span.start_time).total_seconds()
    print(f"  Duration: {duration:.2f} seconds")
    print(f"  Status: Completed")
else:
    print(f"  Status: In Progress")

if span.parent_id:
    print(f"  Parent Span: {span.parent_id}")

if span.input:
    print(f"  Input: {span.input[:100]}...")

if span.output:
    print(f"  Output: {span.output[:100]}...")

if span.error:
    print(f"  ❌ Error: {span.error}")

if span.meta:
    print(f"  Metadata: {span.meta}")

if span.score:
    print(f"  Score: {span.score}")
{
  "name": "my span",
  "start_time": "2024-03-20T10:00:00+00:00",
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "trace_id": "123e4567-e89b-12d3-a456-426614174000",
  "parent_id": "123e4567-e89b-12d3-a456-426614174000",
  "type": "email_tool",
  "end_time": "2024-03-20T10:00:10+00:00",
  "input": "<any>",
  "output": "<any>",
  "error": "Exception: This is an error message",
  "meta": {
    "key": "value"
  },
  "score": 10
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

span_id
string
required

The ID of the span to get

Response

200
application/json

Successful Response

The response is of type object.