An "almost magical" OpenTelemetry integration for .NET 9 - Presets for logs, traces, and metrics with minimal configuration.
- One-line setup for complete observability (logs, traces, metrics)
- Minimal dependencies in the Core package
- Convention over configuration with sensible defaults
- Azure Monitor / Application Insights integration via optional adapter
- Automatic instrumentation for ASP.NET Core, HttpClient, and more
- Production-ready with best practices built-in
| Package | Description | NuGet |
|---|---|---|
| OtelKit.Core | Minimal, dependency-light OpenTelemetry helper | |
| OtelKit.Azure | Optional Azure Monitor / Application Insights adapter |
Perfect for development and testing:
using OtelKit.Core;
var builder = WebApplication.CreateBuilder(args);
// One-line setup with console output
builder.Services.AddOtelKit(options =>
options.UseConsole()
);
var app = builder.Build();
app.Run();For production with Application Insights:
using OtelKit.Core;
using OtelKit.Azure;
var builder = WebApplication.CreateBuilder(args);
// One-line setup with Azure Monitor
builder.Services.AddOtelKit(options =>
options.UseAzureMonitor(builder.Configuration["ApplicationInsights:ConnectionString"]!)
);
var app = builder.Build();
app.Run();Or use environment variables:
builder.Services.AddOtelKit(options =>
options.UseAzureMonitorFromEnvironment()
);builder.Services.AddOtelKit(options => options
.WithService("MyAwesomeService", "1.0.0", "Production")
.UseConsole()
);Add custom attributes to your telemetry:
builder.Services.AddOtelKit(options => options
.WithResourceAttribute("environment", "production")
.WithResourceAttribute("datacenter", "us-east-1")
.WithResourceAttribute("team", "platform")
.UseAzureMonitor(connectionString)
);Disable specific telemetry types if needed:
builder.Services.AddOtelKit(options => options
.DisableMetrics() // Only logs and traces
.UseAzureMonitor(connectionString)
);Combine console output with Azure Monitor:
builder.Services.AddOtelKit(options => options
.UseConsole()
.UseAzureMonitor(connectionString)
);For advanced scenarios, use the ConfigureWith method:
builder.Services.AddOtelKit(options => options
.ConfigureWith((serviceProvider, context) =>
{
// Access the tracing builder
context.TracingBuilder?.AddSource("MyCustomSource");
// Access the metrics builder
context.MetricsBuilder?.AddMeter("MyCustomMeter");
// Access the logging options
if (context.LoggingOptions != null)
{
context.LoggingOptions.IncludeScopes = true;
}
})
);OtelKit provides flexible configuration through OtelKitOptions. You can configure it using either the fluent API or direct property assignment.
builder.Services.AddOtelKit(options => options
.WithService("MyService", "1.0.0", "MyNamespace")
.UseConsole()
.DisableMetrics()
.DisableLogging()
);builder.Services.AddOtelKit(options =>
{
options.ServiceName = "MyService";
options.ServiceVersion = "1.0.0";
options.ServiceNamespace = "MyNamespace";
options.EnableConsoleExporter = true;
options.EnableMetrics = false;
options.EnableLogging = false;
});| Property | Type | Default | Description |
|---|---|---|---|
ServiceName |
string |
"UnknownService" |
Identifies your service in telemetry data |
ServiceVersion |
string? |
null |
Version of your service |
ServiceNamespace |
string? |
null |
Logical namespace for grouping services |
| Property | Type | Default | Description |
|---|---|---|---|
EnableTracing |
bool |
true |
Enable distributed tracing |
EnableMetrics |
bool |
true |
Enable metrics collection |
EnableLogging |
bool |
true |
Enable log export to OpenTelemetry |
| Property | Type | Default | Description |
|---|---|---|---|
EnableConsoleExporter |
bool |
false |
Output telemetry to console for debugging |
| Property | Type | Default | Description |
|---|---|---|---|
EnableAspNetCoreInstrumentation |
bool |
true |
Auto-instrument ASP.NET Core requests |
EnableHttpClientInstrumentation |
bool |
true |
Auto-instrument outgoing HTTP calls |
| Property | Type | Default | Description |
|---|---|---|---|
ResourceAttributes |
Dictionary<string, object> |
new() |
Custom attributes for the telemetry resource |
builder.Services.AddOtelKit(options =>
{
options.ServiceName = "MyApi";
options.EnableConsoleExporter = true;
});builder.Services.AddOtelKit(options =>
{
options.ServiceName = "MyApi";
options.ServiceVersion = "1.0.0";
options.EnableMetrics = false;
});builder.Services.AddOtelKit(options =>
{
options.ServiceName = "MyApi";
options.EnableAspNetCoreInstrumentation = false;
options.EnableHttpClientInstrumentation = false;
});OtelKit automatically instruments:
- ✅ ASP.NET Core (HTTP requests, MVC, minimal APIs)
- ✅ HttpClient (outgoing HTTP calls)
- ✅ .NET Runtime metrics (GC, thread pool, exceptions)
- Traces - Distributed tracing for request flows
- Metrics - Performance counters and custom metrics
- Logs - Structured logging with correlation
OtelKit follows a modular architecture:
┌─────────────────────────────────────┐
│ Your Application │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ OtelKit.Core │
│ (Core abstractions + OpenTelemetry)│
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Optional Adapters │
│ ┌─────────────────────────────┐ │
│ │ OtelKit.Azure │ │
│ │ (Azure Monitor Exporter) │ │
│ └─────────────────────────────┘ │
└─────────────────────────────────────┘
Run all tests:
dotnet testRun specific test project:
dotnet test tests/OtelKit.Core.Tests
dotnet test tests/OtelKit.Azure.TestsThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For more detailed documentation, see the docs folder.
Built on top of the excellent OpenTelemetry .NET project.
Made with ❤️ for the .NET community