API Reference
Platform APIs
- Models
- Functions
- Observability
- Knowledge base
- Datasets
- Other
span metrics
Get Metric
Get a metric for a span
GET
/
spans
/
{span_id}
/
metrics
/
{metric_id}
Copy
Ask AI
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")
Copy
Ask AI
{
"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
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Path Parameters
The id of the span
The id of the metric to get
Response
200
application/json
Successful Response
The response is of type object
.
Copy
Ask AI
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")
Copy
Ask AI
{
"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"
}
Assistant
Responses are generated using AI and may contain mistakes.