Skip to content

Comments

feat(openai): POC for updated gen_ai.attributes#3682

Draft
dinmukhamedm wants to merge 2 commits intotraceloop:mainfrom
lmnr-ai:feat/openai/messages-attributes
Draft

feat(openai): POC for updated gen_ai.attributes#3682
dinmukhamedm wants to merge 2 commits intotraceloop:mainfrom
lmnr-ai:feat/openai/messages-attributes

Conversation

@dinmukhamedm
Copy link
Collaborator

This is an early work attempting to tackle #3515. Once I get initial green light, I will rebase, properly restructure, and continue work on this, gradually adding instrumentations one by one

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

@coderabbitai
Copy link

coderabbitai bot commented Feb 15, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

})
elif role == "user":
content = msg.get("content")
content = [{"text": content, "type": "text"}] if isinstance(content, str) else content
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey i think in the conv its
{ “type”: “text”, “content”: “....” }

https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-input-messages

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! Fair, this slipped through, though I added the correct convention in the schema https://github.com/traceloop/openllmetry/pull/3682/changes#diff-419663c6ce668e979666f0d34f908c8e4a255242e2d7c35aab0dd139e15558ddR72

I'll do that in the next revision of this PR once I've gathered more feedback.

@dinmukhamedm dinmukhamedm force-pushed the feat/openai/messages-attributes branch from f8ec5cd to 3f6cbd0 Compare February 23, 2026 11:24
@@ -0,0 +1,207 @@
"""
This module provides TypedDict definitions for the JSON values used
in Generative AI span attributes, including `gen_ai.input_messages`,
Copy link
Contributor

Choose a reason for hiding this comment

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

gen_ai.input.messages

messages = []
for choice in choices:
messages.append({
"role": "assistant",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should take it to const / enum its will be more typed

})
_set_span_attribute(
span,
"gen_ai.output.messages",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for here maybe its should use the const

for choice in choices:
message = choice.get("message")
content = message.get("content")
parts = [{"text": content, "type": "text"}] if isinstance(content, str) else content
Copy link
Contributor

Choose a reason for hiding this comment

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

"content"

span,
"gen_ai.input.messages",
# f"{SpanAttributes.GEN_AI_INPUT_MESSAGES}",
json.dumps([{"role": "user", "parts": [{"content": prompt, "type": "text"}]}]),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the type of the part should be also an a enum its will be easier to mange


_set_span_attribute(
span,
"gen_ai.input.messages",
Copy link
Contributor

Choose a reason for hiding this comment

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

and use the const over here too

content = msg.get("content")
attr_messages.append({
"role": role,
"parts": [{"type": "tool_call_response", "id": id, "response": content}],
Copy link
Contributor

Choose a reason for hiding this comment

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

WDT about extracting it to helper and create a build part method that we can use along all the code

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.

2 participants