configuring-opentelemetry-dotnet

Configure OpenTelemetry tracing, metrics, and logging in ASP.NET Core applications.

Updated Jul 12, 2026
One-click install
npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill configuring-opentelemetry-dotnet-patrick-rex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: configuring-opentelemetry-dotnet
Source: https://github.com/Patrick-Rex/DotNetTechSamples/tree/main/.agents/plugins/dotnet-aspnetcore/skills/configuring-opentelemetry-dotnet
Command: npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill configuring-opentelemetry-dotnet-patrick-rex

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up observability in ASP.NET Core involves choosing the right OpenTelemetry packages, wiring traces, metrics, and logs into the DI container, and ensuring custom spans and meters actually get exported. This Skill provides a complete, correct configuration workflow that avoids common silent failures like unmatched ActivitySource names. ## Core Features & Use Cases - Full Signal Setup: Configures distributed tracing, metrics, and logging with a single OTLP exporter via AddOpenTelemetry() in Program.cs. - Custom Instrumentation: Guides creation of custom spans with ActivitySource and custom metrics with IMeterFactory, including counters, histograms, and up-down counters. - Distributed Context Propagation: Shows manual trace context injection and extraction for non-HTTP scenarios like message queues. - Use Case: You are adding observability to an order-processing API. Use this Skill to install the correct packages, register ASP.NET Core and HttpClient instrumentation, create a ProcessOrder span with business tags, and export everything to Jaeger via OTLP. ## Quick Start Configure OpenTelemetry tracing, metrics, and logging with an OTLP exporter in my ASP.NET Core project and add a custom ActivitySource for my order service.

Frequently Asked Questions about configuring-opentelemetry-dotnet

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add OpenTelemetry to an ASP.NET Core application?

Install OpenTelemetry.Extensions.Hosting, OpenTelemetry.Instrumentation.AspNetCore, and OpenTelemetry.Exporter.OpenTelemetryProtocol, then call AddOpenTelemetry() in Program.cs with WithTracing, WithMetrics, and WithLogging. Finish with UseOtlpExporter() to export all signals via OTLP.

Which OpenTelemetry NuGet packages do I need for .NET?

You need OpenTelemetry.Extensions.Hosting for DI integration, plus instrumentation packages matching your stack such as AspNetCore, Http, SqlClient, or EntityFrameworkCore. Installing the base OpenTelemetry package alone is insufficient for ASP.NET Core hosting.

Why does ActivitySource.StartActivity return null in .NET?

StartActivity returns null when the ActivitySource name does not match any name registered via AddSource() in the tracing configuration. Names must match exactly, and unmatched sources are silently ignored, which is the most common OpenTelemetry debugging issue.

How do I correlate logs with traces in OpenTelemetry .NET?

Call WithLogging() on the AddOpenTelemetry() builder and set IncludeScopes to true. Each ILogger entry then automatically includes TraceId and SpanId, and the OTLP exporter handles logs alongside traces and metrics without extra packages.

What is the difference between OTLP gRPC and HTTP exporters?

The OTLP exporter defaults to gRPC on port 4317, while HTTP/protobuf uses port 4318. If your collector only accepts HTTP, set OtlpExportProtocol.HttpProtobuf, and override endpoints via the OTEL_EXPORTER_OTLP_ENDPOINT environment variable.

When should I not use the OpenTelemetry SDK for .NET?

Avoid it when you only need application-level logging, where ILogger or Serilog suffices, or when you use the Application Insights SDK directly since it has a different API. It also does not fit scenarios requiring a commercial vendor's proprietary APM SDK.