Skip to content

Add id and finish_reason to OpenTelemetry instrumentation (closes #886) #1882

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Deriverx2
Copy link

This PR addresses issue #886 by adding support for gen_ai.response.id and gen_ai.response.finish_reasons attributes to the OpenTelemetry instrumented.py implementation, in accordance with the OpenTelemetry semantic conventions.

if response.vendor_id is not None:
new_attributes['gen_ai.response.id'] = response.vendor_id
if response.vendor_details is not None:
new_attributes['gen_ai.response.finish_reasons'] = json.dumps(response.vendor_details)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor_details can contain a lot more than just finish reasons, so we should just use the finish_reason key.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also notice that https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-events/ requires finish_reasons to be a list, and it lists some specific known values we should use:

  • content_filter
  • error
  • length
  • stop
  • tool_calls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems reasonable to add a new finish_reason field to ModelResponse that has those 5 values as Literal and also allows any string. We should then update the finish_reason code in the Google and Gemini models to try to map to those values if possible.

@Deriverx2 Would you be up for implementing that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure @DouweM

@Deriverx2
Copy link
Author

Could you check it and provide whether this is ok for mapping in gemini, and provide some context on how to make changes in google model. @DouweM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants