feat: OpenTelemetry instrumentation + Agent365 baggage support#475
Draft
feat: OpenTelemetry instrumentation + Agent365 baggage support#475
Conversation
Emits per-turn ActivitySource spans (turn / middleware / handler / auth.outbound / conversation_client) and Meter instruments (teams.activities.received, teams.turn.duration, teams.handler.errors, teams.middleware.duration, teams.outbound.calls, teams.outbound.errors) from the Teams SDK pipeline so consuming bots can wire telemetry through the Microsoft OpenTelemetry distro. Layering: Core publishes "Microsoft.Teams.Core" source/meter (turn / middleware / auth.outbound / conversation_client); Apps publishes "Microsoft.Teams.Apps" source for the handler span. Each layer owns its own ActivitySource without cross-references. Adds two layer-specific BaggageBuilder classes for Agent365 export (same name in different namespaces, no inheritance): Core's reads from CoreActivity / ConversationAccount with channelData.tenant.id JSON fallback; Apps's adds the keys backed by TeamsConversationAccount (user.id, user.email, microsoft.agent.user.email, gen_ai.agent.description) and uses typed TeamsChannelData for the tenant fallback. Promotes TenantId to a typed property on Core's ConversationAccount so core/observability stays free of Apps-layer dependencies for cert attribute coverage. Adds the design doc at core/docs/Observability-Design.md (layering constraints, span/metric maps, crisp Agent365 cert definition with per-scope attribute tables, channel/sub-channel resolution) and a runnable sample at core/samples/ObservabilityBot/ wiring UseMicrosoftOpenTelemetry with OTLP export. Picks up one new package dep on Microsoft.Teams.Core: OpenTelemetry.Api 1.15.3 (lightweight contract package needed for OpenTelemetry.Baggage.Current). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces TeamsCoreTelemetry with CoreTelemetryNames for ActivitySource and Meter names. Integrates OpenTelemetry tracing/metrics and Azure OpenAI chat client in Program.cs. Adds ModelContextProtocol tools and citation processing. Updates dependencies and unit tests to use new telemetry naming.
Updated target framework to net10.0 and upgraded Microsoft.OpenTelemetry to 1.0.2. Enabled S2S endpoint for Agent365 exporter and adjusted TokenResolver to use the correct API scope and return the token without the "Bearer" prefix.
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.
Summary
ActivitySourcespans (turn/middleware/handler/auth.outbound/conversation_client) andMeterinstruments (teams.activities.received,teams.turn.duration,teams.handler.errors,teams.middleware.duration,teams.outbound.calls,teams.outbound.errors) from the SDK pipeline. Each layer owns its own source: Core →Microsoft.Teams.Core, Apps →Microsoft.Teams.Apps.BaggageBuilderclasses for Agent365 export (same name in different namespaces, no inheritance). Core's reads fromCoreActivity/ConversationAccountwith achannelData.tenant.idJSON fallback; Apps's adds theTeamsConversationAccount-backed keys (user.id,user.email,microsoft.agent.user.email,gen_ai.agent.description) and uses typedTeamsChannelDatafor the tenant fallback.TenantIdto a typed property on Core'sConversationAccountso the Core layer can populatemicrosoft.tenant.idwithout Apps-layer dependencies.core/docs/Observability-Design.md(layering rules, span/metric maps, crisp Agent365 cert definition with per-scope attribute tables, Channel/SubChannel mapping resolution) and a runnable sample atcore/samples/ObservabilityBot/that wiresUseMicrosoftOpenTelemetrywith OTLP export.Microsoft.Teams.Core:OpenTelemetry.Api1.15.3 (lightweight contract package — needed forOpenTelemetry.Baggage.Current; transitive on everyMicrosoft.OpenTelemetryconsumer).Test plan
dotnet buildclean onnet8.0+net10.0forMicrosoft.Teams.Core,Microsoft.Teams.Apps,Microsoft.Teams.Apps.BotBuilder, andsamples/ObservabilityBot.dotnet test core/test/Microsoft.Teams.Core.UnitTests— 111 passing on both TFMs (96 baseline + 15 new for telemetry / baggage).dotnet test core/test/Microsoft.Teams.Apps.UnitTests— 161 passing on both TFMs (152 baseline + 9 new for handler span / baggage).dotnet test core/test/Microsoft.Teams.Apps.BotBuilder.UnitTests— 41 passing (no regressions).samples/ObservabilityBot— Microsoft.OpenTelemetry distro 1.0.1 boots cleanly, log records flow through OTel with the full resource bag.🤖 Generated with Claude Code