/agents-for-dotnet:agents-sdk-dotnet-otelfrom agents-for-dotnet
Configures OpenTelemetry observability for Microsoft 365 Agents SDK .NET applications, including traces, metrics, logs, Aspire Dashboard, and Azure Monitor. Enforces safe telemetry practices.
Ships in agents-for-dotnet. 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.
Configure traces, metrics, and logs for an Agents SDK application, including
the SDK's built-in Microsoft.Agents.Core signals and a local Aspire Dashboard.
Make the smallest complete change that fits the existing hosting and telemetry
architecture.
Use this skill for both AgentApplication and ActivityHandler applications.
The SDK telemetry source is the same for both.
AddOpenTelemetry() registration instead of creating competing providers.builder.Build() and before the app processes
agent requests.AgentsTelemetry.SourceName and
AgentsTelemetry.Meter; the SDK has no direct OpenTelemetry dependency and
publishes through System.Diagnostics.service.name. Do not use
Microsoft.Agents.Core as the service name; that is an instrumentation
source, not the application's identity.AlwaysOnSampler as a production default. Honor the standard
OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG configuration.Complete these steps in order.
Find:
*.csproj) and target framework.Program.cs or the host-builder entry point.AddOpenTelemetry, ConfigureOpenTelemetry,
UseAzureMonitor, AddOtlpExporter, AddApplicationInsightsTelemetry, or
custom observability extensions.ActivitySource, Meter, counters, histograms, and logging setup.appsettings*.json, launch profiles, environment
files, container definitions, or deployment manifests.Directory.Packages.props.If OpenTelemetry already exists, merge the Agents SDK source and meter into that registration. Do not replace existing exporters or instrumentation without a reason.
Use the repository's package-management convention. Keep all OpenTelemetry packages on a compatible stable version. When versions are not centrally managed, these commands select the latest stable packages:
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.Http
dotnet add package OpenTelemetry.Instrumentation.Runtime
Do not add the console exporter unless the user explicitly wants console telemetry. Do not add Azure Monitor packages unless Azure Monitor export is requested.
Prefer a project-local extension such as AgentOtelExtensions.cs. Adapt the
namespace and service name to the project:
using Microsoft.Agents.Core.Telemetry;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
namespace MyAgent;
public static class AgentOtelExtensions
{
public static TBuilder AddAgentObservability<TBuilder>(
this TBuilder builder,
string serviceName,
string? serviceVersion = null,
string? applicationTelemetrySource = null)
where TBuilder : IHostApplicationBuilder
{
string resolvedServiceName =
builder.Configuration["OTEL_SERVICE_NAME"] ?? serviceName;
var openTelemetry = builder.Services
.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(
serviceName: resolvedServiceName,
serviceVersion: serviceVersion));
openTelemetry.WithTracing(tracing =>
{
tracing
.AddSource(AgentsTelemetry.SourceName)
.AddAspNetCoreInstrumentation(options =>
{
options.RecordException = true;
options.Filter = context =>
!context.Request.Path.StartsWithSegments("/health");
})
.AddHttpClientInstrumentation(options =>
{
options.RecordException = true;
})
.AddOtlpExporter();
if (!string.IsNullOrWhiteSpace(applicationTelemetrySource))
{
tracing.AddSource(applicationTelemetrySource);
}
});
openTelemetry.WithMetrics(metrics =>
{
metrics
.AddMeter(AgentsTelemetry.SourceName)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddOtlpExporter();
if (!string.IsNullOrWhiteSpace(applicationTelemetrySource))
{
metrics.AddMeter(applicationTelemetrySource);
}
});
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
logging.AddOtlpExporter();
});
return builder;
}
}
Notes:
/health, keeping the filter is harmless.AgentsTelemetry.SourceName source and meter."Microsoft.AspNetCore" or "System.Net.Http" activity
source strings when the corresponding instrumentation packages are already
configured.service.name should identify the application, for example
contoso-support-agent. Keep it stable across instances.service.version for the deployed build/version when one is available.deployment.environment.name for stable
deployment metadata, not request-specific data.Call the extension before the agent registrations:
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.AddAgentObservability(
serviceName: "contoso-support-agent",
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString(),
applicationTelemetrySource: AgentTelemetry.SourceName);
builder.AddAgentDefaults()
.AddAgent<MyAgent>()
.AddAgentAuthorization(options => options.AddAgentAspNetAuthentication());
If no custom application telemetry is needed, omit
applicationTelemetrySource and do not create AgentTelemetry.
For a local Aspire Dashboard using OTLP/gRPC:
$env:OTEL_SERVICE_NAME = "contoso-support-agent"
$env:OTEL_EXPORTER_OTLP_ENDPOINT = "http://localhost:4317"
$env:OTEL_EXPORTER_OTLP_PROTOCOL = "grpc"
dotnet run
Standard environment variables to support:
| Variable | Purpose |
|---|---|
OTEL_SERVICE_NAME | Stable application service name |
OTEL_RESOURCE_ATTRIBUTES | Stable resource metadata |
OTEL_EXPORTER_OTLP_ENDPOINT | Base OTLP collector endpoint |
OTEL_EXPORTER_OTLP_PROTOCOL | Usually grpc or http/protobuf |
OTEL_EXPORTER_OTLP_HEADERS | Collector authentication headers; keep secret |
OTEL_TRACES_SAMPLER | Trace sampling strategy |
OTEL_TRACES_SAMPLER_ARG | Sampling strategy argument |
Use user secrets, a secret store, or deployment secrets for
OTEL_EXPORTER_OTLP_HEADERS and Azure Monitor connection strings. Never place
them in committed appsettings.json or launch profiles.
The Agents SDK already emits adapter, turn, route, connector, storage, authentication, and authorization signals. Add custom telemetry for application-specific operations, not to duplicate those SDK spans.
Use one shared source name for the application's custom traces and metrics:
using System.Diagnostics;
using System.Diagnostics.Metrics;
namespace MyAgent;
public static class AgentTelemetry
{
public const string SourceName = "Contoso.SupportAgent";
public static readonly ActivitySource ActivitySource = new(SourceName);
public static readonly Meter Meter = new(SourceName);
public static readonly Counter<long> RouteExecutions =
Meter.CreateCounter<long>(
"agent.route.executions",
unit: "{execution}",
description: "Number of application route executions.");
public static readonly Histogram<double> RouteDuration =
Meter.CreateHistogram<double>(
"agent.route.duration",
unit: "ms",
description: "Application route execution duration.");
}
Instrument a handler with bounded attributes:
using System.Diagnostics;
using Activity? activity =
AgentTelemetry.ActivitySource.StartActivity("agent.route.execute");
long started = Stopwatch.GetTimestamp();
string status = "ok";
try
{
await HandleMessageAsync(turnContext, cancellationToken);
}
catch (Exception exception)
{
status = "error";
activity?.SetStatus(ActivityStatusCode.Error, exception.Message);
activity?.AddException(exception);
throw;
}
finally
{
TagList tags = new()
{
{ "route.type", "message" },
{ "status", status }
};
AgentTelemetry.RouteExecutions.Add(1, tags);
AgentTelemetry.RouteDuration.Record(
Stopwatch.GetElapsedTime(started).TotalMilliseconds,
tags);
}
If AddException is unavailable for the project's package version, add an
exception activity event using the OpenTelemetry semantic attributes. Do not
log or tag the prompt, response, or exception message as a metric dimension.
Copy assets/start-aspire-dashboard.ps1 from this skill into a suitable local
development or scripts directory. The script pulls
mcr.microsoft.com/dotnet/aspire-dashboard:latest.
Run:
.\start-aspire-dashboard.ps1
Then open http://localhost:18888. The script:
127.0.0.1.4317 and OTLP/HTTP on 4318.Do not start a second container if aspire-dashboard already exists. Inspect
or reuse the existing container instead. Stop the generated local dashboard
with:
docker stop aspire-dashboard
dotnet build.service.name.agents.adapter.process or agents.app.run.agents.activities.received, agents.turn.count, or
another operation exercised by the test.Error while the original exception behavior remains intact.See references/sdk-signals.md for the canonical Agents SDK source, common spans, metrics, and dashboard checks.
Use OpenTelemetry.Exporter.OpenTelemetryProtocol and AddOtlpExporter().
This is the default for local development and vendor-neutral deployments.
When requested, add the stable
Azure.Monitor.OpenTelemetry.AspNetCore package and configure
UseAzureMonitor() using APPLICATIONINSIGHTS_CONNECTION_STRING from a
secret source. Preserve OTLP export only when dual export is intentional.
Do not add both exporters accidentally.
Use only for short-lived local diagnosis. Console telemetry is noisy, can expose data in terminal logs, and is not a production exporter.
| Symptom | Check |
|---|---|
| No SDK spans | .AddSource(AgentsTelemetry.SourceName) is present before requests |
| No SDK metrics | .AddMeter(AgentsTelemetry.SourceName) is present |
| Custom spans missing | The custom ActivitySource name exactly matches .AddSource(...) |
| Custom metrics missing | The custom Meter name exactly matches .AddMeter(...) |
| Dashboard has no resource | Dashboard is running; endpoint is http://localhost:4317; protocol is grpc |
| Traces appear but metrics do not | Metrics can take one or more OTEL_METRIC_EXPORT_INTERVAL periods plus dashboard processing time to appear; wait and refresh before troubleshooting |
OTLP Unimplemented or protocol errors | Collector port and OTEL_EXPORTER_OTLP_PROTOCOL do not match |
| Duplicate spans or metrics | Multiple providers or repeated instrumentation registrations exist |
| High memory or telemetry cost | Remove high-cardinality tags and reduce trace sampling |
| Logs appear but traces do not | Trace source subscription or sampling configuration is wrong |
| Traces appear but logs do not | builder.Logging.AddOpenTelemetry(...).AddOtlpExporter() is missing |
| Container name conflict | Reuse or stop the existing aspire-dashboard container |
If the SDK signals differ from references/sdk-signals.md, the sample no longer builds, or the Aspire setup changes, draft an issue containing the project type, package versions, configuration, expected signal, actual result, and any workaround: https://github.com/microsoft/agents/issues/new
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
.NET, C#, OpenTelemetry, Azure
opentelemetry, dotnet, agents-sdk, observability, telemetry, azure-monitor
7 skills in this plugin
/agents-sdk-dotnetUse when any code imports Microsoft.Agents.Hosting.AspNetCore, Microsoft.Agents.Builder, or related Agents SDK packages, or when the user is building, configuring, or asking questions about a Microsoft 365 Agents SDK agent in C# / .NET. Trigger on questions about appsettings.json, connection configuration, AgentApplication patterns, OAuth sign-in flows, storage backends, cards, streaming, or local testing with the Agents Playground — even if no code exists yet and the user is planning or asking how to get started.
/agents-sdk-dotnet-activityhandler-migrationUse when migrating a Microsoft 365 Agents SDK agent that uses ActivityHandler or TeamsActivityHandler to AgentApplication. This is ONLY for DotNet projects that uses `Microsoft.Agents.*` packages. Triggered by Agents SDK bots that subclass ActivityHandler or TeamsActivityHandler that need to be modernized to AgentApplication routing./agents-sdk-dotnet-debuggingUse when troubleshooting an agent built with the Microsoft Agents SDK (Microsoft.Agents.Hosting.AspNetCore and related packages) in C# / .NET. Trigger on any of these symptoms: build or C# compile errors, crashes on startup, 401 or auth errors on incoming requests, the bot not responding to messages, appsettings.json configuration problems, Azure AD credential failures (AADSTS errors), port conflicts, or the agent not connecting in Teams or the Agents Playground. Use even if the user doesn't mention the SDK by name — trigger on symptoms like "my bot won't start", "getting 401s", or "bot isn't responding."
npx claudepluginhub microsoft/agents --plugin agents-for-netOther plugins' skills for the same job