원클릭으로
dotnet-otel-instrumentation
Pattern for adding OpenTelemetry tracing to .NET projects with clean library/host separation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Pattern for adding OpenTelemetry tracing to .NET projects with clean library/host separation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | dotnet-otel-instrumentation |
| description | Pattern for adding OpenTelemetry tracing to .NET projects with clean library/host separation |
| domain | observability |
| confidence | low |
| source | earned |
When instrumenting .NET applications with OpenTelemetry, the standard pattern separates instrumentation (library code) from collection/export (host code). This keeps libraries lightweight and lets the host decide where telemetry goes.
Library projects use System.Diagnostics.ActivitySource and Activity for instrumentation. No OpenTelemetry NuGet packages in libraries. ActivitySource is declared as internal static readonly on the class that owns the operations:
public class MyService
{
internal static readonly ActivitySource ActivitySource = new("MyApp.MySubsystem");
public void DoWork()
{
using var activity = ActivitySource.StartActivity("mysubsystem.do_work");
activity?.SetTag("work.param", value);
// actual work
}
}
Only the composition root (CLI, web host, AppHost) references OpenTelemetry packages and registers sources by name:
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyApp"))
.AddSource("MyApp.MySubsystem")
.AddOtlpExporter()
.Build();
Use {subsystem}.{attribute} naming for span tags: midi.channel, note.name, sequence.title.
ActivitySource.StartActivity() returns null when no listener is registered. Always use activity?.SetTag() — never assume the activity exists.
Dispose TracerProvider before exit to flush pending spans. In CLI apps, do this explicitly. In hosted apps, use OpenTelemetry.Extensions.Hosting.
OpenTelemetry.* packages. Use System.Diagnostics only.AddSource() in the host.TracerProvider isn't disposed, the last batch of spans may be lost..SetTag() without null-conditional. Activity is null when no collector is listening.