OpenTelemetry instrumentation for assemblies.
License
—
Deps
4
Install Size
—
Vulns
✓ 0
Published
Feb 20, 2026
$ dotnet add package Intility.OpenTelemetry.Instrumentation.AssemblyA .NET library for automatically instrumenting assemblies with OpenTelemetry traces. This package enables automatic instrumentation of controllers and services within a specified assembly, tracing method calls and capturing method parameters.
Install the package from NuGet:
dotnet add package Intility.OpenTelemetry.Instrumentation.Assembly
Add the following packages to your .csproj:
<ItemGroup>
<PackageReference Include="Intility.OpenTelemetry.Instrumentation.Assembly" Version="0.1.2" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.11.0-beta.2" />
</ItemGroup>
Add assembly instrumentation to your OpenTelemetry configuration:
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
// Add OpenTelemetry
var otel = builder.Services.AddOpenTelemetry();
otel.ConfigureResource(r => r
.AddService(serviceName: "MyService")
// Optional, add serviceVersion and environment
// .AddAttributes(new Dictionary<string, string>(){
// { "deployment.environment.name", "Development" },
// { "service.version", "1.0.0" }
// } )
);
// Configure tracing
otel.WithTracing(tracing =>
{
// Add standard instrumentations
tracing.AddAspNetCoreInstrumentation();
tracing.AddHttpClientInstrumentation();
// Optional, dependent om your system
// tracing.AddEntityFrameworkCoreInstrumentation();
// tracing.AddRedisInstrumentation();
// Add exporter of your choice
tracing.AddConsoleExporter();
// or
tracing.AddOtlpExporter(otlpOptions =>
{
otlpOptions.Endpoint = new Uri("https://<url>/v1/traces");
// Enable Http for default tracing to logfire. When using port 4317,grpc is default.
otlpOptions.Protocol = OtlpExportProtocol.HttpProtobuf;
// Set the token if authentication is required
//otlpOptions.Headers = "Authorization=<Token>";
});
});
// Register your services
builder.Services.AddSingleton<IMyService, MyService>();
builder.Services.AddControllers();
// Add assembly instrumentation LAST
otel.AddAssemblyInstrumentation(typeof(Program).Assembly.FullName!);
Always add the assembly instrumentation after registering all services you want to instrument.
The assembly instrumentation will automatically:
The assembly name parameter should be the fully qualified assembly name:
typeof(Program).Assembly.FullName!
The library works by:
ActionFilter to trace ASP.NET Core controller actionsDispatchProxy class to create dynamic proxies for interface implementationsIn the sample application, you can see how the library automatically instruments:
WeatherForecastControllerWeatherForecastServiceEach method call becomes a span in the trace, with method parameters captured as attributes.
This project is licensed under the terms specified in the repository.
Contributions are welcome! Please feel free to submit a Pull Request.