Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142
Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142droideronline wants to merge 11 commits intomicrosoft:mainfrom
Conversation
Replace all imports from the non-existent copilot.types module with correct SDK 0.2.x module paths (copilot.session, copilot.client, copilot.tools, copilot.generated.session_events). Fix PermissionRequest attribute access from dict-style .get() to dataclass attribute access. Add OTel telemetry support to Copilot samples via configure_otel_providers and document new telemetry environment variables in samples README.
…tures - Remove RawGitHubCopilotAgent split and AgentTelemetryLayer inheritance - Remove TelemetryConfig plumbing and OTLP/file telemetry settings - Remove configure_otel_providers() calls from samples - Remove telemetry env var rows from samples README - Retain only: import path fixes, PermissionRequest attribute access fix, log_level default fix, session kwargs typed fix, dependency pin
- SubprocessConfig replaces CopilotClientOptions dict - create_session and resume_session now use keyword args - send and send_and_wait take plain string prompt instead of MessageOptions - on_permission_request is always required; deny-all fallback replaces omission
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. |
| @property | ||
| def default_options(self) -> dict[str, Any]: | ||
| """Expose default options including model from settings. | ||
|
|
||
| Returns a merged dict of ``_default_options`` with the resolved ``model`` | ||
| from settings injected under the ``model`` key. This is read by | ||
| :class:`AgentTelemetryLayer` to include the model name in span attributes. | ||
| """ | ||
| opts = dict(self._default_options) | ||
| model = self._settings.get("model") | ||
| if model: | ||
| opts["model"] = model | ||
| return opts |
There was a problem hiding this comment.
default_options was added/changed to merge the resolved model from settings so AgentTelemetryLayer can emit it as a span attribute, but there’s no unit test asserting this property’s behavior (e.g., that default_options["model"] reflects the configured model and that other defaults are preserved). Adding a focused test would protect the new telemetry integration from regressions during future SDK/agent refactors.
Tighten the upper bound from <0.3.0 to <=0.2.0 to avoid pulling in 0.2.1+ which has breaking API changes relative to 0.2.0. The lower bound stays at >=0.2.0 since this migration requires the 0.2.x import paths; 0.1.x would fail at import time.
- 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
28955c8 to
60d9177
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Waiting for #5107 to be merged |
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