ZeroAlloc.Telemetry 1.2.1

dotnet add package ZeroAlloc.Telemetry --version 1.2.1
                    
NuGet\Install-Package ZeroAlloc.Telemetry -Version 1.2.1
                    
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="ZeroAlloc.Telemetry" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Telemetry" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Telemetry" />
                    
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 ZeroAlloc.Telemetry --version 1.2.1
                    
#r "nuget: ZeroAlloc.Telemetry, 1.2.1"
                    
#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 ZeroAlloc.Telemetry@1.2.1
                    
#: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=ZeroAlloc.Telemetry&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Telemetry&version=1.2.1
                    
Install as a Cake Tool

ZeroAlloc.Telemetry

NuGet Build License: MIT AOT GitHub Sponsors

Source-generated OpenTelemetry instrumentation for .NET — Activity spans and Meter instruments without reflection, params object[] boxing, or runtime attribute inspection. Native AOT safe.

Add [Instrument] to any interface and the generator emits a sealed proxy class that wraps your implementation and records spans and metrics per method. Swap it in via DI without changing application code.

Install

dotnet add package ZeroAlloc.Telemetry

The package bundles both the attribute assembly and the generator — no separate install.

Quick Start

using ZeroAlloc.Telemetry;

// 1. Annotate your interface
[Instrument("MyApp.Orders")]
public interface IOrderService
{
    [Trace("order.create")]
    [Count("orders.created")]
    ValueTask<OrderId> CreateOrderAsync(CreateOrderCommand cmd, CancellationToken ct);

    [Trace("order.get")]
    [Histogram("order.get_ms")]
    ValueTask<Order> GetOrderAsync(OrderId id, CancellationToken ct);
}

// 2. The generator emits OrderServiceInstrumented : IOrderService automatically.

// 3. Wire up in DI
services.AddSingleton<OrderServiceImpl>();
services.AddSingleton<IOrderService>(sp =>
    new OrderServiceInstrumented(sp.GetRequiredService<OrderServiceImpl>()));

No OpenTelemetry SDK dependency is required. ActivitySource and Meter are BCL types (net8.0+). Add exporters (OTLP, Console, Prometheus) in your application startup separately.

What Gets Generated

For the CreateOrderAsync method above, the generator emits:

// <auto-generated />
internal sealed class OrderServiceInstrumented : IOrderService
{
    private static readonly ActivitySource _activitySource = new("MyApp.Orders");
    private static readonly Meter _meter = new("MyApp.Orders");
    private static readonly Counter<long> _orders_created =
        _meter.CreateCounter<long>("orders.created");

    private readonly IOrderService _inner;
    public OrderServiceInstrumented(IOrderService inner) => _inner = inner;

    public async ValueTask<OrderId> CreateOrderAsync(CreateOrderCommand cmd, CancellationToken ct)
    {
        using var _activity = _activitySource.StartActivity("order.create");
        try
        {
            var _result = await _inner.CreateOrderAsync(cmd, ct);
            _orders_created.Add(1);
            return _result;
        }
        catch (Exception _ex)
        {
            _activity?.SetStatus(ActivityStatusCode.Error, _ex.Message);
            throw;
        }
    }
    // ...
}

Instruments

Attribute Instrument Recorded when
[Trace("name")] ActivitySource.StartActivity("name") Every call — stopped in finally, Error status on exception
[Count("metric")] Counter<long>.Add(1) After a successful (non-throwing) call only
[Histogram("metric")] Histogram<double>.Record(ms) Every call including on exception

Packages

Package Description TFM
ZeroAlloc.Telemetry Attributes + bundled generator net8.0;net9.0;net10.0
ZeroAlloc.Telemetry.Generator Roslyn source generator (standalone) netstandard2.0

The generator is bundled inside ZeroAlloc.Telemetry as an analyzer. Install ZeroAlloc.Telemetry.Generator separately only if you need the generator without the attribute assembly.

AOT Safety

Generated proxies use no reflection, no params object[], and no runtime type inspection. T is closed at generation time — the generated ActivitySource and Meter field initializers are plain constructor calls. Fully compatible with <PublishAot>true</PublishAot>.

Documentation

Full docs at telemetry.zeroalloc.net.

Page Description
Getting Started Install and instrument your first interface
Attribute Reference [Instrument], [Trace], [Count], [Histogram]
Source Generator What the generator emits — input/output examples
Testing Assert spans and metrics with BCL listeners
AOT & Trimming Native AOT compatibility

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on ZeroAlloc.Telemetry:

Package Downloads
AI.Sentinel

Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine.

ZeroAlloc.Scheduling.Telemetry

ZeroAlloc.Telemetry bridge for ZeroAlloc.Scheduling — wraps IJobTypeExecutor with a source-generated OpenTelemetry proxy.

ZeroAlloc.Outbox.Telemetry

ZeroAlloc.Telemetry bridge for ZeroAlloc.Outbox — wraps IOutboxTypeDispatcher with a source-generated OpenTelemetry proxy.

ZeroAlloc.EventSourcing

Source-generated event-sourced aggregates for .NET. Zero-allocation event dispatch, AOT-safe.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 152 5/3/2026
1.2.0 476 5/1/2026
1.1.3 210 5/1/2026
1.1.2 534 4/29/2026
1.1.1 659 4/28/2026
1.1.0 279 4/23/2026
1.0.0 118 4/17/2026