Skip to content

Add OutputScope for output message tracing with parent span linking#164

Draft
Copilot wants to merge 9 commits intomainfrom
copilot/extract-output-span-changes
Draft

Add OutputScope for output message tracing with parent span linking#164
Copilot wants to merge 9 commits intomainfrom
copilot/extract-output-span-changes

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

Extracts output span functionality from PR #113. Adds OutputScope for tracing agent output messages with W3C Trace Context parent span linking.

New files

  • spans_scopes/output_scope.py - OpenTelemetry scope for output messages
  • models/response.py - Response dataclass

Base scope changes

  • Added parent_id parameter to OpenTelemetryScope.__init__
  • Parent context parsed from W3C format and passed at span creation (OTel Python has no post-creation parent setter)

Utils refactoring

  • parse_parent_id_to_context() moved to utils.py
  • Added validate_trace_id(), validate_span_id() with hex validation

Behavior

  • record_output_messages() appends to accumulated list (not replace)
response = Response(messages=["Hello"])
parent_id = "00-1234567890abcdef1234567890abcdef-abcdefabcdef1234-01"

with OutputScope.start(agent_details, tenant_details, response, parent_id=parent_id) as scope:
    scope.record_output_messages(["More"])  # Result: ["Hello", "More"]

Tests

Reduced from 10 to 4 focused tests using real spans via InMemorySpanExporter.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • il-1234567812345678123456781234567.8.tenant.api.powerplatform.com
    • Triggering command: /home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/observability/core/ -v --tb=short -m not integration (dns block)
  • il-testtenan.t.tenant.api.powerplatform.com
    • Triggering command: /home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/observability/core/ -v --tb=short -m not integration (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 6, 2026 15:19
- Add Response model class for agent execution response details
- Add spans_scopes directory with OutputScope implementation
- Add unit tests for OutputScope functionality

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract changes to output span from existing PR Add OutputScope for output message tracing Feb 6, 2026
Copilot AI requested a review from nikhilNava February 6, 2026 15:21
Similar to the .NET ExecuteToolScope, the OutputScope now accepts an optional
parent_id parameter to link spans to upstream operations.

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title Add OutputScope for output message tracing Add OutputScope with parent_id for output message tracing Feb 6, 2026
Similar to the .NET implementation, the base OpenTelemetryScope class now
accepts an optional parent_id parameter that sets the CUSTOM_PARENT_SPAN_ID_KEY
attribute on the span. This allows all scope subclasses to support parent
span linking consistently.

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title Add OutputScope with parent_id for output message tracing Add OutputScope with parent_id support on base OpenTelemetryScope Feb 6, 2026
Changed the behavior of record_output_messages to append new messages to
the accumulated list rather than replacing all messages. This allows
collecting output messages over multiple calls during the scope's lifetime.

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title Add OutputScope with parent_id support on base OpenTelemetryScope Add OutputScope for output message tracing with parent_id support Feb 6, 2026
Changed the parent_id implementation to properly link spans by parsing the
W3C Trace Context format parent ID and using it to create a proper span
context. This aligns with the .NET implementation which calls
`activity?.SetParentId(parentId!)`.

Added validation for W3C Trace Context version and trace_id/span_id lengths.

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title Add OutputScope for output message tracing with parent_id support Add OutputScope for output message tracing with proper parent span linking Feb 6, 2026
Copilot AI changed the title Add OutputScope for output message tracing with proper parent span linking Add OutputScope for output message tracing with parent span linking Feb 6, 2026
Refactored W3C Trace Context parsing:
- Added W3C Trace Context validation constants
- Added validate_w3c_trace_context_version() helper
- Added validate_trace_id() helper with hex validation
- Added validate_span_id() helper with hex validation
- Moved parse_parent_id_to_context() from opentelemetry_scope.py

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title Add OutputScope for output message tracing with parent span linking Add OutputScope for output message tracing with W3C parent span linking Feb 6, 2026
…similar ones

Reduced from 10 tests to 4 focused tests:
- test_output_scope_creates_span_with_messages (merged span name and messages tests)
- test_record_output_messages_appends (merged multiple append tests)
- test_output_scope_with_parent_id (parent linking)
- test_output_scope_dispose (manual dispose)

All tests use real spans via InMemorySpanExporter (no mocks).

Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot AI changed the title Add OutputScope for output message tracing with W3C parent span linking Add OutputScope for output message tracing with parent span linking Feb 6, 2026
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