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.

Comment on lines 466 to 485
ContentCapturingMode.SPAN_ONLY,
ContentCapturingMode.SPAN_AND_EVENT,
]:
span = trace.get_current_span()
span.set_attributes(completion_details_attributes)
if self._content_recording_enabled in [
ContentCapturingMode.EVENT_ONLY,
ContentCapturingMode.SPAN_AND_EVENT,
]:
Copy link
Member

Choose a reason for hiding this comment

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

@DylanRussell should we still do this if there is an upload hook? One practical concern for GCP logging exporter is that if you include the JSON in the log directly and it exceeds the size limit (256kB) the whole log gets dropped. Since the upload hook works on the same log, that would mean everything gets dropped.

Alternatively, maybe we could emit two separate logs to avoid this problem

Copy link
Contributor

Choose a reason for hiding this comment

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

The user can both configure whether they want the upload and whether they want the content in the log right ? So maybe lets just leave it to the user and recommend one way or the other ? Probably should discuss it more internally..

Copy link
Member

Choose a reason for hiding this comment

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

Ah thanks I think you're right from semconv

The hook SHOULD operate independently of the opt-in flags that control capturing of
gen_ai.system_instructions, gen_ai.input.messages, and gen_ai.output.messages.

I kind of read this the opposite way at first but it makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

So the code should always call the hook

Copy link
Author

Choose a reason for hiding this comment

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

So, IIUC, the hook operates independently, is called always (potentially a noop), potentially stamps the attributes with refs, and if span/event logging is enabled, that then is logged, yes?

Copy link
Member

Choose a reason for hiding this comment

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

@DylanRussell can you share the code you did since you had a good look at the specs?

I think we would always create the event and span as well and pass them to the hook. But just not add the content directly to them depending on the environment variable.

Comment on lines 466 to 485
ContentCapturingMode.SPAN_ONLY,
ContentCapturingMode.SPAN_AND_EVENT,
]:
span = trace.get_current_span()
span.set_attributes(completion_details_attributes)
if self._content_recording_enabled in [
ContentCapturingMode.EVENT_ONLY,
ContentCapturingMode.SPAN_AND_EVENT,
]:
Copy link
Contributor

Choose a reason for hiding this comment

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

The user can both configure whether they want the upload and whether they want the content in the log right ? So maybe lets just leave it to the user and recommend one way or the other ? Probably should discuss it more internally..

@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
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