/agent365:instrument-observability Optional: path to agent project, or framework hint (dotnet|nodejs|python)from agent365
Instruments Microsoft Agent 365 observability into .NET, Node.js, or Python agents with OTel tracing, context propagation, and A365 exporter. Adds required instrumentation scopes for store publishing.
Ships in agent365. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Trigger phrases — any of these will activate this skill automatically:
- "instrument observability for this agent"
- "add a365 observability to this agent"
- "add observability to this agent"
- "set up tracing for this agent"
- "make this agent visible in microsoft defender"
- "enable agent 365 telemetry"
- "wire up opentelemetry for this agent"
- "add observability to this .net agent"
- "add observability to this node.js agent"
- "add a365 observability to this python agent"
This skill instruments Microsoft Agent 365 observability into an existing agent codebase without disrupting the agent's core logic. It:
Store publishing requirement: The Agent 365 store validation requires
InvokeAgentScope,InferenceScope, andExecuteToolScopeto be implemented. This skill wires them.
All changes are additive and idempotent — rerunning the skill is safe. The one exception is legacy delegated telemetry wiring, which this skill replaces (see "Migrating delegated telemetry" in Phase 3).
Telemetry is always exported over the S2S route with an app-only token for the exporting agent identity, whatever the
authMode. The S2S route rejects delegated (scp) tokens, so OBO / Agentic User tokens are used only for workload calls (MCP / Graph), never for the exporter. Registered blueprint agent instances need noAgent365.Observability.OtelWritepermission or admin consent (subject to service policy), and neither do AI Teammates, which the route authorizes by their Blueprint's registration. Newera365 setup allversions skip that grant for both; older versions may still grant it, or print anOtelWriteapplication-role action item for AI Teammates, and completing it is harmless.
Task-list display (applies throughout this skill). This skill creates tasks inline via
**TaskCreate** — "..."markers at the start of each phase, and marks them complete at phase end. The user must see this progress visibly. EachTaskCreateline corresponds to one checklist item; exactly one item in_progress at a time.
- Claude Code:
TaskCreateis inallowed-tools— calling it renders a native checklist UI; subsequentTaskUpdatecalls flip statuses.- VS Code Copilot Chat / GitHub Copilot CLI:
allowed-toolsis ignored — before Phase 0.1, scan this SKILL.md for all**TaskCreate** — "..."lines and emit a markdown checklist in chat upfront (- [ ] Load detection cache…,- [ ] Determine agent kind…, etc.); flip items to- [x]as each phase completes.
TaskCreate — "Load detection cache and validate with user"
Run in parallel:
**/*.csproj, package.json, requirements.txt, pyproject.toml, src/**/*.ts, **/*.cs, **/*.py → hasProjectFiles..a365-workspace-detection.local.json → cacheState (fresh if detectedAt < 60 min, stale if older, missing if absent).Decide:
cacheState | hasProjectFiles | Action |
|---|---|---|
fresh | — | Continue to Step 0.2 below. |
missing / stale | false | Hard stop with a useful message: "This skill instruments an existing agent for observability — there's no agent code in this workspace yet. Run /agent365:make-ai-teammate (if this will be a Teams/Copilot agent) or /agent365:make-a365-agent first to scaffold and register the agent, then come back here." Do not proceed. |
missing / stale | true | Tell the user: "Found existing agent code but no fresh Agent 365 registration. I'll run a365-setup now to register it and write the detection cache, then continue here automatically." Read ${CLAUDE_PLUGIN_ROOT}/skills/a365-setup/SKILL.md and follow it through completion, then continue to Step 0.2. |
🛑 STOP — .a365-workspace-detection.local.json MUST exist before this step. Read the file path .a365-workspace-detection.local.json in the working directory. If it does not exist, you arrived at Step 0.2 by skipping Step 0.1's triage routing. Do NOT proceed. Do NOT invent default cache values. Do NOT run any further phase (no npm install, no dotnet add package, no pip install, no file edits). Instead:
a365-setup now to fix that, then I'll return here."${CLAUDE_PLUGIN_ROOT}/skills/a365-setup/SKILL.md and follow it to completion.The stop hook (validate-instrument-observability.js) will fail the session at end if the cache file is missing — this guard exists so the model halts immediately rather than instrumenting against unknown authMode.
Load from cache: agentStack, programmingLanguage, usesTeamsOrCopilot, agentType, authMode (if previously stored).
Present the loaded values in one message and wait for confirmation:
Here's what we detected about your agent:
• Stack: {agentStack}
• Language: {programmingLanguage}
Reply **yes** to confirm, or describe any corrections.
TaskUpdate — Mark complete: "Load detection cache and validate with user"
TaskCreate — "Determine agent kind and authentication mode"
Read ${CLAUDE_PLUGIN_ROOT}/shared/agent-detection.md — section "Agent Type and Auth Mode Detection" — and follow it exactly.
If agentType and authMode are already present in the detection cache (from a prior skill run in this session OR pre-populated by a parent skill like make-ai-teammate), the confirmation behavior depends on agentType:
agentType = "ai-teammate" — skip the confirmation prompt entirely. The AI Teammate identity model is unambiguous (authMode = agentic-user, no obo/s2s decision exists), so a confirm prompt adds friction without catching drift. Proceed silently.agentType = "system-agent" — confirm the cached values with the user before proceeding, since the obo/s2s choice is meaningful and a stale value would silently route to the wrong token path.Read authMode case-insensitively (S2S = s2s, OBO = obo); always write back the canonical lowercase value.
Store agentType (ai-teammate = AI Teammate, or system-agent = Agent (Non AI Teammate)) and authMode:
agentic-user (agent's own M365 identity — not the caller's token; auto-set, no question needed)obo (On-Behalf-Of — signed-in user token) or s2s (Service Principal, no user token)Update .a365-workspace-detection.local.json — merge agentType and authMode into the existing cache file, preserving all other fields (agentStack, programmingLanguage, usesTeamsOrCopilot, detectedAt). Use the Write tool to write the merged object back.
The authMode value drives Phases 3–5: both paths export over the S2S route with an app-only token, but they differ in how that token is sourced — entry point wiring (Phase 3), message handler pattern (Phase 4), and token resolver (Phase 5). Phases 2, 6, 7, and 8 are identical regardless of authMode.
TaskUpdate — Mark complete: "Determine agent type and authentication mode"
TaskCreate — "Detect agent type and load reference patterns"
Read ${CLAUDE_PLUGIN_ROOT}/shared/agent-detection.md for detection heuristics.
Run detection following the rules in agent-detection.md:
.NET AgentFramework indicators (Microsoft.Agent.*, AgentFramework) → .csprojNode.js indicators (package.json, @langchain, openai, @microsoft/agents-*)Python indicators (requirements.txt, pyproject.toml, .py files, microsoft-agents)Load reference patterns:
${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/dotnet-observability.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/nodejs-observability.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/python-observability.mdIf agent type cannot be determined, write marker .a365setup-unknown-agent and exit early with clear error message.
Framework-support soft-warn matrix. Check (programmingLanguage, agentStack) from the detection cache and surface a warning when the stack lacks first-class auto-instrumentation in @microsoft/opentelemetry or microsoft-opentelemetry. The skill still proceeds — observability is the OTel SDK underneath, which works for any HTTP-based LLM — but the user should know they'll need to add manual InferenceScope.start wrappers around each LLM call.
| Lang | Stack | Action |
|---|---|---|
| Node.js | LangChain, OpenAI Agents SDK, Claude SDK | ✅ Auto-instrumented (Claude with custom shape — see Phase 5.5) |
| Node.js | Semantic Kernel, Google ADK | ⚠ Soft-warn — auto-instrumentation may not patch the LLM library; add manual InferenceScope.start around each LLM call |
| Python | Agent Framework, OpenAI, Google ADK | ✅ Auto-instrumented |
| Python | LangChain, Claude SDK, CrewAI | ⚠ Soft-warn — same as Node.js SK/ADK |
| .NET | Agent Framework, Semantic Kernel | ✅ Auto-instrumented via .UseOpenTelemetry() on IChatClient |
| .NET | Azure AI Foundry | ⚠ Soft-warn — best-effort wiring |
For soft-warn rows, surface verbatim: "Auto-instrumentation in <unified-distro-package> doesn't patch your LLM library directly. The skill will still wire useMicrosoftOpenTelemetry/UseMicrosoftOpenTelemetry (OTel SDK + A365 exporter), but you'll need to manually wrap each LLM call with InferenceScope.start(...) to capture gen_ai.* spans. See <language>-observability.md § 'InferenceScope — Manual Wrapping' for the pattern." Continue to Phase 2.
TaskUpdate — Mark complete and report detected agent type (+ any soft-warn) to user.
TaskCreate — "Install A365 observability packages"
All languages converge on a single unified distro that re-exports the legacy A365 observability + hosting types and auto-instruments common LLM SDKs:
| Language | Install command | S2S extra (FMI token chain) |
|---|---|---|
| .NET | dotnet add package Microsoft.OpenTelemetry | dotnet add package Azure.Identity Microsoft.Identity.Client |
| Node.js | npm install @microsoft/opentelemetry | npm install @azure/msal-node @azure/identity |
| Python | pip install microsoft-opentelemetry | pip install msal azure-identity httpx |
Do not install legacy *.Observability.Runtime / -hosting / -extensions-*
packages alongside the unified distro — the distro re-exports their types and
mixing the two produces CS0433 duplicate-type errors (.NET) or duplicate spans
(Node.js / Python). After install, verify the package appears in the manifest
(*.csproj / package.json / requirements.txt or pyproject.toml).
pip install does not update the dependency manifest — prefer
uv add microsoft-opentelemetry (or poetry add ...) for Python.
Python — Google ADK gotcha: if pyproject.toml lists google-adk,
uv sync will backtrack for minutes resolving the OTel graph. Pin OTel via
[tool.uv] override-dependencies — see python-observability.md → "Google ADK
projects — pin the OTel stack" for the exact block. Other Python stacks
(AgentFramework, LangChain, OpenAI, Claude, Semantic Kernel) don't need this.
Full per-language package tables, version constraints, and the LangChain extras flag live in the references — see the "Required packages" section of:
${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/dotnet-observability.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/nodejs-observability.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/python-observability.mdTaskUpdate — Mark complete.
TaskCreate — "Wire observability in entry point"
Pre-existing placeholders: As of CLI 1.1,
a365 setup allauto-writesAgent365Observabilityplaceholder sections toappsettings.json(.NET) or.env(Node.js/Python). Before creating config from scratch, check if placeholders already exist and fill in values rather than duplicating the section.
Migrating delegated telemetry (the one non-additive edit). If the project already wires the legacy delegated (OBO-route) telemetry path, replace it. That path is:
- Node.js:
AgenticTokenCacheInstance.refreshObservabilityToken(...), apreloadObservabilityTokenhelper, or atokenResolverreadingAgenticTokenCacheInstance.getObservabilityToken(...).- .NET:
RegisterObservability(..., new AgenticTokenStruct(...), ...), anynew AgenticTokenStruct(...)(for example anA365OtelWrapperhelper), anIExporterTokenCache<AgenticTokenStruct>dependency, orAddAgenticTracingExporter().- Python:
exchange_token(...)for the observability scope (with or without an explicitscopes=),cache_agentic_token(...), or anAgenticTokenCache/get_cached_agentic_tokenresolver.- Any language: a distro call without the S2S route flag.
The S2S route rejects those delegated tokens, and the delegated route needs admin consent. Swap the resolver for the app-only one, set the S2S route flag, and remove the per-turn delegated refresh. Keep the baggage and scope wiring. Durable/offline delivery spools keep each record's original route, so disable replay until the installed release enforces S2S for both live and replayed exports, or clear the spool directory:
- Node.js (
@microsoft/opentelemetry1.4.0+):a365: { durableDelivery: { enabled: false } }- .NET (
Microsoft.OpenTelemetry1.1.0+):o.Agent365.DisableOfflineStorage = true- Python (
microsoft-opentelemetry):a365_exporter_disable_offline_storage=TrueList every replaced call in the final summary.
Read the current entry point (Program.cs or detected file).
Edit — Add observability wiring following the reference pattern in dotnet-observability.md:
using Microsoft.OpenTelemetry; to Program.cs.Observability/AgentAppTokenResolver.cs from the reference doc and register it with builder.Services.AddSingleton<AgentAppTokenResolver>();. It acquires an app-only Observability API token per agent identity from the agent's default (blueprint) connection. Then call builder.UseMicrosoftOpenTelemetry(o => { ... }) with o.Exporters = ExportTarget.Agent365 | ExportTarget.Console (Dev) or ExportTarget.Agent365 (Production), o.Agent365.UseS2SEndpoint = true, and o.Agent365.TokenResolver = (agentId, tenantId) => obsTokens?.ResolveAsync(agentId, tenantId) ?? Task.FromResult<string?>(null);, where obsTokens is resolved from app.Services after builder.Build(). On Microsoft.OpenTelemetry 1.0.2 and earlier these options live under o.Agent365.Exporter. Do NOT rely on the distro's auto-registered IExporterTokenCache<AgenticTokenStruct> — it serves delegated tokens that the S2S route rejects. Also set "EnableAgent365Exporter": true in appsettings.json to activate the backend exporter — the SDK defaults this to false when absent, so without it the exporter is wired but inert.IChatClient.UseOpenTelemetry() — when registering the IChatClient (e.g. Azure OpenAI), chain .AsBuilder().UseFunctionInvocation().UseOpenTelemetry(sourceName: null, cfg => cfg.EnableSensitiveData = true).Build(). This is what makes the AI SDK emit the gen_ai.inference and gen_ai.tool spans that InvokeAgentScope (Phase 5.5) anchors as children. Skipping this means no LLM spans appear in MAC, even with everything else wired — the InvokeAgent parent becomes a hollow span. EnableSensitiveData = true includes prompts/completions in span attributes (PII consideration — set to false for regulated data).Observability/ObservabilityServiceExtensions.cs (DI extension with AddAgent365Observability() using ServiceTokenCache and conditional ObservabilityTokenService) and Observability/ObservabilityTokenService.cs (background service that acquires the Observability API token via the MSAL FMI 3-hop chain with .WithFmiPath() targeting scope api://9b975845-388f-4429-889e-eab1ef63949c/.default, supports MSI with client-secret fallback). Then call builder.Services.AddAgent365Observability(); and builder.UseMicrosoftOpenTelemetry(...) with token resolver reading from the ServiceTokenCache. Critical: Set o.Agent365.UseS2SEndpoint = true in the options callback (o.Agent365.Exporter.UseS2SEndpoint on 1.0.2 and earlier) — without this, the exporter posts to the wrong path (/observability/ instead of /observabilityService/) and gets HTTP 401. See "Known Issues" section.
adapter.Use(new BaggageTurnMiddleware()) to auto-populate baggage on every request// A365 Observability — best-effort instrumentation (verify against official sample)Preserve all existing code — only add new lines, never remove.
Read the current entry point (index.ts, app.ts, or detected file).
Edit — Add observability initialization following the reference pattern in nodejs-observability.md:
useMicrosoftOpenTelemetry, shutdownMicrosoftOpenTelemetry, and configureA365Hosting — all from @microsoft/opentelemetry (single package as of GA 1.0; do NOT import from the legacy -observability, -hosting, or -runtime packages). Do NOT import AgenticTokenCacheInstance for telemetry — it serves delegated tokens.observability/app-token-resolver.ts from nodejs-observability.md ("App-only Token Resolver Scaffold"). Then call useMicrosoftOpenTelemetry({ a365: { enabled: true, enableObservabilityExporter: true, useS2SEndpoint: true, tokenResolver: appTokenResolver } }) before any LLM/framework imports, where appTokenResolver = createAppTokenResolver(() => getObsConnection()). Assign getObsConnection = () => adapter.connectionManager.getDefaultConnection(); once the adapter exists. Both enabled: true AND enableObservabilityExporter: true are required in 1.0+ to actually export spans; useS2SEndpoint: true sends them to the S2S route, which accepts the app-only token.observability/token-cache.ts (in-memory token cache with cacheToken/getCachedToken/tokenResolver) and observability/observability-token-service.ts using the scaffold pattern from nodejs-observability.md (S2S section). This module acquires the Observability API token via MSAL FMI 3-hop chain (@azure/msal-node with fmiPath parameter, targeting scope api://9b975845-388f-4429-889e-eab1ef63949c/.default, supports MSI with client-secret fallback) and refreshes it every 50 min. Then call useMicrosoftOpenTelemetry({ a365: { enabled: true, enableObservabilityExporter: true, useS2SEndpoint: true, tokenResolver: a365TokenResolver } }). useS2SEndpoint: true is now a first-class option (1.0+); the old workaround with custom Agent365Exporter via spanProcessors and ENABLE_A365_OBSERVABILITY_EXPORTER=false is no longer needed for new instrumentation. If the old workaround is already present in an existing agent, leave it in place — do not delete code as part of this additive skill; flag it in the final summary as a candidate for cleanup if the user explicitly asks to migrate.configureA365Hosting(adapter, { enableBaggage: true }) once at startup to register BaggageMiddleware. This replaces manual adapter.use(new BaggageMiddleware()) and removes the need for BaggageBuilderUtils.fromTurnContext in handlers.SIGTERM/SIGINT handlers calling await shutdownMicrosoftOpenTelemetry() to flush pending spans on shutdown.OpenAIAgentsTraceInstrumentor.enable() or LangChainTraceInstrumentor.instrument() — these are auto-enabled in 1.0+ and manual calls cause duplicate spans. To opt out, set instrumentationOptions: { openaiAgents: { enabled: false } }.// A365 Observability — best-effort instrumentation (verify against official sample)Preserve all existing code — only add new lines, never remove.
Read the current entry point (app.py, host_agent_server.py, or detected file).
Edit — Add observability configuration following the reference pattern in python-observability.md:
use_microsoft_opentelemetry from microsoft.opentelemetry (single unified package; do NOT import from the legacy microsoft_agents_a365.* namespace).observability/app_token_resolver.py from python-observability.md ("App-only Token Resolver Scaffold"). Then create OBS_TOKENS = AppTokenResolver() and call use_microsoft_opentelemetry(enable_a365=True, a365_enable_observability_exporter=True, a365_use_s2s_endpoint=True, a365_token_resolver=OBS_TOKENS.resolve). Both enable_a365=True AND a365_enable_observability_exporter=True are required in 1.0+ to actually export spans; a365_use_s2s_endpoint=True sends them to the S2S route. Do NOT wire AgenticTokenCache().get_observability_token or a cache of exchange_token() results — both serve delegated tokens.observability/token_cache.py (in-memory token cache with cache_token/get_cached_token) and observability/observability_token_service.py using the scaffold pattern from python-observability.md (S2S section). This module acquires the Observability API token via a 3-hop FMI chain: direct HTTP POST with fmi_path for Hops 1+2 (MSAL Python does not properly serialize fmi_path — known limitation), then msal.ConfidentialClientApplication for Hop 3, targeting scope api://9b975845-388f-4429-889e-eab1ef63949c/.default, supports MSI with client-secret fallback, refreshes every 50 min via an asyncio background task. Then call use_microsoft_opentelemetry(enable_a365=True, a365_enable_observability_exporter=True, a365_use_s2s_endpoint=True, a365_token_resolver=...). a365_use_s2s_endpoint=True is now a first-class kwarg — no workaround needed. Schedule run_token_service() as an asyncio task and call acquire_initial_token() in your aiohttp lifespan startup. Also install msal, azure-identity, and httpx.ObservabilityHostingManager.configure(adapter.middleware_set, ObservabilityHostingOptions(enable_baggage=True)) once at startup to auto-populate baggage from TurnContext. Note: enable_baggage defaults to False — must be explicitly set to True.*Instrumentor().instrument() methods for LangChain/OpenAI/SK/AgentFramework — these are auto-enabled in 1.0+ and manual calls cause duplicate spans.# A365 Observability — best-effort instrumentation (verify against official sample)Preserve all existing code — only add new lines, never remove.
TaskUpdate — Mark complete.
TaskCreate — "Add BaggageBuilder context to message handler"
Skip this phase if BaggageMiddleware was registered in Phase 3 — the middleware handles baggage propagation automatically for every request.
Auth mode note: Telemetry never goes through the auth handler. Every
authModeexports over the S2S route with an app-only token (Phase 3), and the auth handler (AgentApplication:AgenticAuthHandlerName, etc.) is only for workload calls (MCP / Graph). Add an inline comment indicating which mode was chosen.
Read the detected message handler file.
Edit — Follow the reference pattern in dotnet-observability.md (full code sample under "Agent Class — Message Handler (OBO Path)"):
OBO path (obo / agentic-user) — applies to both AI Teammate agents and Standard .NET agents:
IConfiguration (for blueprint/observability config) and ILogger<MyAgent>. Do not inject IExporterTokenCache<AgenticTokenStruct> or make a per-turn RegisterObservability(...) call: the app-only AgentAppTokenResolver wired in Phase 3 supplies the export token. If an existing handler has either, remove it (see "Migrating delegated telemetry" in Phase 3).a365 setup all writes to Agent365Observability:AgentId for non-AI-Teammate blueprint agents. Do NOT decode it from an OBO token: Utility.ResolveAgentIdentity(context, oboToken) returns the blueprint or bot app ID for OBO tokens. Do NOT fall back to Guid.Empty.ToString() either. Both produce an identity the exporter cannot authenticate.
var obsConfig = _configuration.GetSection("Agent365Observability");
string? resolvedAgentId = turnContext.Activity.IsAgenticRequest()
? turnContext.Activity.GetAgenticInstanceId()
: obsConfig["AgentId"];
if (!Guid.TryParse(resolvedAgentId, out _)
|| string.Equals(resolvedAgentId, obsConfig["AgentBlueprintId"], StringComparison.OrdinalIgnoreCase))
{
resolvedAgentId = null; // not an agent identity; the S2S route would reject it
}
var resolvedTenantId = turnContext.Activity.Conversation?.TenantId
?? turnContext.Activity.Recipient?.TenantId
?? obsConfig["TenantId"];
var hasObservabilityIdentity = !string.IsNullOrEmpty(resolvedAgentId)
&& !string.IsNullOrEmpty(resolvedTenantId);
GetAgenticInstanceId() returns the agentic instance ID (Recipient.AgenticAppId). That is the identity the app-only token is minted for, and what shows up in MAC Advanced Hunting.hasObservabilityIdentity == true; skip cleanly when the identity can't be resolved:
using IDisposable? baggageScope = hasObservabilityIdentity
? new BaggageBuilder()
.TenantId(resolvedTenantId!)
.AgentId(resolvedAgentId!)
.Build()
: null;
Agent365Observability section in appsettings.json (EnableAgent365Exporter and base exporter settings are still required — Phase 6 handles these). No S2S credentials are needed there: AgentAppTokenResolver uses the agent's Connections settings, and agentic turns resolve their agent ID at runtime.A365OtelWrapper is the legacy delegated-token wrapper. Remove it and migrate the handler to the inline app-only S2S pattern above (see "Migrating delegated telemetry" in Phase 3).S2S path:
Agent365ObservabilityContext (singleton registered by AddAgent365Observability()) in the constructornew BaggageBuilder().FromTurnContext(turnContext).Build() as a separate using var baggageScope — FromTurnContext() is an extension on BaggageBuilder only; it does not exist on InvokeAgentScope or any scope typeInvokeAgentScope.Start(new Request(...), new InvokeAgentScopeDetails(endpoint: new Uri("...")), _obs.AgentDetails, callerDetails) as a separate using var scope — InvokeAgentScopeDetails has no parameterless constructor; always pass at least endpoint. CallerDetails with the blueprint sponsor's identity is required for S2S traces to appear in the portalRegisterObservability() call; no .FromTurnContext() chaining on the scope// A365 auth mode: S2S — FMI 3-hop chain via ObservabilityTokenService (scope: api://9b975845-388f-4429-889e-eab1ef63949c/.default)Mark all new lines with: // A365 Observability — best-effort instrumentation (verify against official sample)
Preserve all existing handler logic.
Read the detected message handler file.
Edit — Follow the reference pattern in nodejs-observability.md ("Message Handler"):
tokenResolver wired in Phase 3 acquires the export token when spans are exported, so there is no per-turn refresh. That resolver is observability/app-token-resolver.ts for obo / agentic-user, and the background token service for s2s.AgenticTokenCacheInstance.refreshObservabilityToken(...) or add a preloadObservabilityToken helper. That call exchanges a delegated token, needs admin consent, and the S2S route rejects the result. If an existing handler has one, remove it (see "Migrating delegated telemetry" in Phase 3).recipient.agenticAppId) through the Phase 5.5 baggage scope, never from config. The only exception is the optional non-agentic fallback described in nodejs-observability.md.BaggageBuilderUtils.fromTurnContext(new BaggageBuilder(), turnContext as any).build() and runs InvokeAgentScope.start(...) inside baggageScope.run(...). The configureA365Hosting(adapter, { enableBaggage: true }) middleware registered in Phase 3 is a fallback that auto-populates baggage outside the handler, but it does NOT cover the scopes you'll add in Phase 5.5 — those need the manual outer wrapping or they get filtered as Partitioned into 0 identity groups. Do NOT call InvokeAgentScope.start in Phase 4.// A365 auth mode: {authMode} — telemetry uses an app-only token on the S2S route// A365 Observability — best-effort instrumentation (verify against official sample)Preserve all existing handler logic.
Read the detected message handler file AND host_agent_server.py. The helper lives in the HOST file, not the agent class, so it can reach the host's connection_manager and be called by activity middleware. Per-turn baggage construction also lives in the handler/middleware layer in host_agent_server.py, NOT in agent.py.
Edit host_agent_server.py (the host file) — Prefetch the app-only telemetry token per turn following the reference pattern in python-observability.md:
obo / agentic-user): Resolve agent_id and tenant_id dynamically from context each turn (never from config), then prefetch the app-only token (non-fatal, wrap in try/except). a365_token_resolver is synchronous, so the async FMI acquisition happens here and the resolver only reads the cache:
agent_id = context.activity.recipient.agentic_app_id
tenant_id = context.activity.recipient.tenant_id
await self._setup_observability_token(context, tenant_id, agent_id)
The _setup_observability_token helper prefetches and caches the app-only token:
async def _setup_observability_token(self, context, tenant_id, agent_id):
try:
await OBS_TOKENS.prefetch(self.connection_manager, tenant_id, agent_id)
except Exception as e:
logger.warning(f"Failed to acquire observability token: {e}")
self.connection_manager is the host's MsalConnectionManager (the object passed to CloudAdapter(connection_manager=...)). Its default connection is the blueprint credential, so no auth handler or extra settings are involved. CloudAdapter does not expose it publicly. If the host only keeps it in a local variable, store it on the host with self.connection_manager = ... and pass that same object to the adapter. Never create a second one.on_agent_notification). The sync resolver can only serve tokens a prefetch cached.exchange_token(...) with get_observability_authentication_scope(), or cache its result with cache_agentic_token. That is a delegated exchange: it needs admin consent, and the S2S route rejects the token. Replace any existing body that does this (see "Migrating delegated telemetry" in Phase 3)._setup_observability_token — token comes from the background token service wired in Phase 3. The handler should NOT touch tokens.ObservabilityHostingManager.configure(adapter.middleware_set, ObservabilityHostingOptions(enable_baggage=True)) which auto-populates baggage from TurnContext for every request. (Optional fallback if you skipped that: build manually with populate(builder, context) then with builder.build():.)# A365 auth mode: {authMode} — telemetry uses an app-only token on the S2S route# A365 Observability — best-effort instrumentation (verify against official sample)Preserve all existing handler logic.
TaskUpdate — Mark complete.
TaskCreate — "Implement app-only token resolver with caching"
Every path exports with an app-only token for the exporting agent identity. obo / agentic-user agents use the app-only resolver scaffold, which reuses the hosting connection (blueprint credential). s2s agents use the background token-service scaffold. Phase 3 normally writes these files; this phase makes sure they exist on re-runs or partial states. Never fall back to the distro's delegated token caches (IExporterTokenCache<AgenticTokenStruct>, AgenticTokenCacheInstance, AgenticTokenCache) or to a legacy Use_Custom_Resolver cache of delegated tokens.
Check that Observability/AgentAppTokenResolver.cs exists and is registered with builder.Services.AddSingleton<AgentAppTokenResolver>(). Also check that o.Agent365.UseS2SEndpoint = true and o.Agent365.TokenResolver are set, with obsTokens resolved from app.Services after Build(). If any piece is missing, add it from dotnet-observability.md ("Scaffold: Observability/AgentAppTokenResolver.cs").
The ObservabilityTokenService background service (created in Phase 3 via the scaffold) acquires and refreshes the Observability API token automatically via the FMI 3-hop chain (Blueprint → Agent Identity → Observability API) — no manual TokenResolver delegate needed beyond the cache read wired in Phase 3.
Check if Observability/ObservabilityServiceExtensions.cs and Observability/ObservabilityTokenService.cs exist. If yes, skip — they were already created in Phase 3.
If absent (Phase 3 was skipped or re-running the skill on a partial state), create them now following the S2S scaffold patterns in dotnet-observability.md. These files provide AddAgent365Observability() (DI extension registering AddServiceTracingExporter, ObservabilityTokenService, and Agent365ObservabilityContext) and ObservabilityTokenService (background service that acquires the Observability API token via the FMI 3-hop chain and refreshes it every 50 minutes).
Check that observability/app-token-resolver.ts exists. Also check that useMicrosoftOpenTelemetry() passes useS2SEndpoint: true and tokenResolver: appTokenResolver, and that getObsConnection is assigned once the adapter exists. If anything is absent, add it from nodejs-observability.md ("App-only Token Resolver Scaffold").
Check if observability/observability-token-service.ts exists. If yes, skip — it was created in Phase 3.
If absent (Phase 3 was skipped or re-running), create observability/token-cache.ts and observability/observability-token-service.ts now using the scaffold from nodejs-observability.md (S2S section). The token service uses MSAL (@azure/msal-node) with fmiPath to acquire tokens via the FMI 3-hop chain targeting scope api://9b975845-388f-4429-889e-eab1ef63949c/.default. Call startTokenService(config) at app startup and pass tokenResolver from the cache module to useMicrosoftOpenTelemetry().
Check that observability/app_token_resolver.py exists and that use_microsoft_opentelemetry() receives a365_token_resolver=OBS_TOKENS.resolve and a365_use_s2s_endpoint=True. Also check that the Phase 4 _setup_observability_token helper awaits OBS_TOKENS.prefetch(...). If anything is absent, add it from python-observability.md ("App-only Token Resolver Scaffold").
Check if observability/observability_token_service.py exists. If yes, skip — it was created in Phase 3.
If absent, create observability/token_cache.py and observability/observability_token_service.py now using the scaffold from python-observability.md (S2S section). The token service uses MSAL (msal.ConfidentialClientApplication) with fmi_path to acquire tokens via the FMI 3-hop chain targeting scope api://9b975845-388f-4429-889e-eab1ef63949c/.default. Call acquire_initial_token() for pre-warm, schedule run_token_service() as asyncio.create_task(), and pass token_cache.get_cached_token as the a365_token_resolver in use_microsoft_opentelemetry().
TaskUpdate — Mark complete.
TaskCreate — "Wire InvokeAgentScope, InferenceScope, ExecuteToolScope"
Auto-instrumentation vs manual: Whether manual scopes are needed depends on
authModeand whether auto-instrumentation framework extensions were installed in Phase 2.
Situation InvokeAgentScope InferenceScope ExecuteToolScope authMode = "s2s"Required — add always Required — add always Required — add always OBO + framework extension installed (Phase 2) Required — add always Skip — auto-instrumentation generates these Only for local/custom tools not covered by the extension OBO + no framework extension Required — add always Required — add always Required — add always "Autonomous" agents can run on either OBO or S2S — auth mode is the actual differentiator here, not whether the agent is autonomous.
Rule: Never skip
InvokeAgentScope— it wraps the turn and is always required for traces to appear in the MAC portal. Auto-instrumentation extensions cover LLM calls (InferenceScope) and framework-managed tool calls (ExecuteToolScope), but they do not wrap the agent turn itself.
Determine which scopes to add:
authMode = "s2s": proceed directly — add all three scopes without prompting (required for S2S agents).InvokeAgentScope always.InferenceScope — the framework extension instruments LLM calls automatically.ExecuteToolScope wrappers for those." Add ExecuteToolScope only if the user confirms custom tool calls exist.Store publishing: The Agent 365 store validator requires
InvokeAgentScope,InferenceScope, andExecuteToolScopeto be present. For OBO agents with framework extensions, the extension satisfiesInferenceScopeand framework-managedExecuteToolScopeautomatically.
Follow the reference patterns in dotnet-observability.md for each scope being added:
InvokeAgentScope — wrap the top-level message handler to capture agent invocation telemetry. Gate the scope on hasObservabilityIdentity (see Phase 4) so it's only opened when a real (agent, tenant) tuple is available; otherwise the scope groups spans under a synthetic identity the exporter cannot authenticate.InferenceScope — wrap each LLM call to capture model, token counts, finish reasons (skip if framework extension installed)ExecuteToolScope — wrap each local/custom tool call (skip if framework extension covers all tool calls)OutputScope — use for async response scenarios where output isn't captured synchronouslyCallerDetails must be passed to InvokeAgentScope.Start() as the 4th parameter — required for traces to appear in the MAC portal. For OBO/agentic-user, build it from turnContext.Activity.From (AadObjectId/Name). For S2S, read sponsor details from config (Agent365Observability:Sponsor section) and construct CallerDetails with UserDetails(userId, userName, userEmail).InvokeAgentScopeDetails.endpoint URI: build the endpoint from Agent365Observability:AgentBlueprintId (a GUID — always URI-safe) under the RFC 2606 reserved .invalid TLD. Do NOT slugify the free-form display name — characters like apostrophes, &, parentheses, or slashes throw UriFormatException at runtime:
var blueprintForUri = obsConfig["AgentBlueprintId"];
var endpointUri = !string.IsNullOrEmpty(blueprintForUri)
? new Uri($"https://{blueprintForUri}.agent.invalid/")
: new Uri("https://agent.invalid/");
ChatClientAgentOptions.Id to match resolvedAgentId when constructing the ChatClientAgent for each turn. Without this, the AI SDK auto-generates a fresh N-format GUID (32 hex chars, no dashes) per turn, producing orphan identity groups the exporter cannot authenticate (logs show "Obtained token for agent <random32hex> tenant ..." followed by "No token obtained. Skipping export for this identity."). Pattern:
var options = new ChatClientAgentOptions
{
Name = obsConfig["AgentName"] ?? "Agent",
ChatOptions = toolOptions,
ChatHistoryProvider = ...,
};
if (!string.IsNullOrEmpty(resolvedAgentId))
{
options.Id = resolvedAgentId;
}
UserDetails directly (not wrapped in CallerDetails) to InferenceScope.Start() and ExecuteToolScope.Start() as the optional 4th parameterAgent365ObservabilityContext singleton (S2S path) should hold both AgentDetails and CallerDetails propertiesThe pattern is per-stack — read agentStack from .a365-workspace-detection.local.json and branch:
LangChain or OpenAI → canonical wrapping pattern below (verified against the LangChain + OpenAI samples).Claude → InferenceScope-only, no outer baggageScope, no InvokeAgentScope. The Claude sample (Agent365-Samples/nodejs/claude/sample-agent/src/client.ts) wraps each LLM call individually in src/client.ts. Skip the canonical pattern below; follow the InferenceScope-only shape from the Claude sample instead. Tell the user: "Claude SDK uses a different observability shape — wrapping per LLM call in client.ts instead of around the message handler. InvokeAgentScope is not used."Semantic Kernel or Google ADK → handled by Phase 0.6 framework guard (soft-warn — auto-instrumentation may not patch the LLM library; manual InferenceScope.start wrapping required around each LLM call).For LangChain + OpenAI, follow the reference patterns in nodejs-observability.md for each scope. The wrapping order is non-negotiable — wrong order produces silent span drops (logged as Partitioned into 0 identity groups).
Canonical pattern (generate exactly this shape):
const baggageScope = BaggageBuilderUtils // STEP 1 — outer baggage scope
.fromTurnContext(new BaggageBuilder(), turnContext as any)
.sessionDescription('agent-turn')
.build();
await baggageScope.run(async () => { // STEP 2 — scopes run INSIDE baggage
const scope = InvokeAgentScope.start(request, scopeDetails, agentDetails, callerDetails);
try {
await scope.withActiveSpanAsync(async () => {
// InferenceScope / ExecuteToolScope / agent invocation here
});
} finally { scope.dispose(); }
});
Why this exact shape:
tokenResolver (Phase 3) acquires and caches the export token on demand, so a cold turn does not need a preload. Do not reintroduce preloadObservabilityToken / refreshObservabilityToken.baggageScope.run wrapping InvokeAgentScope.start, the spans have no microsoft.tenant.id / gen_ai.agent.id baggage attached — the exporter filters them as Partitioned into 0 identity groups (N spans skipped) and they never reach MAC.Additional rules:
BaggageBuilder AND BaggageBuilderUtils from @microsoft/opentelemetry. Both are required.InvokeAgentScopeDetails is {} in Node.js — endpoint is optional and unused. Do NOT generate endpoint: new Uri(...) — that's the .NET API surface and will not compile in TypeScript.InferenceScope — wrap each LLM call (skip if framework extension installed)ExecuteToolScope — wrap each local/custom tool call (skip if framework extension covers all tool calls)OutputScope — for async scenariosCallerDetails must be passed to InvokeAgentScope.start() as the 4th parameter — required for traces to appear in the MAC portalagent365Observability__sponsorUserId, agent365Observability__sponsorUserName, agent365Observability__sponsorUserEmail) and construct the CallerDetails objectUserDetails directly to InferenceScope.start() and ExecuteToolScope.start() as the optional 4th parametercallerDetails (for InvokeAgentScope) and userDetails (for InferenceScope/ExecuteToolScope) from the entry point module alongside agentDetailsFollow the reference patterns in python-observability.md for each scope being added:
InvokeAgentScope — wrap the top-level message handler as a context managerInferenceScope — wrap each LLM call (skip if framework extension installed)ExecuteToolScope — wrap each local/custom tool call (skip if framework extension covers all tool calls)OutputScope — for async response scenariosCallerDetails / UserDetails must be supplied when creating the top-level InvokeAgentScope — required for traces to appear in the MAC portalCallerDetails(UserDetails(userId, userName, userEmail))UserDetails directly to InferenceScope, ExecuteToolScope, and OutputScope when their optional user parameter is availableagent_details and caller_details / user_details so nested scopes can reuse them consistentlyAll new lines marked with the language-appropriate comment:
// A365 Observability — best-effort instrumentation (verify against official sample)# A365 Observability — best-effort instrumentation (verify against official sample)TaskUpdate — Mark complete.
TaskCreate — "Update configuration files with observability settings"
Read the language-appropriate reference for the complete config block:
${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/dotnet-observability.md → "appsettings.json"${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/nodejs-observability.md → ".env"${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/python-observability.md → ".env"Apply these invariants across all three languages:
Preserve existing values. If Agent365Observability (.NET) or
ENABLE_A365_OBSERVABILITY_EXPORTER (Node.js / Python) already exists, do not
overwrite. Add only missing keys.
.NET — exactly one Logging section. Read appsettings.json fully
before writing. If Logging or Logging.LogLevel exists, merge the new
log-level keys (Microsoft.Agents.A365.Observability: Debug,
OpenTelemetry: Debug) into that block. A second Logging block produces
silently invalid config where only the last one wins.
.NET — EnableAgent365Exporter: true at the root. a365 setup may write
false; this skill corrects it. Add an appsettings.Development.json with
"EnableAgent365Exporter": false so local dev traces go to console only.
Sponsor / CallerDetails — required for MAC portal trace visibility.
Agent365Observability.Sponsor (UserId, UserName, UserEmail) in appsettings.json.agent365Observability__sponsorUserId / __sponsorUserName / __sponsorUserEmail in .env.S2S route (all auth modes) and S2S-only additions:
o.Agent365.UseS2SEndpoint = true (.NET), useS2SEndpoint: true (Node), or
a365_use_s2s_endpoint=True (Python). Keep it in code: Python's A365_USE_S2S_ENDPOINT
env fallback is fragile (the code validator flags env-only selection), and the legacy
AGENT365_USE_S2S_ENDPOINT env var is ignored.obo / agentic-user: no extra settings — the app-only resolver reads the blueprint
credential from the existing connection settings that a365 setup all wrote: Connections
(.NET), connections__service_connection__settings__* (Node.js), or
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__* (Python).s2s, .NET: add ClientId, ClientSecret, and UseManagedIdentity: false (for
local dev — MSI fails off-Azure with CredentialUnavailableError) under
Agent365Observability.Inform the user when:
AgentBlueprintId / TenantId are empty → "run a365 setup to populate".false (Node.js / Python local dev) → "instrumented but
disabled; set ENABLE_A365_OBSERVABILITY_EXPORTER=true to start exporting".Stamp the verbose-logging pair into .env (Node.js / Python) — OTEL_LOG_LEVEL=INFO (OpenTelemetry SDK's own internal logger) and A365_OBSERVABILITY_LOG_LEVEL=info|warn|error (pipe-separated levels emitted by the A365 exporter). For .NET, write the equivalent Logging.LogLevel.Microsoft.Agents.A365.Observability: Information to appsettings.json AND set OTEL_LOG_LEVEL=INFO / A365_OBSERVABILITY_LOG_LEVEL=info|warn|error as env vars (.NET reads both forms). Recommended baseline: INFO + info|warn|error in prod; users can trim to WARN + warn|error to reduce noise. Write them as a labeled # ── Observability verbose logging ── block so the two vars stay grouped. Additive — never overwrite values the user has set.
If the project also uses .env.example (Node.js / Python), update it with
placeholder values to match .env.
TaskUpdate — Mark complete.
TaskCreate — "Validate build passes"
Bash — Run:
dotnet build
If build fails, collect error output and present to user with suggested fixes.
If build succeeds, confirm to user.
Bash — Run:
npm install # Ensure new packages are installed
npm run build || npm run compile || echo "No build script found — skipping compile check"
If build fails, collect error output and present to user with suggested fixes.
If build succeeds (or no build script exists), confirm to user.
Bash — Run an import check to verify the package loads without errors:
python3 -c "from microsoft.opentelemetry import use_microsoft_opentelemetry; from microsoft.opentelemetry.a365.hosting import ObservabilityHostingManager; print('A365 observability imports OK')" 2>/dev/null || python -c "from microsoft.opentelemetry import use_microsoft_opentelemetry; from microsoft.opentelemetry.a365.hosting import ObservabilityHostingManager; print('A365 observability imports OK')"
If import fails, collect error output and present to user with suggested fixes (usually a missing pip install).
If import succeeds, confirm to user.
TaskUpdate — Mark complete.
TaskCreate — "Test locally"
Ask the user:
AskUserQuestion:
question: "Build succeeded. Want to run a quick local test now?"
options:
- "Yes — run the test-local skill"
- "No — I'll test later"
If yes, invoke the test-local skill.
TaskUpdate — Mark complete.
TaskCreate — "Verify a span actually exports"
Without this phase the skill ends "instrumented successfully" but the user has no way to know whether spans actually reach MAC until 15-90 min later when indexing catches up. This phase runs the agent for ~30 seconds with verbose-logging env vars enabled, sends one message, and greps the log for the specific line that confirms export succeeded. Pass/fail is visible immediately.
Node.js:
Bash (background) — start the agent with verbose logs enabled:
OTEL_LOG_LEVEL=INFO A365_OBSERVABILITY_LOG_LEVEL=info|warn|error npm start > .a365-smoketest.log 2>&1 &
Use Claude Code's run_in_background: true so the agent stays up while we probe.
Wait ~5s for boot, then send a test message to /api/messages (or instruct the user to send one via AgentsPlayground / Teams).
Bash — after ~30s, check the log for the export-success line:
grep -E "export-group succeeded|exported successfully|rejectedSpans:0" .a365-smoketest.log | head -5
Interpret:
admin.cloud.microsoft → Advanced Hunting → CloudAppEvents filtered by AgentId = <AUID> after that delay."Partitioned into 0 identity groups lines → ❌ silent drop. Most likely: missing outer baggage scope (Phase 5.5) OR missing exporter flag (a365.enableObservabilityExporter: true / env var). Re-check Phases 3 + 5.5.Python: same flow with OTEL_LOG_LEVEL + A365_OBSERVABILITY_LOG_LEVEL env vars and python host_agent_server.py instead of npm start.
.NET: skip this phase — the .NET CLI's own boot-time logging covers the verification path. If the user wants stricter checking, set Logging.LogLevel.Microsoft.Agents.A365.Observability: Information in appsettings.json and grep dotnet run output for "Sending N spans to ..." / "HTTP 202 exporting spans".
TaskUpdate — Mark complete with the result (pass / fail / skipped).
TaskList — Show all completed tasks.
Present summary to user:
✅ A365 observability instrumented successfully!
**Agent type:** [.NET AgentFramework | Node.js | Python]
**Agent kind:** [AI Teammate | Agent (Non AI Teammate)]
**Auth mode:** [Access data as signed-in user | Its own persistent identity | Runs autonomously]
**Packages installed:** [list packages]
**Files modified:** [list files]
**Next steps:**
1. Enable exporting when ready for production:
- .NET: set EnableAgent365Exporter: true in appsettings.json
- Node.js / Python: set ENABLE_A365_OBSERVABILITY_EXPORTER=true in .env (or `a365.enableObservabilityExporter: true` in code — both required alongside `a365.enabled: true`)
2. Run your agent and verify traces appear in the Observability dashboard.
**What to expect for MAC visibility (first-run reality check):**
- **Indexing lag: 15–90 minutes** between first successful export and spans appearing in `admin.cloud.microsoft → Advanced Hunting → CloudAppEvents`. If you query immediately after instrumenting, you'll see empty results — that's not a bug.
- **Instance approval required.** Spans only attribute to a `CloudAppEvents` row when the AI Teammate's agent instance has been approved at `admin.cloud.microsoft/#/agents/all/requested` and an Agentic User UPN has been issued. Without that, exported spans land but don't surface in MAC queries.
- **KQL filter MUST use the AUID, NOT the blueprint id.** The `AgentId` column in `CloudAppEvents` is the runtime AUID resolved from `turnContext.activity.recipient.agenticAppId`. For AI Teammates, the `agent365Observability__agentId` env var that `a365 setup all` stamps into `.env` is the BLUEPRINT id, and filtering by that value returns empty results. Get the AUID from your agent logs (the exporter logs `Obtained token for agent <AUID> tenant ...`) or from `recipient.agenticAppId` in any inbound activity.
- **OBS authorization.** Telemetry is exported over the S2S route with an app-only token. Blueprint agents: no OBS permission or consent step — registered instances are authorized without `Agent365.Observability.OtelWrite` (subject to service policy); on 403 `insufficient_scope`, run `a365 setup all --agent-registration-only`. AI Teammates: no OBS permission or consent step either — the route authorizes them by their Blueprint's registration (subject to service policy); on 403 `insufficient_scope`, use the application-role fallback in "Authorization — registration, not OtelWrite".
**Verbose logging — only enable when actively debugging:**
- Node.js / Python: uncomment `OTEL_LOG_LEVEL=INFO` AND `A365_OBSERVABILITY_LOG_LEVEL=info|warn|error` in `.env`. **Both** are required to see `[Agent365Exporter]` activity — the exporter uses a wrapped logger that defaults to silent.
- Grep for `exported successfully` / `export-group succeeded` to confirm spans are flowing; `Partitioned into 0 identity groups (N spans skipped)` for spans outside an active baggage scope is **expected** (early framework / middleware / health-ping spans) — not an error.
3. [If authMode = obo] Confirm the workload (MCP / Graph) OBO token exchange works. Telemetry does not use it — it uses the app-only resolver.
- Signed-in user sub-type: verify the signed-in user's token is passed correctly.
→ OBO flow docs: https://learn.microsoft.com/en-us/entra/agent-id/agent-on-behalf-of-oauth-flow
- Agentic identity sub-type: ensure the agentic user identity has been provisioned in Azure AD.
→ Identity docs: https://learn.microsoft.com/en-us/microsoft-agent-365/developer/identity
4. [If authMode = agentic-user] Confirm the agentic-user M365 license and identity are provisioned.
→ Identity docs: https://learn.microsoft.com/en-us/microsoft-agent-365/developer/identity
5. [If authMode = s2s] No user token required — verify agent blueprint credentials and the agent identity (`AgentId`) are configured.
→ Auth flow docs: https://learn.microsoft.com/en-us/microsoft-agent-365/developer/authentication-flow
6. [If delegated telemetry wiring was migrated] List each replaced call (per-turn refresh / token registration / delegated resolver) so the user can review the diff.
All instrumented lines are marked with:
// A365 Observability — best-effort instrumentation (verify against official sample)
Remind user to:
If the agent type cannot be determined:
.a365setup-unknown-agentIf the build fails after instrumentation:
If expected files are not found:
This skill is safe to rerun. On subsequent runs:
useS2SEndpoint: true / a365_use_s2s_endpoint=True / o.Agent365.UseS2SEndpoint = true), and no delegated-telemetry signal may remain: refreshObservabilityToken(...), AgenticTokenCacheInstance.getObservabilityToken, AgenticTokenStruct / RegisterObservability(..., AgenticTokenStruct), exchange_token(...) for the observability scope, cache_agentic_token, or an AgenticTokenCache resolver. Marker comments alone are not enough — code written by earlier versions of this skill carries them on the delegated wiring. If any delegated signal is present or the route flag is missing, run "Migrating delegated telemetry" (Phase 3) instead of skipping.Telemetry is exported over the S2S route with an app-only token for the agent identity. Registered blueprint agent instances, and AI Teammates through their Blueprint's registration, are authorized on that route without Agent365.Observability.OtelWrite or admin consent (subject to service policy). Newer a365 setup all versions skip Observability API permissions for both, and for blueprint agents exit 1 when registration fails or cannot be verified. Older versions may still grant OtelWrite (harmless) and may exit 0 after a failed registration, so check setup output for registration errors and rerun a365 setup all --agent-registration-only if needed.
403 insufficient_scope on export → the service could not authorize the agent by registration, and it has no OtelWrite application role. Blueprint agents: run a365 setup all --agent-registration-only (idempotent), then retry. AI Teammates: that flag does not apply. First re-run a365 setup all --aiteammate --m365 (idempotent) and check its output for Blueprint registration errors; if registration succeeded and exports still return 403, use the application role below.
Application role (fallback): a Global Administrator grants the Agent365.Observability.OtelWrite application role on the Blueprint, which the S2S route accepts. The Global Administrator runs both steps below, because a non-admin run of setup permissions custom stops at the delegated grant before it creates the inheritable entry. Use the Observability API app ID for the agent's cloud: Commercial 9b975845-388f-4429-889e-eab1ef63949c, GCC Moderate 2c672ad5-b104-44ed-8069-bb68dd138546, GCC High 009c6bd0-82e4-4466-95b3-4c996521f3d7, DoD a9e04047-c6a7-430b-a7ae-faf8f8eed1b7.
a365 setup permissions custom --resource-app-id <Observability app ID> --scopes Agent365.Observability.OtelWrite (the delegated scope it also adds is harmless and not used for telemetry).<Observability app ID> > Application Agent365.Observability.OtelWrite > Grant admin consent.Older a365 setup all --aiteammate versions print a PowerShell script that grants the role; run that script if its action item is still pending.
Do not add the delegated OtelWrite scope or run a delegated consent flow to authorize telemetry. Delegated tokens are rejected by the S2S route. Only agents still on an old SDK that exports over the delegated route need that grant, and they should migrate instead (see "Migrating delegated telemetry" in Phase 3).
/otlp/ URL Path BugThe Node.js SDK (@microsoft/[email protected]) and .NET SDK (0.3.4-beta) include /otlp/ in the S2S export URL path. The Power Platform PFAT gateway returns 401 MSAuth10AuthenticatorTypeUnknown on this path. Python SDK 0.1.0 does NOT include /otlp/ and works correctly.
Status: Awaiting SDK fix. No workaround should be applied in generated code — this is an SDK-level issue.
The distros default to the delegated route (/observability/tenants/{tenantId}/otlp/agents/{agentId}/traces), which rejects app-only tokens. Every agent — agentic-user, obo, and s2s — must select the S2S route (/observabilityService/...) explicitly:
Node.js (@microsoft/opentelemetry 1.0+):
useMicrosoftOpenTelemetry({
a365: {
enabled: true,
enableObservabilityExporter: true,
useS2SEndpoint: true, // required in every auth mode
tokenResolver: appTokenResolver, // or the s2s token-cache resolver
},
});
The old AGENT365_USE_S2S_ENDPOINT env var workaround and custom spanProcessors workarounds are no longer needed.
Python (microsoft-opentelemetry 1.1+): pass a365_use_s2s_endpoint=True to use_microsoft_opentelemetry(...).
.NET (Microsoft.OpenTelemetry 1.0.x GA):
The UseMicrosoftOpenTelemetry() builder extension does NOT set UseS2SEndpoint = true. Without it, the exporter posts to /observability/ instead of /observabilityService/, causing HTTP 401. Set it explicitly. On 1.0.3+ the options live on o.Agent365; on 1.0.2 and earlier, use o.Agent365.Exporter instead:
builder.UseMicrosoftOpenTelemetry(o =>
{
o.Exporters = ExportTarget.Agent365 | ExportTarget.Console;
o.Agent365.UseS2SEndpoint = true; // ← Required in every auth mode
// obo / agentic-user: AgentAppTokenResolver; s2s: the ServiceTokenCache read shown in the reference.
o.Agent365.TokenResolver = (agentId, tenantId) =>
obsTokens?.ResolveAsync(agentId, tenantId) ?? Task.FromResult<string?>(null);
});
URL paths:
observability/tenants/{tenantId}/otlp/agents/{agentId}/tracesobservabilityService/tenants/{tenantId}/otlp/agents/{agentId}/tracesfmiPath Not Supported (AADSTS82008)No published version of @azure/msal-node (v3.x or v5.x) serializes the fmiPath parameter to the token endpoint request body. Passing fmiPath in acquireTokenByClientCredential() options (even with as any) is silently ignored, resulting in:
AADSTS82008: All agentic applications requesting a token exchange token must include the fmipath parameter on the token request.
Workaround (implemented in nodejs-observability.md): For the client-secret local-dev path (acquireT1ViaClientSecret), use a direct HTTP POST to https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token with fmi_path={agentId} as a URL-encoded form parameter. The MSI path still uses MSAL + ManagedIdentityCredential which handles FMI via a different mechanism.
Status: Awaiting @azure/msal-node to ship native fmiPath support. Remove the HTTP workaround once available.
LangChainTraceInstrumentor.instrument(LangChainCallbacks) requires ObservabilityManager to be fully initialized. Calling it as a standalone statement after useMicrosoftOpenTelemetry() throws "ObservabilityManager is not configured yet" when a365.enabled: true.
Workaround: Use instrumentationOptions: { langchain: {} } inside the useMicrosoftOpenTelemetry() options object. This ensures the distro initializes the manager and the LangChain instrumentor in the correct order.
InferenceCallDetails Constructor — providerName Is RequiredThe InferenceCallDetails constructor signature is (InferenceOperationType operationName, string model, string providerName, int? inputTokens, int? outputTokens, string[]? finishReasons, string? conversationId). The providerName parameter is required (not optional). Omitting it causes CS7036.
Correct usage:
new InferenceCallDetails(
operationName: InferenceOperationType.Chat,
model: "gpt-5.4",
providerName: "Azure OpenAI")
ExecuteToolScope.RecordResponse Takes string, Not ResponseExecuteToolScope.RecordResponse() accepts a string parameter (the tool result), not a Response object. Passing new Response(...) causes CS1503.
Correct usage:
toolScope.RecordResponse(resultString);
appsettings.json — S2S Configuration NotesFor S2S agents:
EnableAgent365Exporter must be true in appsettings.json (not false — a365 setup may write false by default)UseManagedIdentity must be false for local development (MSI is only available on Azure infrastructure)ClientId and ClientSecret are required under Agent365Observability for the FMI 3-hop chainFor S2S agents, CallerDetails with UserDetails (userId, userName, userEmail) must be passed to InvokeAgentScope.Start() / .start(). Without CallerDetails, exported spans reach the observability API (HTTP 200) but do not appear in the Microsoft Admin Center (MAC) portal's Advanced Hunting view.
Node.js API differences:
InvokeAgentScope.start() takes CallerDetails (wraps userDetails) as 4th parameterInferenceScope.start() and ExecuteToolScope.start() take UserDetails directly as 4th parameterOutputScope.start() takes UserDetails directly as 4th parameter.NET API:
InvokeAgentScope.Start() takes CallerDetails (wraps UserDetails) as 4th parameterCallerDetails directlyRecommendation: For agents without a real signed-in user (typically S2S, but can apply to OBO scenarios with no UI), use the Blueprint sponsor's identity:
UserId = Blueprint App (Client) IDUserName = Blueprint display nameUserEmail = Agent sponsor's email address${CLAUDE_PLUGIN_ROOT}/shared/agent-detection.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/dotnet-observability.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/nodejs-observability.md${CLAUDE_PLUGIN_ROOT}/skills/instrument-observability/references/python-observability.mdWhat SKILL.md sets; muted values are Claude Code's defaults
sonnetnpx claudepluginhub microsoft/agent365-skills --plugin agent3658 skills in this plugin
/a365-code-validatorValidates and optionally fixes Agent 365 observability code so an agent actually emits MAC Activity telemetry. Use when an Agent 365 agent's telemetry isn't reaching MAC Activity or Defender, when spans export (HTTP 200 / "sent") but Activity stays empty, when the caller or agent id looks wrong in reporting, or to pre-flight whether an agent will emit MAC Activity before shipping. Diagnoses and fixes existing instrumentation; do NOT use it to add observability from scratch — use instrument-observability for that. Checks exporter activation, runtime agent-identity binding (vs blueprint id), the app-only S2S token shape (and any leftover delegated OBO telemetry token), S2S endpoint selection in every auth mode, the required semantic spans (invoke_agent/chat/execute_tool/output_messages), Activity attributes, and live blueprint grants and inheritance through read-only a365 Microsoft Graph diagnostics. Read-only by default; asks before applying safe fixes. Python, Node.js, and .NET.
/a365-setupEntry point for general Agent 365 (A365) registration and CLI setup — use this skill whenever the user wants to "set up A365", "register agent", "create blueprint", or general A365 onboarding for non-AI-Teammate agents (Register, Observability paths). Verifies and installs the CLI, validates Azure prerequisites, then delegates to make-a365-agent or make-ai-teammate at Step 3. Does NOT run a365 setup all inline — setup is run by the delegated skill. Supports .NET AgentFramework, Node.js LangChain, and Python agents.
/add-workiq-toolsAdds WorkIQ MCP tool servers to an existing .NET AgentFramework, Node.js, or Python agent using the A365 CLI. Runs a365 develop list-available to show the catalog, adds selected servers via a365 develop add-mcp-servers (which writes ToolingManifest.json), wires McpToolRegistrationService in the agent code, and guides the user through the permissions handoff. Non-destructive and idempotent.
/make-a365-agentProvisions a non-AI Teammate agent with Agent 365 — use this skill for Register and Observability paths. Runs a365 setup all to create the Blueprint and Entra ID permissions. After setup, always offers instrument-observability (optional) and add-workiq-tools (optional, skipped automatically when authMode = s2s) as add-ons. Supports .NET AgentFramework, Node.js, and Python agents. Normally delegated to from a365-setup after CLI and Azure prerequisites are confirmed. Can also be invoked directly when those steps are already done.
/make-ai-teammateTransforms a non-M365 agent into a Microsoft Agent 365 AI Teammate. Supports all major frameworks across .NET (AgentFramework, Semantic Kernel), Node.js (LangChain, OpenAI Agents SDK, Claude SDK, Semantic Kernel, Google ADK), and Python (AgentFramework, LangChain, OpenAI, Claude, Semantic Kernel, Google ADK). Adds the hosting layer (Express/CloudAdapter for Node.js, ASP.NET Core for .NET, aiohttp for Python), AgentApplication class with message routing and typing indicators, email notifications, and all required packages and env vars. Wraps existing LLM code — does not replace it. Requires a365-setup to have been run first.
/purview-dlp-integrationIntegrate Microsoft Purview DLP (data loss prevention) + audit into an existing Microsoft Agent 365 (A365 SDK) agent, so sensitive prompts are blocked before the LLM and responses can be audited. Use when a user wants to add Purview DLP to an AI agent, block sensitive data (credit cards, SSNs, PII) in agent turns, enforce data protection/compliance on an A365 AgentApplication, call the Graph processContent API, or wire a DLP gate into agent code. Bundles drop-in guards for Node.js/TypeScript, Python, and .NET, minimal wiring for each, a PowerShell script to create the AI-apps DLP policy, a Purview portal/tenant enablement guide, and verification + troubleshooting. Works with A365 agents in Node.js (@microsoft/agents-hosting), Python (microsoft-agents-hosting-*), and .NET (Microsoft.Agents.*).
Other plugins' skills for the same job