Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
from opentelemetry.semconv._incubating.attributes import (
gen_ai_attributes as GenAIAttributes,
)
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import (
GenAiOperationNameValues,
GenAiSystemValues,
)
from opentelemetry.semconv_ai import (
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY,
LLMRequestTypeValues,
Meters,
SpanAttributes,
)
Expand Down Expand Up @@ -278,15 +281,15 @@ async def _aset_token_usage(
choices,
attributes={
**metric_attributes,
SpanAttributes.LLM_RESPONSE_STOP_REASON: getattr(response, "stop_reason", None),
SpanAttributes.GEN_AI_RESPONSE_STOP_REASON: getattr(response, "stop_reason", None),
},
)

set_span_attribute(span, GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
set_span_attribute(
span, GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS, completion_tokens
)
set_span_attribute(span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, total_tokens)
set_span_attribute(span, SpanAttributes.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)

set_span_attribute(
span, SpanAttributes.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, cache_read_tokens
Expand Down Expand Up @@ -392,15 +395,15 @@ def _set_token_usage(
choices,
attributes={
**metric_attributes,
SpanAttributes.LLM_RESPONSE_STOP_REASON: getattr(response, "stop_reason", None),
SpanAttributes.GEN_AI_RESPONSE_STOP_REASON: getattr(response, "stop_reason", None),
},
)

set_span_attribute(span, GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
set_span_attribute(
span, GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS, completion_tokens
)
set_span_attribute(span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, total_tokens)
set_span_attribute(span, SpanAttributes.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)

set_span_attribute(
span, SpanAttributes.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, cache_read_tokens
Expand Down Expand Up @@ -537,12 +540,17 @@ def _wrap(
return wrapped(*args, **kwargs)

name = to_wrap.get("span_name")
operation_name = (
GenAiOperationNameValues.TEXT_COMPLETION.value
if name == "anthropic.completion"
else GenAiOperationNameValues.CHAT.value
)
span = tracer.start_span(
name,
kind=SpanKind.CLIENT,
attributes={
GenAIAttributes.GEN_AI_SYSTEM: "Anthropic",
SpanAttributes.LLM_REQUEST_TYPE: LLMRequestTypeValues.COMPLETION.value,
GenAIAttributes.GEN_AI_PROVIDER_NAME: GenAiSystemValues.ANTHROPIC.value,
Comment thread
max-deygin-traceloop marked this conversation as resolved.
GenAIAttributes.GEN_AI_OPERATION_NAME: operation_name,
},
)

Expand Down Expand Up @@ -661,12 +669,17 @@ async def _awrap(
return await wrapped(*args, **kwargs)

name = to_wrap.get("span_name")
operation_name = (
GenAiOperationNameValues.TEXT_COMPLETION.value
if name == "anthropic.completion"
else GenAiOperationNameValues.CHAT.value
)
span = tracer.start_span(
name,
kind=SpanKind.CLIENT,
attributes={
GenAIAttributes.GEN_AI_SYSTEM: "Anthropic",
SpanAttributes.LLM_REQUEST_TYPE: LLMRequestTypeValues.COMPLETION.value,
GenAIAttributes.GEN_AI_PROVIDER_NAME: GenAiSystemValues.ANTHROPIC.value,
GenAIAttributes.GEN_AI_OPERATION_NAME: operation_name,
},
)
await _ahandle_input(span, event_logger, kwargs)
Expand Down
Loading
Loading