Add OpenTelemetry API middleware - #514
Merged
heyitsaamir merged 2 commits intoJul 22, 2026
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0d367487-e88d-4423-8016-475637d47ed0
This was referenced Jul 20, 2026
corinagum
approved these changes
Jul 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OpenTelemetry-based outbound diagnostics plumbing to the Teams API client stack by introducing a common HTTP middleware pipeline and attaching outbound/auth spans + metrics from API client operations.
Changes:
- Added a public middleware mechanism to the common HTTP client and refactored request dispatch through a middleware pipeline.
- Introduced Teams API diagnostics helpers/constants plus outbound telemetry middleware and auth-token span recording.
- Updated conversation activity APIs to preserve existing service URL / agentic identity scoping while routing through the new telemetry + token callback paths.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds opentelemetry-api to the workspace lock for the API package. |
| packages/common/tests/test_client.py | Adds unit tests covering middleware behavior, ordering, mutation, and metadata stripping. |
| packages/common/src/microsoft_teams/common/http/client.py | Implements middleware types, registration, cloning, and the _send() dispatch pipeline. |
| packages/common/src/microsoft_teams/common/http/init.py | Exports new middleware types from the common HTTP module. |
| packages/api/tests/unit/test_diagnostics.py | Adds tests for exported telemetry names and basic diagnostics helper behavior. |
| packages/api/tests/unit/test_conversation_client.py | Extends tests for scoping compatibility and validates outbound/auth telemetry behavior. |
| packages/api/tests/unit/test_base_client.py | Adds tests ensuring outbound telemetry middleware is registered once and auth spans are recorded. |
| packages/api/src/microsoft_teams/api/models/account.py | Extends the Account model with additional optional fields (email, user_role). |
| packages/api/src/microsoft_teams/api/diagnostics/_telemetry.py | Defines canonical tracer/meter names and instrumentation version for the API package. |
| packages/api/src/microsoft_teams/api/diagnostics/_outbound.py | Adds outbound telemetry middleware and a metadata carrier for per-call attributes/hooks. |
| packages/api/src/microsoft_teams/api/diagnostics/_helpers.py | Adds tracer/meter helpers plus outbound counters and exception recording utilities. |
| packages/api/src/microsoft_teams/api/diagnostics/_constants.py | Defines internal constants for attribute keys, metric names, operation names, and span names. |
| packages/api/src/microsoft_teams/api/diagnostics/init.py | Exposes public telemetry naming API via __all__. |
| packages/api/src/microsoft_teams/api/clients/user/client.py | Ensures outbound telemetry middleware is installed when HTTP client is set. |
| packages/api/src/microsoft_teams/api/clients/conversation/client.py | Adds service URL/agentic identity kwargs and scoped-client routing while ensuring telemetry middleware. |
| packages/api/src/microsoft_teams/api/clients/conversation/activity.py | Adds per-operation telemetry metadata and response hooks for activity id tagging + scoped routing. |
| packages/api/src/microsoft_teams/api/clients/bot/client.py | Ensures outbound telemetry middleware is installed when HTTP client is set. |
| packages/api/src/microsoft_teams/api/clients/base_client.py | Ensures outbound telemetry middleware is installed at construction and on HTTP reassignment. |
| packages/api/src/microsoft_teams/api/clients/api_client.py | Wraps auth provider token resolution in an auth outbound span and wires conversation scoping factory. |
| packages/api/src/microsoft_teams/api/init.py | Re-exports diagnostics from the top-level API package. |
| packages/api/pyproject.toml | Adds opentelemetry-api to the API package dependencies. |
Review details
- Files reviewed: 20/21 changed files
- Comments generated: 2
- Review effort level: Low
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0d367487-e88d-4423-8016-475637d47ed0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the API-side plumbing for Teams SDK OpenTelemetry: common HTTP middleware, outbound API spans, and auth spans.
Why
This is the foundation layer. It lets us see what the SDK is doing when it calls Teams APIs: which operation ran, which auth flow was used, whether the call failed, and how it lines up under the app’s trace.
Keeping this in the API/common layer also means Apps can stay focused on inbound activity processing instead of knowing HTTP client internals. Nice little separation of concerns, for once.
Interesting bits
microsoft.teams.api.clientfor outbound Teams API calls.microsoft.teams.auth.outboundfrom the API auth token callback.Microsoft.Teams.Apias the instrumentation scope, with the package version attached as the scope version.activity.id.Reviewer tips
Start with common HTTP client middleware, then the API outbound middleware, then conversation activity methods. The compatibility bits are worth a close look because they keep old scoping behavior working while routing through the new token callback path.
Testing
CI is green for this layer. The full stack was also live-smoked against Agent365/ACF and Echo/PokemonCatcher before splitting.