Skip to main content
PATCH
/
spans
/
{span_id}
/
metrics
/
{metric_id}
Python
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 update
created_span = opper.spans.create(
    name="content_quality_review",
    start_time=datetime.now(timezone.utc),
    type="review",
    input="Please review this blog post draft for quality and accuracy.",
    output="The blog post draft shows good structure and content, but could benefit from more specific examples and improved conclusion.",
    meta={"content_type": "blog_post", "reviewer_id": "reviewer_456"},
)

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

# Create a metric to update
created_metric = opper.span_metrics.create_metric(
    span_id=created_span.id,
    dimension="content_quality",
    value=7.5,
    comment="Initial quality assessment - good but needs improvement",
)

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

# Update the metric value and comment after review
updated_metric = opper.span_metrics.update_metric_spans_span_id_metrics_metric_id_patch(
    span_id=created_span.id,
    metric_id=created_metric.id,
    value=9.2,
    comment="Updated quality score after review - improved reasoning and accuracy",
)

print(f"Updated metric: {updated_metric.dimension}")
print(f"New value: {updated_metric.value}")
print(f"Updated comment: {updated_metric.comment}")
print(f"Last updated: {updated_metric.created_at}")

# Update only the dimension name
dimension_updated = (
    opper.span_metrics.update_metric_spans_span_id_metrics_metric_id_patch(
        span_id=created_span.id,
        metric_id=created_metric.id,
        dimension="content_quality_final",
    )
)

print(f"\nUpdated dimension to: {dimension_updated.dimension}")
{
  "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<uuid>
required

The id of the span

metric_id
string<uuid>
required

The id of the metric to update

Body

application/json
dimension
string | null

The dimension of the metric

value
number | null

The value of the metric

comment
string | null

A comment about the metric, e.g. a description of the metric

Response

Successful Response

dimension
string
required

The dimension of the metric

value
number
required

The value of the metric

id
string<uuid>
required
span_id
string<uuid>
required
created_at
string<date-time>
required
comment
string | null

A comment about the metric, e.g. a description of the metric

I