Skip to content

feat: OpenTelemetry instrumentation + Agent365 baggage support#475

Draft
rido-min wants to merge 4 commits intomainfrom
feature/observability-otel-baggage
Draft

feat: OpenTelemetry instrumentation + Agent365 baggage support#475
rido-min wants to merge 4 commits intomainfrom
feature/observability-otel-baggage

Conversation

@rido-min
Copy link
Copy Markdown
Member

@rido-min rido-min commented May 4, 2026

Summary

  • 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 SDK pipeline. Each layer owns its own source: Core → Microsoft.Teams.Core, Apps → Microsoft.Teams.Apps.
  • Adds two layer-specific BaggageBuilder classes for Agent365 export (same name in different namespaces, no inheritance). Core's reads from CoreActivity / ConversationAccount with a channelData.tenant.id JSON fallback; Apps's adds the TeamsConversationAccount-backed keys (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 the Core layer can populate microsoft.tenant.id without Apps-layer dependencies.
  • Adds the design doc at 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 at core/samples/ObservabilityBot/ that wires 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; transitive on every Microsoft.OpenTelemetry consumer).

Test plan

  • dotnet build clean on net8.0 + net10.0 for Microsoft.Teams.Core, Microsoft.Teams.Apps, Microsoft.Teams.Apps.BotBuilder, and samples/ObservabilityBot.
  • dotnet test core/test/Microsoft.Teams.Core.UnitTests111 passing on both TFMs (96 baseline + 15 new for telemetry / baggage).
  • dotnet test core/test/Microsoft.Teams.Apps.UnitTests161 passing on both TFMs (152 baseline + 9 new for handler span / baggage).
  • dotnet test core/test/Microsoft.Teams.Apps.BotBuilder.UnitTests41 passing (no regressions).
  • Smoke-run samples/ObservabilityBot — Microsoft.OpenTelemetry distro 1.0.1 boots cleanly, log records flow through OTel with the full resource bag.
  • End-to-end Agent365 export validation against a real tenant (deferred — no Agent365 credentials in this environment).

🤖 Generated with Claude Code

rido-min and others added 4 commits May 4, 2026 18:15
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant