Skip to content

Add OpenTelemetry HTTP middleware - #513

Closed
heyitsaamir wants to merge 8 commits into
feature_agent365_supportfrom
heyitsaamir-python-otel-diagnostics
Closed

Add OpenTelemetry HTTP middleware#513
heyitsaamir wants to merge 8 commits into
feature_agent365_supportfrom
heyitsaamir-python-otel-diagnostics

Conversation

@heyitsaamir

Copy link
Copy Markdown
Collaborator

Adds the first cut of OpenTelemetry observability across the Python Teams SDK runtime.

Why

This gives developers a real trace through the SDK: inbound activity → handler → outbound Teams API call → auth. Makes it way easier to debug whether Teams called us, whether the handler ran, whether we sent the reply, and which auth flow was used.

It also sets up the Agent 365 story. Teams SDK spans are the useful diagnostic detail; Agent 365 product visibility still comes from explicit A365 scopes like invoke_agent / execute_tool / chat.

Interesting bits

  • Adds public common HTTP middleware support so API telemetry can wrap auth + transport cleanly.
  • Adds API outbound telemetry middleware for microsoft.teams.api.client.
  • Emits microsoft.teams.auth.outbound from the API auth token callback.
  • Adds Apps spans/metrics for microsoft.teams.activity.process and microsoft.teams.handler.
  • Adds Agent365-compatible baggage from inbound Teams activities.
  • Adds package version as the OTel instrumentation scope version for Microsoft.Teams.Api and Microsoft.Teams.Apps.
  • Keeps the generic HTTP middleware mechanics-only. Client methods own semantic attrs and response hooks.
  • Restores compatibility for public service_url / agentic_identity scoping kwargs, HttpServer exports, skip_auth, and explicit/default Authorization header behavior after the middleware refactor.

TS/Python intentionally differ from .NET right now: .NET still has Core-shaped names like Microsoft.Teams.Core, turn, and conversation_client. This PR uses the newer API/Apps split and microsoft.teams.api.client middleware model.

Reviewer tips

Start with common HTTP middleware, then API outbound middleware, then conversation activity methods that attach semantic attrs/hooks. The compatibility commits are worth reviewing too: they preserve per-call service URL / agentic identity behavior and legacy app/http server surface.

Testing

  • Ruff, format, and pyright passed on affected files.
  • Targeted pytest suites passed, including common HTTP client, diagnostics, conversation client, app, and HTTP server tests.
  • Live Teams smokes passed for Agent365 / ACF and Echo / PokemonCatcher.
  • Aspire inspection confirmed traces + metrics, expected span nesting, API/auth spans, and response-derived activity IDs.
  • Fixed issues found during smoke/review: API/auth spans now use client span kind, compatibility surfaces are restored, and direct conversation activity clients now respect per-call agentic identity.

heyitsaamir and others added 8 commits July 18, 2026 09:24
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 193946ff-3efa-4820-8e7d-0cea257aa1c2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 193946ff-3efa-4820-8e7d-0cea257aa1c2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 193946ff-3efa-4820-8e7d-0cea257aa1c2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 193946ff-3efa-4820-8e7d-0cea257aa1c2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0d367487-e88d-4423-8016-475637d47ed0
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 193946ff-3efa-4820-8e7d-0cea257aa1c2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0d367487-e88d-4423-8016-475637d47ed0
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0d367487-e88d-4423-8016-475637d47ed0
@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

Superseded by the Git Spice stack:\n\n1. API layer: https://github.com/microsoft/teams.py/pull/514\n2. Apps layer: https://github.com/microsoft/teams.py/pull/515\n3. Docs/examples layer: https://github.com/microsoft/teams.py/pull/516\n\nClosing this large PR so review can happen layer-by-layer.

@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

Superseded by stacked PRs #514, #515, and #516.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant