Skip to content

Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142

Open
droideronline wants to merge 4 commits intomicrosoft:mainfrom
droideronline:dinesh/github-copilot-otel-integration
Open

Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142
droideronline wants to merge 4 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.

@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 from f8d4872 to d1361bf Compare April 9, 2026 18:33
droideronline and others added 3 commits April 10, 2026 12:56
- 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>
@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch 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!

)


class GitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent[OptionsT], Generic[OptionsT]):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should probably also add the middleware layer here? and I think that is not applied properly in all agents, I will fix that, but telemetry should be inside the middleware so that the time spent on middleware is not captured by the telemtry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch - added middleware explicitly to GitHubCopilotAgent.run() overloads and forwarded it through to super().run() so it reaches AgentTelemetryLayer properly. Agree on the ordering concern - leaving that for your broader fix across agents.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need a separate sample, just add a note in the sample readme here, that telemtry is enabled and refer to the observability samples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done - removed the separate sample file and replaced it with an inline snippet + link to the observability samples in the README.

@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.py2761295%38–39, 45, 64, 374–375, 650–651, 666, 669, 736, 759
TOTAL27213318488% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5442 20 💤 0 ❌ 0 🔥 1m 23s ⏱️

- 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
)


class GitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent[OptionsT], Generic[OptionsT]):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this also then need the middleware layer!

| `OTEL_EXPORTER_OTLP_PROTOCOL` | Protocol: `grpc` or `http/protobuf` | `grpc` |
```python
from agent_framework.observability import configure_otel_providers
from agent_framework_github_copilot import GitHubCopilotAgent
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
from agent_framework_github_copilot import GitHubCopilotAgent
from agent_framework.github import GitHubCopilotAgent

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