Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142
Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142droideronline wants to merge 4 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
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) andGitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent)(instrumented). - Bump
github-copilot-sdkdependency to>=0.2.0,<0.3.0and 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. |
28955c8 to
60d9177
Compare
|
Waiting for #5107 to be merged |
f8d4872 to
d1361bf
Compare
- 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>
6c50266 to
42680ad
Compare
|
@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]): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done - removed the separate sample file and replaced it with an inline snippet + link to the observability samples in the README.
- 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]): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| from agent_framework_github_copilot import GitHubCopilotAgent | |
| from agent_framework.github import GitHubCopilotAgent |
Summary
Adds OpenTelemetry tracing support for
GitHubCopilotAgentfollowing the same pattern used byClaudeAgentandFoundryAgent.GitHubCopilotAgentintoRawGitHubCopilotAgent(core, no OTel) andGitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent)(OTel-enabled, recommended)default_optionsproperty to expose the configured model name in span attributesRawGitHubCopilotAgentfromagent_framework.githubandagent_framework_github_copilotgithub_copilot_with_observability.pysample and update README with OTel environment variablesCloses #5141
Test plan
uv run poe test- 77 passed)uv run poe lint)uv run poe pyright- 0 errors)uv run mypy- no issues)Notes
GitHubCopilotAgentremains the default import; existing code is unaffectedRawGitHubCopilotAgent.run()accepts**kwargsto absorb extra parameters passed byAgentTelemetryLayer(e.g.,compaction_strategy,tokenizer)default_optionsproperty mergesmodelfrom_settingsso it appears in OTel span attributes