Replace parent_id string with OpenTelemetry Context for trace propagation#205
Merged
nikhilNava merged 7 commits intomainfrom Mar 18, 2026
Merged
Replace parent_id string with OpenTelemetry Context for trace propagation#205nikhilNava merged 7 commits intomainfrom
nikhilNava merged 7 commits intomainfrom
Conversation
…opagation - Changed all scope classes to accept `parent_context: Context` instead of `parent_id: str` - Added `inject_trace_context()` method to OpenTelemetryScope for header propagation - Added `get_context()` method to get the scope's Context for passing to child scopes - Added `extract_trace_context()` utility function using OTel's standard `extract()` - Removed custom W3C trace context parsing in favor of OTel's propagation API - Updated OutputLoggingMiddleware to use extract_trace_context() - Updated all tests to use extract_trace_context() and parent_context Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
nikhilNava
March 18, 2026 15:58
View session
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the observability “scope” APIs to use OpenTelemetry’s native Context for parent/child span relationships (replacing the previous W3C traceparent string), and adds helpers for standard trace header propagation.
Changes:
- Replace
parent_id: str | Nonewithparent_context: Context | Noneacross scope classes (includingInvokeAgentScope). - Add W3C propagation helpers:
extract_trace_context(headers)and scope methods to inject/forward context (inject_trace_context(),get_context()). - Update/expand unit tests to validate inject/extract propagation and parent-child span linking.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/observability/hosting/middleware/test_output_logging_middleware.py | Updates middleware test expectations from parent_id to parent_context. |
| tests/observability/core/test_trace_context_propagation.py | New tests validating inject/extract propagation, span parenting, and InvokeAgentScope support. |
| tests/observability/core/test_output_scope.py | Updates OutputScope test to build parent_context via extract_trace_context. |
| tests/observability/core/test_inference_scope.py | Updates InferenceScope test to use parent_context extracted from traceparent. |
| tests/observability/core/test_execute_tool_scope.py | Updates ExecuteToolScope test to use parent_context extracted from traceparent. |
| libraries/microsoft-agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/middleware/output_logging_middleware.py | Extracts parent OTel context from stored traceparent value and passes it into OutputScope. |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/utils.py | Removes custom W3C parsing and adds extract_trace_context() backed by OTel propagation. |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/spans_scopes/output_scope.py | Updates OutputScope API to accept parent_context and forwards it to the base scope. |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/opentelemetry_scope.py | Updates base scope constructor to accept parent_context; adds get_context() and inject_trace_context(). |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/invoke_agent_scope.py | Adds parent_context support to InvokeAgentScope. |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/inference_scope.py | Updates InferenceScope API to accept and forward parent_context. |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/execute_tool_scope.py | Updates ExecuteToolScope API to accept and forward parent_context. |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/init.py | Exports extract_trace_context from the public core package API. |
You can also share your feedback on Copilot code review. Take the survey.
...-hosting/microsoft_agents_a365/observability/hosting/middleware/output_logging_middleware.py
Outdated
Show resolved
Hide resolved
...-hosting/microsoft_agents_a365/observability/hosting/middleware/output_logging_middleware.py
Outdated
Show resolved
Hide resolved
...s/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/utils.py
Show resolved
Hide resolved
...s/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/utils.py
Outdated
Show resolved
Hide resolved
...ents-a365-observability-core/microsoft_agents_a365/observability/core/opentelemetry_scope.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
juliomenendez
approved these changes
Mar 18, 2026
fpfp100
approved these changes
Mar 18, 2026
biswapm
pushed a commit
to biswapm/Agent365-python
that referenced
this pull request
Mar 20, 2026
…tion (microsoft#205) * Initial plan * feat: Replace parent_id string with Context object and add context propagation - Changed all scope classes to accept `parent_context: Context` instead of `parent_id: str` - Added `inject_trace_context()` method to OpenTelemetryScope for header propagation - Added `get_context()` method to get the scope's Context for passing to child scopes - Added `extract_trace_context()` utility function using OTel's standard `extract()` - Removed custom W3C trace context parsing in favor of OTel's propagation API - Updated OutputLoggingMiddleware to use extract_trace_context() - Updated all tests to use extract_trace_context() and parent_context Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com> * refactor: Address code review feedback - move imports to module level Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * clean up usage of preant context propogation --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com> Co-authored-by: Nikhil Navakiran <nikhil.navakiran@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Nikhil Chitlur Navakiran (from Dev Box) <nikhilc@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope classes used
parent_id: str(W3C traceparent format) for linking spans. This should use OpenTelemetry's nativeContextobject and expose methods for context propagation headers.Changes
API Changes
parent_context: Context | Noneinstead ofparent_id: str | Noneinject_trace_context()→ returns W3C trace headers for downstream propagationget_context()→ returns scope's Context for passing to child scopesextract_trace_context(headers)utility using OTel's standardextract()InvokeAgentScopenow supportsparent_context(was previously missing)Removed
parse_parent_id_to_context) — delegated to OTelUsage