configuring-opentelemetry-dotnet
Configure OpenTelemetry distributed tracing, metrics, and logging in ASP.NET Core using the .NET OpenTelemetry SDK.
Skill by SteffenCarlsen
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/steffencarlsen-configuring-opentelemetry-dotnet
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
configuring-opentelemetry-dotnet- Description
- Configure OpenTelemetry distributed tracing, metrics, and logging in ASP.NET Core using the .NET OpenTelemetry SDK. Use when adding observability, setting up OTLP exporters, creating custom metrics/spans, or troubleshooting distributed trace correlation.
- License
- MIT
- Instructions
- 285 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Configuring OpenTelemetry in .NET
## When to Use
- Adding distributed tracing to an ASP.NET Core application
- Setting up OpenTelemetry exporters (OTLP is the primary protocol; Jaeger accepts OTLP natively; Prometheus OTLP ingestion requires explicit opt-in)
- Creating custom metrics or trace spans for business operations
- Troubleshooting distributed trace context propagation across services
## When Not to Use
- The user wants application-level logging only (use ILogger, Serilog)
- The user is using Application Insights SDK directly (different API)
- The user needs APM with a commercial vendor's proprietary SDK
## Inputs
| Input | Required | Description |
|-------|----------|-------------|
| ASP.NET Core project | Yes | The application to instrument |
| Observability backend | No | Where to export: OTLP collector, Aspire dashboard, Jaeger (accepts OTLP natively) |
## Workflow
### Step 1: Install the correct packages
**There are many OpenTelemetry NuGet packages. Install exactly these:**
```bash
# Core SDK + ASP.NET Core instrumentation + logging integration
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.Http
# Exporter
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol # OTLP exporter for traces, metrics, AND logs
# Optional — dev/local debugging only (do NOT include in production deployments)
# dotnet add package OpenTelemetry.Exporter.Console
```
**Do NOT install `OpenTelemetry` alone** — you need `OpenTelemetry.Extensions.Hosting` for proper DI integration.
#### Optional: additional auto-instrumentation packages
Install only the packages that match the libraries your application uses:
```bash
dotnet add package OpenTelemetry.Instrumentation.SqlClient # SQL Server queries
dotnet add package OpenTelemetry.Instrumentation.EntityFrameworkCore # EF Core
dotnet add package OpenTelemetry.Instrumentation.GrpcNetClient # gRPC calls
dotnet add package OpenTelemetry.Instrumentation.Runtime # GC, thread pool metrics
```
### Step 2: Configure all signals in Program.cs
```csharp
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using OpenTelemetry.Metrics;
using OpenTelemetry.Logs;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource
.AddService(serviceName: builder.Environment.ApplicationName))
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation(options =>
{
// Filter out health check endpoints from traces
options.Filter = httpContext =>
!httpContext.Request.Path.StartsWithSegments("/healthz");
})
.AddHttpClientInstrumentation(options =>
{
options.RecordException = true;
})
// Optional: add SQL instrumentation if using SqlClient directly
// .AddSqlClientInstrumentation(options =>
// {
// options.SetDbStatementForText = true;
// options.RecordException = true;
// })
// Custom activity sources (must match ActivitySource names in your code)
.AddSource("MyApp.Orders")
.AddSource("MyApp.Payments")
.AddSource("MyApp.Messaging"))
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
// Optional: .AddRuntimeInstrumentation() for GC and thread pool metrics
// (requires OpenTelemetry.Instrumentation.Runtime package)
// Custom meters (must match Meter names in your code)
.AddMeter("MyApp.Metrics"))
.WithLogging(logging =>
{
logging.IncludeScopes = true;
// logging.IncludeFormattedMessage = true; // Enable if you need the formatted message string in log exports
})
// Single OTLP exporter for all signals — reads OTEL_EXPORTER_OTLP_ENDPOINT
// env var (defaults to http://localhost:4317). Override via environment variable
// or appsettings.json configuration.
.UseOtlpExporter();
```
### Step 3: Understanding log–trace correlation
The `.WithLogging()` call in Step 2 integrates ILogger with OpenTelemetry:
- Each log entry automatically includes TraceId and SpanId for correlation with traces
- The service resource from `.ConfigureResource()` propagates to logs automatically
- `UseOtlpExporter()` applies to logs alongside traces and metrics
- No additional packages or separate `SetResourceBuilder` call needed
### Step 4: Create custom spans (Activities) for business operations
```csharp
using System.Diagnostics;From SteffenCarlsen/agent-skills, MIT.
More from SteffenCarlsen/agent-skills
- 0.524score
code-testing-agent
SteffenCarlsen
Generates and writes new unit tests for any programming language using a Research-Plan-Implement pipeline.
SkillBFreshness: BClaude Code +9 - 0.479score
android-tombstone-symbolication
SteffenCarlsen
Symbolicate the .NET runtime frames in an Android tombstone file.
SkillCFreshness: CClaude Code +9 - 0.479score
convert-to-cpm
SteffenCarlsen
Convert .NET projects and solutions (.sln, .slnx) to NuGet Central Package Management (CPM) using Directory.Packages.props.
SkillCFreshness: CClaude Code +9 - 0.479score
author-component
SteffenCarlsen
Create or review Blazor components (.razor files) with correct architecture.
SkillCFreshness: CClaude Code +9 - 0.479score
clr-activation-debugging
SteffenCarlsen
Diagnoses .NET Framework CLR activation issues using CLR activation logs (CLRLoad logs) produced by mscoree.dll.
SkillCFreshness: CClaude Code +9 - 0.479score
apple-crash-symbolication
SteffenCarlsen
Symbolicate .NET runtime frames in Apple platform .ips crash logs (iOS, tvOS, Mac Catalyst, macOS).
SkillCFreshness: CClaude Code +9 - 0.474score
convert-blazor-server-to-webapp
SteffenCarlsen
Guides conversion of a pre-.NET 8 Blazor Server app into a .NET 8+ Blazor Web App.
SkillCFreshness: CClaude Code +9 - 0.474score
build-parallelism
SteffenCarlsen
Guide for optimizing MSBuild build parallelism and multi-project scheduling.
SkillCFreshness: CClaude Code +9 - 0.474score
build-perf-baseline
SteffenCarlsen
Establish build performance baselines and apply systematic optimization techniques.
SkillCFreshness: CClaude Code +9 - 0.474score
build-perf-diagnostics
SteffenCarlsen
Diagnose MSBuild build performance bottlenecks using binary log analysis.
SkillCFreshness: CClaude Code +9 - 0.474score
check-bin-obj-clash
SteffenCarlsen
Detects MSBuild projects with conflicting OutputPath or IntermediateOutputPath.
SkillCFreshness: CClaude Code +9 - 0.474score
binlog-failure-analysis
SteffenCarlsen
Analyze MSBuild binary logs to diagnose build failures.
SkillCFreshness: CClaude Code +9
Signals
- Stars
- 0
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Jul 15, 2026 (3 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/SteffenCarlsen/agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from SteffenCarlsen
- 0.524score
code-testing-agent
SteffenCarlsen
Generates and writes new unit tests for any programming language using a Research-Plan-Implement pipeline.
SkillBFreshness: BClaude Code +9 - 0.479score
apple-crash-symbolication
SteffenCarlsen
Symbolicate .NET runtime frames in Apple platform .ips crash logs (iOS, tvOS, Mac Catalyst, macOS).
SkillCFreshness: CClaude Code +9 - 0.479score
clr-activation-debugging
SteffenCarlsen
Diagnoses .NET Framework CLR activation issues using CLR activation logs (CLRLoad logs) produced by mscoree.dll.
SkillCFreshness: CClaude Code +9 - 0.479score
author-component
SteffenCarlsen
Create or review Blazor components (.razor files) with correct architecture.
SkillCFreshness: CClaude Code +9 - 0.479score
android-tombstone-symbolication
SteffenCarlsen
Symbolicate the .NET runtime frames in an Android tombstone file.
SkillCFreshness: CClaude Code +9 - 0.479score
convert-to-cpm
SteffenCarlsen
Convert .NET projects and solutions (.sln, .slnx) to NuGet Central Package Management (CPM) using Directory.Packages.props.
SkillCFreshness: CClaude Code +9
Cite this page
configuring-opentelemetry-dotnet skill. Agent Mart. https://agentmart.dev/skills/steffencarlsen-configuring-opentelemetry-dotnet (last updated 2026-10-24)