Skip to content

Update mapper for open ai#236

Merged
nikhilNava merged 2 commits intomainfrom
nikhilc/messageFormat2
Apr 24, 2026
Merged

Update mapper for open ai#236
nikhilNava merged 2 commits intomainfrom
nikhilc/messageFormat2

Conversation

@nikhilNava
Copy link
Copy Markdown
Contributor

Task
Support A365 message format for openAi and SK

Result

The latest version of SK no longer reports input and output messages on span attributes.

 Semantic Kernel 1.41.0+ no longer emits gen_ai.input.messages / gen_ai.output.messages as span attributes or span
  events.

  Instead, SK moved message content to Python logging.info() calls with extras like event.name: gen_ai.user.message.
  This is in SK's decorators.py — the _set_completion_input() (line 367-395) and _set_completion_response() (line
  398-447) functions use logger.info() exclusively, not span.add_event() or span.set_attribute().

  The old behavior (documented on Microsoft Learn as of Sep 2024) used span events like gen_ai.content.prompt / 
  gen_ai.content.completion. That's gone in the current version.

openAI

Invoke agent

 {
     "name": "invoke_agent WeatherAgent",
     "context": {
         "trace_id": "0xe9fcb489e54cbb78b6efd7736f96947b",
         "span_id": "0xf1a4f830aafb58ba"
     },
     "kind": "SpanKind.INTERNAL",
     "parent_id": null,
     "status": { "status_code": "OK" },
     "attributes": {
         "gen_ai.operation.name": "invoke_agent",
         "gen_ai.provider.name": "openai",
         "gen_ai.input.messages": "{\"messages\": [{\"role\": \"user\", \"parts\": [{\"content\": \"What's the 
weather in Seattle?\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}",
         "gen_ai.output.messages": "{\"messages\": [{\"role\": \"assistant\", \"parts\": [{\"content\": \"The 
weather in Seattle is sunny with a temperature of 22°C.\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}"
     }
 }

inference span

 {
     "name": "chat gpt-4o-mini",
     "context": {
         "trace_id": "0xe9fcb489e54cbb78b6efd7736f96947b",
         "span_id": "0xe328c0caf7f4cb4d"
     },
     "kind": "SpanKind.INTERNAL",
     "parent_id": "0xf1a4f830aafb58ba",
     "status": { "status_code": "OK" },
     "attributes": {
         "gen_ai.operation.name": "chat",
         "gen_ai.provider.name": "openai",
         "gen_ai.request.model": "gpt-4o-mini",
         "gen_ai.usage.input_tokens": 114,
         "gen_ai.usage.output_tokens": 16,
         "gen_ai.input.messages": "{\"messages\": [{\"role\": \"system\", \"parts\": [{\"content\": \"You are a 
weather assistant. Always use the get_weather function.\", \"type\": \"text\"}]}, {\"role\": \"user\", \"parts\": 
[{\"content\": \"What's the weather in Seattle?\", \"type\": \"text\"}]}, {\"role\": \"assistant\", \"parts\": 
[{\"name\": \"get_weather\", \"id\": \"call_3fhF3lmlJ5kaDk7lVJVNmoIv\", \"arguments\": 
\"{\\\"city\\\":\\\"Seattle\\\"}\", \"type\": \"tool_call\"}]}, {\"role\": \"tool\", \"parts\": [{\"id\": 
\"call_3fhF3lmlJ5kaDk7lVJVNmoIv\", \"response\": \"The weather in Seattle is sunny, 22°C.\", \"type\": 
\"tool_call_response\"}]}], \"version\": \"0.1.0\"}",
         "gen_ai.output.messages": "{\"messages\": [{\"role\": \"assistant\", \"parts\": [{\"content\": \"The 
weather in Seattle is sunny with a temperature of 22°C.\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}",
         "gen_ai.input.messages.0.message_role": "system",
         "gen_ai.input.messages.0.message_content": "You are a weather assistant...",
         "gen_ai.input.messages.1.message_role": "user",
         "gen_ai.input.messages.1.message_content": "What's the weather in Seattle?",
         "gen_ai.input.messages.2.message_role": "assistant",
         "gen_ai.input.messages.2.message_tool_calls.0.gen_ai.tool.name": "get_weather",
         "gen_ai.input.messages.3.message_role": "tool",
         "gen_ai.input.messages.3.message_content": "The weather in Seattle is sunny, 22°C."
     }
 }

Copilot AI review requested due to automatic review settings April 23, 2026 20:36
@nikhilNava nikhilNava requested a review from a team as a code owner April 23, 2026 20:36
@nikhilNava nikhilNava changed the title update mapper for open ai Update mapper for open ai Apr 23, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds OpenAI-specific message mapping so gen_ai.input.messages / gen_ai.output.messages span attributes are converted into the Agent365 (A365) versioned message schema (v0.1.0) before spans are ended/exported, with unit + integration coverage.

Changes:

  • Introduce message_mapper.py to normalize multiple OpenAI message shapes (chat completions, Response API, plain strings) into A365 typed-parts format.
  • Apply the mapper in the OpenAI trace processor on span end for invoke_agent and chat operations.
  • Add unit tests for the mapper and integration tests validating exported spans contain versioned message payloads.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libraries/.../openai/message_mapper.py New mapping layer converting OpenAI message payloads into A365 v0.1.0 wrapper format.
libraries/.../openai/trace_processor.py Invokes the new mapper during on_span_end to rewrite message attributes before span end.
libraries/.../openai/trace_instrumentor.py Clears OpenAI Agents SDK trace processors on uninstrument.
tests/observability/extensions/openai/test_message_mapper.py Unit tests covering supported input/output JSON shapes and fallback behavior.
tests/observability/extensions/openai/integration/test_message_format.py Integration tests that capture enriched spans from real Azure OpenAI calls and validate versioned messages.

@nikhilNava nikhilNava merged commit f3d1d5f into main Apr 24, 2026
9 checks passed
@nikhilNava nikhilNava deleted the nikhilc/messageFormat2 branch April 24, 2026 06:21
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.

5 participants