8000 Update google genai instrumentation to work with latest semantic convention, allow for uploading content. by argaj · Pull Request #3772 · open-telemetry/opentelemetry-python-contrib · GitHub
[go: up one dir, main page]

Skip to content

Conversation

argaj
Copy link
@argaj argaj commented Sep 22, 2025

Description

Accomodation of semantic conventions changes made in open-telemetry/semantic-conventions#2179.

Also, when logging the completion details, the upload hook is called, so if user has configured OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH and OTEL_INSTRUMENTATION_GENAI_UPLOAD_HOOK env vars, completion details will also be logged as refs (if appropriate capture content env var is set).

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Unit tests, manual tests.

Does This PR Require a Core Repo Change?

No?

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
linux-foundation-easycla bot commented Sep 22, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@argaj argaj force-pushed the genai-instrumentation-semconv branch from e76d888 to d0d6f1a Compare September 25, 2025 13:30
@argaj argaj force-pushed the genai-instrumentation-semconv branch from d0d6f1a to ee911f5 Compare September 26, 2025 11:32
@argaj argaj force-pushed the genai-instrumentation-semconv branch from 5d0572a to 8583327 Compare September 29, 2025 09:23
@argaj argaj changed the title [WIP] Update google genai instrumentation to work with latest semantic convention, allow for uploading content. Update google genai instrumentation to work with latest semantic convention, allow for uploading content. Sep 30, 2025
@argaj argaj marked this pull request as ready for review September 30, 2025 17:36
@argaj argaj requested a review from a team as a code owner September 30, 2025 17:36
interactions:
- request:
body: |-
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member
@aabmass aabmass left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM! Will merge once Dylan has finished reviewing/approved too.


if as_str:
return {
k: json.dumps(v, cls=_GenAiJsonEncoder)
Copy link
Member

Choose a reason for hiding this comment

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

can you use this function instead? it will remove extra whitespace too

Copy link
Author

Choose a reason for hiding this comment

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

Done, but won't this require util-genai package version bump? I see this func is not in the currently released version (0.1b0)

Copy link
Member

Choose a reason for hiding this comment

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

Ya I can do a release today before merging

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe for now don't pin a version and use it.

# TODO https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3786: restrict
# version after the first release
"opentelemetry-util-genai",
-- for vertexAI we don't have a version pinned currently

Copy link
Author

Choose a reason for hiding this comment

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

Done, I linked it to the same issue, will add a comment there that it's also the case for google-genai instrumentation.

uri: https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
response:
body:
string: "data: {\"candidates\": [{\"content\": {\"role\": \"model\",\"parts\"\
Copy link
Member

Choose a reason for hiding this comment

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

Any idea why this one is formatted like this vs the other RPC recordings?

Copy link
Author

Choose a reason for hiding this comment

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

Dylan updated these, so I don't know :/ @DylanRussell?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure.. will take a look

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, so it's only like this for the streaming tests. It's like this in the current streaming cassettes at head too.

It's because the response is sent using Server-Sent Events (SSE) format, which is a stream of separate data messages. json.loads fails here:

json_data = json.loads(string_value)
return _LiteralBlockScalar(json.dumps(json_data, indent=2))
and we just return the raw string..

uri: https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
response:
body:
string: "data: {\"candidates\": [{\"content\": {\"role\": \"model\",\"parts\"\
Copy link
Member

Choose a reason for hiding this comment

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

Same question, why is the YAML not nice like the other recordings?


if as_str:
return {
k: json.dumps(v, cls=_GenAiJsonEncoder)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe for now don't pin a version and use it.

# TODO https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3786: restrict
# version after the first release
"opentelemetry-util-genai",
-- for vertexAI we don't have a version pinned currently

uri: https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
response:
body:
string: "data: {\"candidates\": [{\"content\": {\"role\": \"model\",\"parts\"\
Copy link
Contributor

Not sure.. will take a look

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0