Skip to content

Add A365-specific OpenAI Agents SDK instrumentor#132

Merged
hectorhdzg merged 2 commits into
microsoft:mainfrom
hectorhdzg:feature/a365-openai-agents-instrumentor
May 12, 2026
Merged

Add A365-specific OpenAI Agents SDK instrumentor#132
hectorhdzg merged 2 commits into
microsoft:mainfrom
hectorhdzg:feature/a365-openai-agents-instrumentor

Conversation

@hectorhdzg
Copy link
Copy Markdown
Member

@hectorhdzg hectorhdzg commented May 11, 2026

When enable_a365=True, the distro now uses a bundled A365OpenAIAgentsInstrumentor instead of the upstream opentelemetry-instrumentation-openai-agents-v2. This produces spans with the A365 versioned envelope format including custom.parent.span.id, per-message indexed attributes, detailed token counts, and graph_node_parent_id for handoffs.

Fixes #130 — ResponseSpanData no longer maps to chat, eliminating duplicate span names with GenerationSpanData. It now gets its own response span name.
Fixes #131 — tool_call_id correlation between GenerationSpanData and FunctionSpanData is now tracked. The processor captures IDs from generation output and stamps gen_ai.tool.call.id on the corresponding function span.
Fixes #133 — CustomSpanData (e.g. turn) now maps to chain instead of unknown, preserving the original span name.
Fixes #134 — Agent identity is no longer hardcoded. Spans are created through the standard OTel Tracer.start_span() API, so A365SpanProcessor stamps real identity from baggage.
Fixes #135 — All baggage attributes now propagate to auto-instrumented spans. The old GenAISemanticProcessor created spans outside the OTel span lifecycle; the new processor participates in the normal pipeline.

Copilot AI review requested due to automatic review settings May 11, 2026 23:40
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

This PR adds a bundled, A365-specific OpenAI Agents SDK instrumentor and wires the distro to use it when enable_a365=True, so emitted spans follow A365’s expected envelope/message formats and attributes (e.g., custom.parent.span.id, per-message indexing, handoff parent IDs).

Changes:

  • Introduces a new A365OpenAIAgentsInstrumentor + OpenAIAgentsTraceProcessor + message-mapping utilities under src/microsoft/opentelemetry/_genai/_openai_agents/.
  • Updates distro instrumentation setup to select the bundled instrumentor for openai_agents when A365 is enabled.
  • Adds unit + integration tests plus documentation updates describing the dual-instrumentor behavior.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/openai_agents/test_utils.py Unit tests for new OpenAI Agents utility helpers.
tests/openai_agents/test_trace_processor.py Unit tests for the new OpenAI Agents trace processor behavior.
tests/openai_agents/test_trace_instrumentor.py Unit tests for the new A365 OpenAI Agents instrumentor registration logic.
tests/openai_agents/test_message_mapper.py Unit tests for mapping raw OpenAI/Agents message shapes into A365 versioned message envelopes.
tests/openai_agents/integration/test_openai_agents_trace_processor.py Integration tests against real OpenAI/Azure OpenAI for end-to-end span assertions.
tests/openai_agents/integration/conftest.py Integration fixtures for OpenAI/Azure OpenAI env configuration + marker registration.
tests/openai_agents/integration/init.py Marks integration tests package.
tests/openai_agents/init.py Marks openai_agents tests package.
src/microsoft/opentelemetry/_genai/_openai_agents/_utils.py Core attribute extraction helpers for Agents/Response/ChatCompletions span data.
src/microsoft/opentelemetry/_genai/_openai_agents/_trace_processor.py New processor translating OpenAI Agents spans into OTel spans enriched with A365 attributes.
src/microsoft/opentelemetry/_genai/_openai_agents/_trace_instrumentor.py New BaseInstrumentor registering the A365 trace processor with the Agents SDK.
src/microsoft/opentelemetry/_genai/_openai_agents/_message_mapper.py Maps raw gen_ai.input/output.messages JSON into A365 versioned message envelopes.
src/microsoft/opentelemetry/_genai/_openai_agents/_constants.py New constants for span kind keys and message-attribute subkeys used by the Agents bridge.
src/microsoft/opentelemetry/_genai/_openai_agents/init.py Declares the new package.
src/microsoft/opentelemetry/_distro.py Routes openai_agents instrumentation to the bundled A365 instrumentor when enable_a365=True.
README.md Documents the dual-instrumentor behavior for openai_agents.
pyproject.toml Adds openai-agents optional extra.
MIGRATION_A365.md Updates migration guidance for the new A365 Agents instrumentor behavior.
CHANGELOG.md Notes the new A365-specific OpenAI Agents instrumentor feature.
A365_DOCUMENTATION.md Documents the dual instrumentation selection and implications for exporters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/microsoft/opentelemetry/_genai/_openai_agents/_utils.py
Comment thread src/microsoft/opentelemetry/_genai/_openai_agents/_utils.py Outdated
Comment thread src/microsoft/opentelemetry/_genai/_openai_agents/_utils.py Outdated
Comment thread tests/openai_agents/test_utils.py Outdated
Comment thread tests/openai_agents/test_trace_processor.py Outdated
Comment thread tests/openai_agents/test_trace_instrumentor.py Outdated
Comment thread tests/openai_agents/integration/test_openai_agents_trace_processor.py Outdated
Comment thread src/microsoft/opentelemetry/_genai/_openai_agents/_utils.py
@hectorhdzg hectorhdzg force-pushed the feature/a365-openai-agents-instrumentor branch 2 times, most recently from b3397c4 to b46db04 Compare May 12, 2026 19:25
When enable_a365=True, the distro now uses a bundled A365OpenAIAgentsInstrumentor
instead of the upstream opentelemetry-instrumentation-openai-agents-v2. This produces
spans with the A365 versioned envelope format including custom.parent.span.id,
per-message indexed attributes, detailed token counts, and graph_node_parent_id
for handoffs.

- Port trace processor, message mapper, utils, and constants from Agent365-python
- Wire A365 instrumentor in _distro.py (skip upstream when A365 enabled)
- Add openai-agents as optional dependency
- Add unit tests (70 tests) and integration test scaffolding
- Update A365_DOCUMENTATION.md, MIGRATION_A365.md, README.md, CHANGELOG.md
@hectorhdzg hectorhdzg force-pushed the feature/a365-openai-agents-instrumentor branch from b46db04 to 219aa61 Compare May 12, 2026 20:17
@hectorhdzg hectorhdzg merged commit 1c21c8a into microsoft:main May 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants