Skip to content

Commit 67696ca

Browse files
authored
refactoring create_metrics
1 parent 25b600b commit 67696ca

File tree

1 file changed

+3
-18
lines changed
  • packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic

1 file changed

+3
-18
lines changed

packages/opentelemetry-instrumentation-anthropic/opentelemetry/instrumentation/anthropic/__init__.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
LLMRequestTypeValues,
3030
SpanAttributes,
3131
Meters,
32+
MetricUtils,
3233
)
3334
from opentelemetry.trace import SpanKind, Tracer, get_tracer
3435
from opentelemetry.trace.status import Status, StatusCode
@@ -372,24 +373,8 @@ def wrapper(wrapped, instance, args, kwargs):
372373

373374

374375
def _create_metrics(meter: Meter):
375-
token_histogram = meter.create_histogram(
376-
name=Meters.LLM_TOKEN_USAGE,
377-
unit="token",
378-
description="Measures number of input and output tokens used",
379-
)
380-
381-
choice_counter = meter.create_counter(
382-
name=Meters.LLM_GENERATION_CHOICES,
383-
unit="choice",
384-
description="Number of choices returned by chat completions call",
385-
)
386-
387-
duration_histogram = meter.create_histogram(
388-
name=Meters.LLM_OPERATION_DURATION,
389-
unit="s",
390-
description="GenAI operation duration",
391-
)
392-
376+
token_histogram, choice_counter, duration_histogram = MetricUtils.basic_metrics(meter)
377+
393378
exception_counter = meter.create_counter(
394379
name=Meters.LLM_ANTHROPIC_COMPLETION_EXCEPTIONS,
395380
unit="time",

0 commit comments

Comments
 (0)