Skip to content

IsaacJordan/OtelKit

Repository files navigation

OtelKit

.NET License

An "almost magical" OpenTelemetry integration for .NET 9 - Presets for logs, traces, and metrics with minimal configuration.

🚀 Features

  • 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

📦 Packages

Package Description NuGet
OtelKit.Core Minimal, dependency-light OpenTelemetry helper NuGet
OtelKit.Azure Optional Azure Monitor / Application Insights adapter NuGet

🎯 Quick Start

Basic Setup (Console Output)

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();

Azure Monitor Integration

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()
);

🎨 Advanced Configuration

Custom Service Information

builder.Services.AddOtelKit(options => options
    .WithService("MyAwesomeService", "1.0.0", "Production")
    .UseConsole()
);

Resource Attributes

Add custom attributes to your telemetry:

builder.Services.AddOtelKit(options => options
    .WithResourceAttribute("environment", "production")
    .WithResourceAttribute("datacenter", "us-east-1")
    .WithResourceAttribute("team", "platform")
    .UseAzureMonitor(connectionString)
);

Selective Telemetry

Disable specific telemetry types if needed:

builder.Services.AddOtelKit(options => options
    .DisableMetrics()  // Only logs and traces
    .UseAzureMonitor(connectionString)
);

Multiple Exporters

Combine console output with Azure Monitor:

builder.Services.AddOtelKit(options => options
    .UseConsole()
    .UseAzureMonitor(connectionString)
);

Custom Configuration

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;
        }
    })
);

⚙️ Configuration Options Reference

OtelKit provides flexible configuration through OtelKitOptions. You can configure it using either the fluent API or direct property assignment.

Fluent API (Recommended)

builder.Services.AddOtelKit(options => options
    .WithService("MyService", "1.0.0", "MyNamespace")
    .UseConsole()
    .DisableMetrics()
    .DisableLogging()
);

Direct Configuration

builder.Services.AddOtelKit(options =>
{
    options.ServiceName = "MyService";
    options.ServiceVersion = "1.0.0";
    options.ServiceNamespace = "MyNamespace";
    options.EnableConsoleExporter = true;
    options.EnableMetrics = false;
    options.EnableLogging = false;
});

Available Options

Service Identification

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

Telemetry Signals

Property Type Default Description
EnableTracing bool true Enable distributed tracing
EnableMetrics bool true Enable metrics collection
EnableLogging bool true Enable log export to OpenTelemetry

Exporters

Property Type Default Description
EnableConsoleExporter bool false Output telemetry to console for debugging

Instrumentation

Property Type Default Description
EnableAspNetCoreInstrumentation bool true Auto-instrument ASP.NET Core requests
EnableHttpClientInstrumentation bool true Auto-instrument outgoing HTTP calls

Advanced

Property Type Default Description
ResourceAttributes Dictionary<string, object> new() Custom attributes for the telemetry resource

Common Configuration Scenarios

Development Environment (Console Only)

builder.Services.AddOtelKit(options =>
{
    options.ServiceName = "MyApi";
    options.EnableConsoleExporter = true;
});

Production with Traces and Logs Only

builder.Services.AddOtelKit(options =>
{
    options.ServiceName = "MyApi";
    options.ServiceVersion = "1.0.0";
    options.EnableMetrics = false;
});

Minimal Configuration (No Auto-Instrumentation)

builder.Services.AddOtelKit(options =>
{
    options.ServiceName = "MyApi";
    options.EnableAspNetCoreInstrumentation = false;
    options.EnableHttpClientInstrumentation = false;
});

📚 What's Included?

Automatic Instrumentation

OtelKit automatically instruments:

  • ✅ ASP.NET Core (HTTP requests, MVC, minimal APIs)
  • ✅ HttpClient (outgoing HTTP calls)
  • ✅ .NET Runtime metrics (GC, thread pool, exceptions)

Telemetry Types

  • Traces - Distributed tracing for request flows
  • Metrics - Performance counters and custom metrics
  • Logs - Structured logging with correlation

🏗️ Architecture

OtelKit follows a modular architecture:

┌─────────────────────────────────────┐
│         Your Application            │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│         OtelKit.Core                │
│  (Core abstractions + OpenTelemetry)│
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│       Optional Adapters             │
│  ┌─────────────────────────────┐   │
│  │      OtelKit.Azure           │   │
│  │  (Azure Monitor Exporter)    │   │
│  └─────────────────────────────┘   │
└─────────────────────────────────────┘

🧪 Testing

Run all tests:

dotnet test

Run specific test project:

dotnet test tests/OtelKit.Core.Tests
dotnet test tests/OtelKit.Azure.Tests

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📖 Documentation

For more detailed documentation, see the docs folder.

🙏 Acknowledgments

Built on top of the excellent OpenTelemetry .NET project.


Made with ❤️ for the .NET community

About

An "almost magical" OpenTelemetry integration for .NET 9 - Presets for logs, traces, and metrics with minimal configuration and Azure Monitor / Application Insights integration via optional adapter.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors