Skip to content

GenAI Utils | Embedding Type and Span Creation#4219

Open
shuningc wants to merge 7 commits intoopen-telemetry:mainfrom
shuningc:adding-embedding-type
Open

GenAI Utils | Embedding Type and Span Creation#4219
shuningc wants to merge 7 commits intoopen-telemetry:mainfrom
shuningc:adding-embedding-type

Conversation

@shuningc
Copy link

@shuningc shuningc commented Feb 19, 2026

Description

This PR adds initial embedding lifecycle coverage, to add metrics in the next PR.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Ran from repo root with local package path:
PYTHONPATH=util/opentelemetry-util-genai/src pytest -q util/opentelemetry-util-genai/tests/test_utils.py
PYTHONPATH=util/opentelemetry-util-genai/src pytest -q util/opentelemetry-util-genai/tests/test_handler_metrics.py
Results:
[test_utils.py]: 23 passed

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

@shuningc shuningc requested a review from a team as a code owner February 19, 2026 17:08
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 19, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@aabmass aabmass marked this pull request as draft February 19, 2026 17:19
@shuningc shuningc changed the title [WIP] GenAI Utils | Embedding Type and Span Creation GenAI Utils | Embedding Type and Span Creation Feb 23, 2026
@shuningc shuningc marked this pull request as ready for review February 23, 2026 16:04
dependencies = [
"opentelemetry-instrumentation ~= 0.58b0",
"opentelemetry-semantic-conventions ~= 0.58b0",
"opentelemetry-instrumentation ~= 0.61b0.dev",
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIR the latest embeddings related addition has been gen_ai.embeddings.dimension.count in 1.38.0. The bump to semconv 1.38.0 has been done in 0.60b0.


request_model: str | None = None
# Chat by default
operation_name: str = GenAI.GenAiOperationNameValues.CHAT.value
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this line a different outcome than the __post_init__ ?

Copy link
Author

Choose a reason for hiding this comment

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

I moved the two common attributes from children level to parent level(GenAIInvocation), but this is open for discussion

context_token: ContextToken | None = None
span: Span | None = None
attributes: dict[str, Any] = field(default_factory=_new_str_any_dict)
request_model: str | None = None

Choose a reason for hiding this comment

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

Step, Tool may have no request_model

span: Span | None = None
attributes: dict[str, Any] = field(default_factory=_new_str_any_dict)
request_model: str | None = None
operation_name: str | None = None

Choose a reason for hiding this comment

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

All of the types in semconv require operation name, it looks good
https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-spans.md#spans

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Copy link
Member

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

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

tried it with with OpenAI instrumentation and left a couple of comments.

Looks good otherwise!

span.end()
return invocation

def fail_embedding(
Copy link
Member

Choose a reason for hiding this comment

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

does public API need to be specific to embedding? Can we have one stop/fail for all invocations and apply different logic depending on the invocation type?


provider: str | None = None # e.g., azure.ai.openai, openai, aws.bedrock
server_address: str | None = None
server_port: int | None = None
Copy link
Member

Choose a reason for hiding this comment

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

we should also take response model. I think we just forgot to add it to semconv, fixing it here open-telemetry/semantic-conventions#3499. OpenAI instrumentation already sets it

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

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

8 participants