Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(groq): exception when metrics are turned off #2778

Merged
merged 1 commit into from
Mar 13, 2025
Merged
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 @@ -196,24 +196,35 @@ def _set_response_attributes(span, response, token_histogram):
span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, usage.get("total_tokens")
)
set_span_attribute(
span,
SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens
)
set_span_attribute(
span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, prompt_tokens
span, SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens
)
set_span_attribute(span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, prompt_tokens)

if isinstance(prompt_tokens, int) and prompt_tokens >= 0 and token_histogram is not None:
token_histogram.record(prompt_tokens, attributes={
SpanAttributes.LLM_TOKEN_TYPE: "input",
SpanAttributes.LLM_RESPONSE_MODEL: response.get("model")
})
if (
isinstance(prompt_tokens, int)
and prompt_tokens >= 0
and token_histogram is not None
):
token_histogram.record(
prompt_tokens,
attributes={
SpanAttributes.LLM_TOKEN_TYPE: "input",
SpanAttributes.LLM_RESPONSE_MODEL: response.get("model"),
},
)

if isinstance(completion_tokens, int) and completion_tokens >= 0 and token_histogram is not None:
token_histogram.record(completion_tokens, attributes={
SpanAttributes.LLM_TOKEN_TYPE: "output",
SpanAttributes.LLM_RESPONSE_MODEL: response.get("model")
})
if (
isinstance(completion_tokens, int)
and completion_tokens >= 0
and token_histogram is not None
):
token_histogram.record(
completion_tokens,
attributes={
SpanAttributes.LLM_TOKEN_TYPE: "output",
SpanAttributes.LLM_RESPONSE_MODEL: response.get("model"),
},
)

choices = response.get("choices")
if should_send_prompts() and choices:
Expand Down Expand Up @@ -575,7 +586,7 @@ def _instrument(self, **kwargs):
token_histogram,
choice_counter,
duration_histogram,
) = (None, None, None, None)
) = (None, None, None)

for wrapped_method in WRAPPED_METHODS:
wrap_package = wrapped_method.get("package")
Expand Down