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

opper = Opper(http_bearer="YOUR_API_KEY")

# First, create a span and a metric to have real IDs to work with
created_span = opper.spans.create(
    name="customer_feedback_analysis",
    start_time=datetime.now(timezone.utc),
    type="analysis",
    input="Customer feedback: The service was excellent and the response time was very fast.",
    output="Sentiment: Positive, Key topics: service quality, response time, Overall satisfaction: High",
    meta={"analysis_type": "sentiment", "user_id": "user_123"},
)

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

# Create a metric to get
created_metric = opper.span_metrics.create_metric(
    span_id=created_span.id,
    dimension="sentiment_score",
    value=9.2,
    comment="Sentiment analysis score (0-10, where 10 is most positive)",
)

print(f"Created metric with ID: {created_metric.id}")

# Get the specific metric for the span
metric = opper.span_metrics.get(span_id=created_span.id, metric_id=created_metric.id)

print(f"Metric Details:")
print(f"  ID: {metric.id}")
print(f"  Span ID: {metric.span_id}")
print(f"  Dimension: {metric.dimension}")
print(f"  Value: {metric.value}")
if metric.comment:
    print(f"  Comment: {metric.comment}")
print(f"  Created: {metric.created_at}")

# Check if it's a quality metric
if "quality" in metric.dimension.lower():
    if metric.value >= 8.0:
        print("\n✅ High quality response!")
    elif metric.value >= 6.0:
        print("\n⚠️ Moderate quality response")
    else:
        print("\n❌ Low quality response - needs improvement")
{
  "dimension": "<string>",
  "value": 123,
  "comment": "<string>",
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "span_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "created_at": "2023-11-07T05:31:56Z"
}

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

metric_id
string
required

The id of the metric to get

Response

200
application/json

Successful Response

The response is of type object.