Skip to content

Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142

Merged
moonbox3 merged 10 commits intomicrosoft:mainfrom
droideronline:dinesh/github-copilot-otel-integration
Apr 24, 2026
Merged

Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142
moonbox3 merged 10 commits intomicrosoft:mainfrom
droideronline:dinesh/github-copilot-otel-integration

Conversation

@droideronline
Copy link
Copy Markdown
Contributor

@droideronline droideronline commented Apr 7, 2026

Summary

Adds OpenTelemetry tracing support for GitHubCopilotAgent following the same pattern used by ClaudeAgent and FoundryAgent.

  • Split GitHubCopilotAgent into RawGitHubCopilotAgent (core, no OTel) and GitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent) (OTel-enabled, recommended)
  • Add default_options property to expose the configured model name in span attributes
  • Export RawGitHubCopilotAgent from agent_framework.github and agent_framework_github_copilot
  • Add github_copilot_with_observability.py sample and update README with OTel environment variables

Closes #5141

Test plan

  • All existing unit tests pass (uv run poe test - 77 passed)
  • Lint passes (uv run poe lint)
  • Pyright passes (uv run poe pyright - 0 errors)
  • Mypy passes (uv run mypy - no issues)
  • New sample file lints cleanly

Notes

  • GitHubCopilotAgent remains the default import; existing code is unaffected
  • RawGitHubCopilotAgent.run() accepts **kwargs to absorb extra parameters passed by AgentTelemetryLayer (e.g., compaction_strategy, tokenizer)
  • The default_options property merges model from _settings so it appears in OTel span attributes

Copilot AI review requested due to automatic review settings April 7, 2026 09:30
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels Apr 7, 2026
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 OpenTelemetry tracing support for the Python GitHubCopilotAgent by aligning it with the framework’s established “Raw* + telemetry-enabled wrapper” pattern and updating the GitHub Copilot SDK integration accordingly.

Changes:

  • Split the agent into RawGitHubCopilotAgent (core) and GitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent) (instrumented).
  • Bump github-copilot-sdk dependency to >=0.2.0,<0.3.0 and update call sites for the SDK’s updated APIs/types.
  • Add an observability sample + README updates documenting OTel environment variables.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/uv.lock Updates locked dependencies, including github-copilot-sdk to 0.2.x.
python/packages/github_copilot/pyproject.toml Bumps github-copilot-sdk requirement to >=0.2.0,<0.3.0.
python/packages/github_copilot/agent_framework_github_copilot/_agent.py Introduces RawGitHubCopilotAgent and an OTel-enabled GitHubCopilotAgent wrapper; updates SDK calls for 0.2.x.
python/packages/github_copilot/agent_framework_github_copilot/init.py Exports RawGitHubCopilotAgent from the package public surface.
python/packages/core/agent_framework/github/init.py Adds RawGitHubCopilotAgent to the lazy re-export mapping.
python/packages/core/agent_framework/github/init.pyi Adds RawGitHubCopilotAgent to typing exports.
python/packages/github_copilot/tests/test_github_copilot_agent.py Updates tests for SDK 0.2.x API/type changes and updated call signatures.
python/scripts/sample_validation/create_dynamic_workflow_executor.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/README.md Documents OTel environment variables and links to the new observability sample.
python/samples/02-agents/providers/github_copilot/github_copilot_basic.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_file_operations.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_mcp.py Updates permission/mcp config imports for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_multiple_permissions.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_session.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_shell.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_url.py Updates permission result import for SDK 0.2.x.
python/samples/02-agents/providers/github_copilot/github_copilot_with_observability.py New sample demonstrating configure_otel_providers() with GitHubCopilotAgent.

Comment thread python/samples/02-agents/providers/github_copilot/README.md Outdated
@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch from 28955c8 to 60d9177 Compare April 7, 2026 09:38
@droideronline
Copy link
Copy Markdown
Contributor Author

Waiting for #5107 to be merged

@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch 2 times, most recently from 6c50266 to 42680ad Compare April 10, 2026 07:26
@droideronline
Copy link
Copy Markdown
Contributor Author

@moonbox3 @eavanvalkenburg @chetantoshniwal - could you please review this PR when you get a chance? Branch has been rebased on latest main and all tests pass (80/80). Thanks!

Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 10, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/github_copilot/agent_framework_github_copilot
   _agent.py2821395%44–45, 51, 70, 385, 400–401, 676–677, 692, 695, 762, 787
TOTAL29173344388% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5859 30 💤 0 ❌ 0 🔥 1m 34s ⏱️

Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
Comment thread python/samples/02-agents/providers/github_copilot/README.md Outdated
@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch from 126d3c4 to 21022fd Compare April 13, 2026 11:54
Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

one final thing needed, otherwise good to go

@eavanvalkenburg
Copy link
Copy Markdown
Member

@droideronline we do have a failing test, from this update, please have a look

auto-merge was automatically disabled April 13, 2026 14:10

Head branch was pushed to by a user without write access

@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch from 6700fb2 to fbac838 Compare April 13, 2026 17:39
@droideronline
Copy link
Copy Markdown
Contributor Author

