Shared.K8.Common 1.0.3

dotnet add package Shared.K8.Common --version 1.0.3
                    
NuGet\Install-Package Shared.K8.Common -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shared.K8.Common" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shared.K8.Common" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Shared.K8.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Shared.K8.Common --version 1.0.3
                    
#r "nuget: Shared.K8.Common, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Shared.K8.Common@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shared.K8.Common&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Shared.K8.Common&version=1.0.3
                    
Install as a Cake Tool

Shared.K8.Common

A comprehensive .NET 9 library for configuring OpenTelemetry observability (logging, metrics, and tracing) in ASP.NET Core applications using standard OpenTelemetry environment variables.

Features

  • Simple API: Just two extension methods - AddObservability() and UseObservability()
  • Zero Configuration: Works out-of-the-box with sensible defaults
  • Standard Compliant: Uses official OpenTelemetry environment variables
  • Comprehensive Telemetry: Logging, metrics, and distributed tracing included
  • Error Resilient: Gracefully falls back to console when OTLP endpoints are unavailable
  • Production Ready: Built on OpenTelemetry 1.14.0 with .NET 9 support

Quick Start

using Shared.K8.Common.OpenTelemetry;

var builder = WebApplication.CreateBuilder(args);

// Add OpenTelemetry observability
builder.AddObservability();

var app = builder.Build();

// Configure observability middleware
app.UseObservability();

app.Run();

That's it! Your application now has comprehensive observability configured with:

  • Structured logging with OpenTelemetry
  • ASP.NET Core and HTTP client metrics and tracing
  • Prometheus metrics endpoint at /metrics
  • Automatic fallback to console when no OTLP endpoint is configured

Configuration

Configure the library using standard OpenTelemetry environment variables:

# Basic configuration
OTEL_SERVICE_NAME=my-web-api
OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4317
OTEL_EXPORTER_OTLP_PROTOCOL=grpc

# With authentication
OTEL_SERVICE_NAME=my-web-api
OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.company.com:4317
OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer token123"
Environment Variable Description Default
OTEL_SERVICE_NAME Service name for telemetry Application name
OTEL_EXPORTER_OTLP_ENDPOINT OTLP endpoint URL None (uses console)
OTEL_EXPORTER_OTLP_PROTOCOL Protocol (grpc or http/protobuf) grpc
OTEL_EXPORTER_OTLP_HEADERS Headers (e.g., auth) None

What's Included

Automatic Instrumentation

  • ASP.NET Core: HTTP request/response metrics and tracing
  • HTTP Client: Outbound HTTP call metrics and tracing
  • Prometheus: /metrics endpoint for scraping

Built-in Meters

  • Microsoft.AspNetCore.Hosting - Request metrics
  • Microsoft.AspNetCore.Server.Kestrel - Server metrics
  • System.Net.Http - HTTP client metrics
  • System.Net.NameResolution - DNS metrics
  • Custom service meter (matches your service name)

Resource Attributes

  • service.name - From environment or application name
  • service.version - Set to "1.0.0"
  • service.instance.id - Machine name
  • deployment.environment - Environment name
  • service.namespace - Set to "mockery"

Smart Fallbacks

  • OTLP available: Exports to your configured endpoint
  • OTLP unavailable: Falls back to console output
  • No configuration: Uses console for development

Usage Examples

Docker Deployment

FROM mcr.microsoft.com/dotnet/aspnet:9.0
WORKDIR /app
COPY . .

ENV OTEL_SERVICE_NAME=my-web-api
ENV OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4317

ENTRYPOINT ["dotnet", "MyApp.dll"]

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-api
spec:
  template:
    spec:
      containers:
      - name: my-web-api
        image: my-web-api:latest
        env:
        - name: OTEL_SERVICE_NAME
          value: "my-web-api"
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: "http://otel-collector:4317"

With Custom Telemetry

using System.Diagnostics;
using System.Diagnostics.Metrics;

var builder = WebApplication.CreateBuilder(args);

// Create custom telemetry
using var activitySource = new ActivitySource("MyApp.Orders");
using var meter = new Meter("MyApp.BusinessMetrics");
var orderCounter = meter.CreateCounter<int>("orders_total");

builder.AddObservability();

var app = builder.Build();
app.UseObservability();

app.MapPost("/orders", (Order order) =>
{
    using var activity = activitySource.StartActivity("ProcessOrder");
    activity?.SetTag("order.id", order.Id);
    
    orderCounter.Add(1, new("status", "processed"));
    return Results.Ok();
});

app.Run();

Requirements

  • .NET 9.0 or later
  • ASP.NET Core applications
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 191 11/24/2025
1.0.2 176 11/24/2025
1.0.1 188 11/23/2025
1.0.0 160 11/23/2025