Skip to content

Python: Add OpenTelemetry integration for GitHubCopilotAgent#5142

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

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

droideronline and others added 8 commits April 5, 2026 23:31
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
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 on lines +296 to +308
@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
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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
@droideronline droideronline force-pushed the dinesh/github-copilot-otel-integration branch from 28955c8 to 60d9177 Compare April 7, 2026 09:38
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@droideronline
Copy link
Copy Markdown
Contributor Author

Waiting for #5107 to be merged

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

3 participants