@eavanvalkenburg @moonbox3 — while working on this PR, I discovered a bug in the core OTel layer: _finalize_stream in observability.py unconditionally calls get_final_response() even when the stream errors, which triggers result hooks (e.g. _run_after_providers) on error paths incorrectly. This affects all agents with OTel enabled, not just GitHub Copilot.

This was also the root cause of test_after_run_not_called_on_streaming_error failing in CI — when ENABLE_INSTRUMENTATION=true leaks between xdist workers, _finalize_stream fires get_final_response() on the errored stream, which in turn triggers the after_run hook unexpectedly.

I've filed the details in #5231 and raised a fix in #5232. Would appreciate a look when you get a chance.

@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch from fbac838 to b8f1d98 Compare April 14, 2026 10:00
@droideronline
Copy link
Copy Markdown
Contributor Author

@eavanvalkenburg @moonbox3 the branch is now rebased on the latest main and all tests pass, including test_after_run_not_called_on_streaming_error with ENABLE_INSTRUMENTATION=true. Could you please take a look when you get a chance?

@droideronline
Copy link
Copy Markdown
Contributor Author

@eavanvalkenburg @moonbox3 the core fix from #5232 has now been merged and the branch is freshly rebased. Could you please take one more look?

@droideronline
Copy link
Copy Markdown
Contributor Author

droideronline commented Apr 17, 2026

@moonbox3 @eavanvalkenburg - I'd appreciate if we can take a look again please. thanks

@droideronline
Copy link
Copy Markdown
Contributor Author

@moonbox3 @eavanvalkenburg - I'd appreciate if we can get this before our next release, we are in need of this. thanks

Copy link
Copy Markdown
Contributor

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 87%

✓ Correctness

This PR cleanly refactors GitHubCopilotAgent into a layered architecture by extracting a RawGitHubCopilotAgent (no telemetry) and composing GitHubCopilotAgent via MRO with AgentMiddlewareLayer and AgentTelemetryLayer. The MRO order is intentionally reversed from the Agent class to place middleware outside the telemetry span. The init chain, run() chain, and default_options property all work correctly through the MRO. Tests are well-constructed. No blocking correctness issues found.

✓ Security Reliability

This PR refactors GitHubCopilotAgent into a two-layer design: RawGitHubCopilotAgent (core) and GitHubCopilotAgent (with middleware + telemetry via MRO). The MRO chain, init parameter forwarding, and default_options property are implemented correctly. The middleware-outside-telemetry ordering is intentional and documented. No security or reliability issues found. One minor type annotation inconsistency noted.

✓ Test Coverage

The PR refactors GitHubCopilotAgent into a RawGitHubCopilotAgent base class and a new GitHubCopilotAgent composed via MRO with AgentMiddlewareLayer and AgentTelemetryLayer. Three new tests cover the default_options property, which is good. However, the newly exported RawGitHubCopilotAgent class has zero direct test coverage (confirmed: 0 occurrences in test files), and there is no integration test verifying that the MRO-based middleware/telemetry layer composition actually invokes the layers during run() — which is the primary architectural change in this PR.

✗ Design Approach

The telemetry wrapper is a reasonable direction, but the middleware approach is not wired through correctly. The new GitHubCopilotAgent advertises full middleware support by inheriting AgentMiddlewareLayer, yet the underlying Copilot implementation drops the forwarded middleware kwarg and invokes tools directly, so chat/function middleware are silently ignored instead of participating in execution. That makes the public API broader than the implementation and is worth fixing before release.


Automated review by moonbox3's agents

Comment thread python/packages/github_copilot/tests/test_github_copilot_agent.py
droideronline and others added 7 commits April 23, 2026 19:05
- Split GitHubCopilotAgent into RawGitHubCopilotAgent (core, no OTel) and
  GitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent) with tracing
- Add default_options property to expose model for span attributes
- Export RawGitHubCopilotAgent from all public namespaces
- Add github_copilot_with_observability.py sample and update README
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add middleware param to GitHubCopilotAgent.run() overloads so per-call
  middleware is explicitly forwarded through AgentTelemetryLayer
- Remove github_copilot_with_observability.py sample per feedback; replace
  with inline snippet + link to observability samples in README
- Add middleware param to RawGitHubCopilotAgent.run() overloads for interface
  compatibility with AgentTelemetryLayer
- Fix import in README observability snippet to use agent_framework.github
Follow FoundryAgent pattern: AgentMiddlewareLayer runs outside the telemetry
span so middleware execution time is not captured in traces. Overloads removed
as AgentMiddlewareLayer.run() handles dispatch via MRO.
@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch from 28122d1 to 295976f Compare April 23, 2026 13:35
…ions

- Add assert "timeout" not in opts to test_default_options_includes_model_for_telemetry
  to document the intentional asymmetry where timeout is extracted into _settings
  and not returned in default_options.
- Replace silent del middleware with a logged warning when per-run middleware is
  passed to RawGitHubCopilotAgent, making it clear that the GitHub Copilot SDK
  handles tool execution internally and chat/function middleware cannot be injected.
@droideronline droideronline requested a review from moonbox3 April 23, 2026 13:39
Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

Small comment left, otherwise good to go

Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
Address review feedback: use typing.Self (3.11+) / typing_extensions.Self
(3.10) for __aenter__ so subclasses like GitHubCopilotAgent get the correct
return type from async context manager usage.
@moonbox3 moonbox3 added this pull request to the merge queue Apr 24, 2026
Merged via the queue into microsoft:main with commit 63c0a51 Apr 24, 2026
33 checks passed
moonbox3 added a commit to moonbox3/agent-framework that referenced this pull request Apr 24, 2026
Previous commit incorrectly renamed the [1.1.1] header to [1.2.0], which
wiped the historical 1.1.1 entries and wrongly attributed them to 1.2.0.
This restores [1.1.1] to its origin/main content and adds a new [1.2.0]
section above containing only the commits in python-1.1.1..HEAD:

- microsoft#4238 functional workflow API
- microsoft#5142 GitHub Copilot OpenTelemetry
- microsoft#2403 A2A bridge support
- microsoft#5070 oauth_consent_request events in Foundry clients
- microsoft#5447 FoundryAgent hosted agent sessions
- microsoft#5459 hosting server dependency upgrade + types
- microsoft#5389 AG-UI reasoning/multimodal parsing fix
- microsoft#5440 stop [TOOLBOXES] warning spam
- microsoft#5455 user agent prefix fix

Also corrects the [1.2.0] compare base to python-1.1.1 (not 1.1.0) and
adds the missing [1.1.1] reference link.
moonbox3 added a commit that referenced this pull request Apr 24, 2026
* Bump Python package versions for 1.2.0 release

Released tier bumps 1.1.1 -> 1.2.0 (core, openai, foundry, root) to
reflect additive public APIs landed since 1.1.0: functional workflow API
(#4238) and FunctionTool SKIP_PARSING sentinel (#5424). All beta packages
stamped 1.0.0b260424, alpha packages 1.0.0a260424. All 26 non-core
agent-framework-core floors raised to >=1.2.0,<2. CHANGELOG consolidates
the never-tagged 1.1.1 entries with the post-merge additions into [1.2.0].

* Update CHANGELOG footer links for 1.2.0

Advance [Unreleased] comparison base from python-1.1.0 to python-1.2.0
and add a [1.2.0] reference link comparing python-1.1.0...python-1.2.0
so the heading links resolve correctly.

* Fix CHANGELOG: restore [1.1.1] section and add proper [1.2.0]

Previous commit incorrectly renamed the [1.1.1] header to [1.2.0], which
wiped the historical 1.1.1 entries and wrongly attributed them to 1.2.0.
This restores [1.1.1] to its origin/main content and adds a new [1.2.0]
section above containing only the commits in python-1.1.1..HEAD:

- #4238 functional workflow API
- #5142 GitHub Copilot OpenTelemetry
- #2403 A2A bridge support
- #5070 oauth_consent_request events in Foundry clients
- #5447 FoundryAgent hosted agent sessions
- #5459 hosting server dependency upgrade + types
- #5389 AG-UI reasoning/multimodal parsing fix
- #5440 stop [TOOLBOXES] warning spam
- #5455 user agent prefix fix

Also corrects the [1.2.0] compare base to python-1.1.1 (not 1.1.0) and
adds the missing [1.1.1] reference link.
learn-build-service-prod Bot pushed a commit to MicrosoftDocs/semantic-kernel-docs that referenced this pull request Apr 27, 2026
* Sync Agent Framework Python docs for PRs since 2026-04-22

Updates docs to reflect changes in microsoft/agent-framework Python PRs
merged after MicrosoftDocs/semantic-kernel-pr#982 (2026-04-22).

- get-started/workflows.md, AGENTS.md: rename
  01-get-started/05_first_workflow.py -> 07_first_graph_workflow.py
  (microsoft/agent-framework#4238).
- integrations/a2a.md: add Python section 'Exposing an Agent Framework
  agent over A2A' documenting A2AExecutor and the new
  agent_framework_to_a2a.py sample (microsoft/agent-framework#2403).
- agents/providers/github-copilot.md: add Observability subsection in
  Python zone showing configure_otel_providers() and
  RawGitHubCopilotAgent (microsoft/agent-framework#5142).
- agents/providers/microsoft-foundry.md: add 'Connecting to a deployed
  (hosted) Foundry agent' subsection covering allow_preview=True / v2
  and explicit AIProjectClient session creation
  (microsoft/agent-framework#5447).
- integrations/hyperlight.md: note that result_parser does not run on
  the sandbox path; tools must format in-sandbox themselves
  (microsoft/agent-framework#5424).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Defer #4238 (functional workflow API) doc updates to PR author

Revert the get-started/workflows.md sample rename and the AGENTS.md
mapping update. The author of microsoft/agent-framework#4238 will
handle the docs (rename + new functional workflow page) in a
dedicated follow-up.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Add OpenTelemetry integration for GitHubCopilotAgent

4 participants