Skip to content

Conversation

lmolkova
Copy link
Member

@lmolkova lmolkova commented Apr 24, 2025

Fixes #2010, #2179, #1913, #1621, #1912

Depends on #2588

Key points:

  1. System message is recorded as gen_ai.system.instructions attribute. It's not necessarily a part of chat history (when dealing with server-side agents)
  2. Prompt is recorded as gen_ai.input.messages attribute, format is defined in json schema (for now until we have tooling to define complex attributes). If uploading to an external storage, it's replaced with gen_ai.input.messages_ref
  3. Completion is recorded as gen_ai.output.messages (or gen_ai.output.messages_ref)
  4. These attributes can be recorded on spans or on the new event gen_ai.client.inference.operation.details which captures all the details of the inference operation so that it can be useful if span is sampled out and/or if queries between spans and logs backends is problematic.

Depends on #2046 (gen_ai.system rename and migration plan)

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.

Thanks for putting this together! What's need to take this out of draft?

@lmolkova lmolkova moved this from Untriaged to Draft in Semantic Conventions Triage May 4, 2025
@lmolkova lmolkova force-pushed the gen-ai-attributes-and-refs branch from e2facbb to 1ce1548 Compare May 8, 2025 01:14
@lmolkova lmolkova requested a review from Copilot May 8, 2025 01:17
Copilot

This comment was marked as outdated.

@zhirafovod
Copy link

zhirafovod commented May 8, 2025

Unfortunately had to skip today's meeting because of a conflict. Wanted to bring up some cases for sending the prompts and messages as events:

  1. Some customers want to send this customer-sensitive data to a different backend, for compliance reasons.
  2. this data is useful independently from application tracing or metrics, as it provides an option to build a conversation-specific tools and UIs.
  3. tracing usually implemented with different backend technologies

All of this is specifically important for non-purposely built solution, but for a bigger observability platforms.

@lmolkova My proposal would be to keep the events optional, and keep them in the existing implementations enabled with an environment variable.

@lmolkova lmolkova force-pushed the gen-ai-attributes-and-refs branch from 060af49 to d3712a6 Compare May 20, 2025 14:38
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.

Here is a rough prototype of this PR for opentelemetry-instrumentation-google-genai open-telemetry/opentelemetry-python-contrib@main...aabmass:opentelemetry-python-contrib:google-genai-message_ref

@lmolkova lmolkova changed the title [WIP] Using attributes and refs for chat history on gen_ai spans [WIP] Using attributes and refs for chat history on gen_ai spans and events Jun 7, 2025
@lmolkova lmolkova force-pushed the gen-ai-attributes-and-refs branch from 8113a4f to 092db44 Compare June 7, 2025 15:57
Copy link
Contributor

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

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

Thanks for all your hard work and diligence @lmolkova !

@github-project-automation github-project-automation bot moved this from Ready to be Merged to Needs More Approval in Semantic Conventions Triage Aug 14, 2025
Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

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

I wonder if we need first-class interaction with the JSON schema + weaver (e.g. live-check).

@lmolkova Have you already opened tickets in Weaver to make sure it also moves the same direction for supporting events here? (i.e. the 'nested' json schema approach), or are you considering something else going forward?

@lmolkova lmolkova moved this from Needs More Approval to Ready to be Merged in Semantic Conventions Triage Aug 18, 2025
@lmolkova lmolkova added this pull request to the merge queue Aug 19, 2025
Merged via the queue into open-telemetry:main with commit 3e06ddb Aug 19, 2025
15 checks passed
@github-project-automation github-project-automation bot moved this from How to model prompts and completions to Done in GenAI Semantic Conventions and Instrumentation libraries Aug 19, 2025
@srtux srtux mentioned this pull request Aug 22, 2025
3 tasks
trentm added a commit to trentm/opentelemetry-js-contrib that referenced this pull request Oct 8, 2025
One complication was that in [email protected] 'interface ChatCompletionMessageToolCall'
was changed to be:
    export type ChatCompletionMessageToolCall =
      | ChatCompletionMessageFunctionToolCall
      | ChatCompletionMessageCustomToolCall;
which complicated capturing 'tool_calls' info for the telemetry event.

Note also that the GenAI semconv has since moved on. As of open-telemetry/semantic-conventions#2179
there is no longer a 'tool_calls' property in a captured event. This PR
does *not* get into updating the semconv version used by this instrumentation.

Unrelated, there was also a fix to a typo in the 'compile:with-dependencies' npm script
for this package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Capture GenAI prompts and completions as events or attributes