ZeroAlloc.Telemetry 1.12.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZeroAlloc.Telemetry --version 1.12.7
                    
NuGet\Install-Package ZeroAlloc.Telemetry -Version 1.12.7
                    
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.12.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Telemetry" Version="1.12.7" />
                    
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.12.7
                    
#r "nuget: ZeroAlloc.Telemetry, 1.12.7"
                    
#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.12.7
                    
#: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.12.7
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Telemetry&version=1.12.7
                    
Install as a Cake Tool

ZeroAlloc.Telemetry

NuGet Build codecov License: MIT AOT GitHub Sponsors

Put [Instrument] on an interface and get OpenTelemetry spans and metrics for every call, generated at compile time: no hand-written ActivitySource boilerplate, no reflection, and nothing allocated when nobody is listening.

Why ZeroAlloc.Telemetry

  • 0 B per call when nothing listens, the common production case after sampling. Tests assert it for Task, ValueTask and ValueTask<T> methods, tagged metrics included.
  • 7.5× faster than a straightforward hand-written ActivitySource + Meter wrapper with no listener attached, measured in the same run: the proxy skips the instrumented path entirely until something subscribes.
  • Works under NativeAOT and trimming. Plain generated code over BCL ActivitySource and Meter, no reflection and no params object[]; CI publishes a NativeAOT app.
  • Mistakes surface at compile time. A result member that is not numeric, or a metric attribute on an interface without [Instrument], is a compiler diagnostic.

Install

dotnet add package ZeroAlloc.Telemetry

No OpenTelemetry SDK dependency: add the exporters you want, OTLP, Prometheus or Console, in your application.

Quick start

using System.Diagnostics;
using ZeroAlloc.Telemetry;

using var listener = new ActivityListener
{
    ShouldListenTo = source => source.Name == "MyApp.Orders",
    Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData,
    ActivityStopped = activity => Console.WriteLine($"span {activity.DisplayName}: {activity.Duration.TotalMilliseconds:F1} ms"),
};
ActivitySource.AddActivityListener(listener);

IOrderService orders = new OrderServiceInstrumented(new OrderService()); // generated proxy
await orders.PlaceOrderAsync("book", CancellationToken.None);            // prints the order.place span

[Instrument("MyApp.Orders")]
public interface IOrderService
{
    [Trace("order.place")]
    [Count("orders.placed")]
    [Histogram("order.place_ms")]
    ValueTask<int> PlaceOrderAsync(string product, CancellationToken ct);
}

public sealed class OrderService : IOrderService
{
    public async ValueTask<int> PlaceOrderAsync(string product, CancellationToken ct)
    {
        await Task.Delay(10, ct);
        return 42;
    }
}

In an application, register the proxy in DI in place of the implementation, and subscribe with OpenTelemetry's AddSource("MyApp.Orders") and AddMeter("MyApp.Orders"). Your code keeps calling IOrderService.

What you get

  • Spans per method, with error status and error.type on exceptions, or on a failed Result you choose to treat as an error.
  • Counters and duration histograms per method, recorded on success or on every call, optionally only when a result guard such as IsSuccess holds.
  • Metrics from the return value, such as tokens consumed or a cost, recorded straight from a member of the result.
  • Tags on spans and metrics from arguments, from the result, or as constants, built only when a listener needs them.
  • Consistent instrumentation: every method gets the same span, counter and histogram pattern, with no Activity left undisposed and no metric forgotten.
  • Testable with BCL listeners, no exporter needed: Testing.
  • Every attribute and option: attribute reference. Compile-time diagnostics: the full list.

Performance

No listener attached, the production case after sampling. .NET 10.0.13, BenchmarkDotNet v0.15.8. Time is relative to the uninstrumented call in the same run; allocations are exact.

Method Time vs direct call Allocated
Direct call, no instrumentation 1× 0 B
Hand-written ActivitySource + Counter + Histogram 60.6× 0 B
ZA.Telemetry generated proxy 8.1× 0 B

Neither wrapper allocates. The hand-written version still runs its async state machine, takes timestamps and calls instruments nobody listens to; the proxy checks for listeners and hands back the inner task as is. Hand-written code can do the same, but every method has to remember to. Methodology: docs/performance.md.

Learn more

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

Showing the top 5 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.

Minos.NET

Typed, source-generated decision questions for .NET, provider-neutral: the question model, IDecisionClient and its pipeline. Add a protocol package such as Minos.NET.SystemOne to call a provider. Native AOT-compatible and allocation-conscious.

Thalos.NET.Abstractions

Ports and models for Thalos.NET. Depends only on ZeroAlloc primitives and Microsoft.Extensions.AI.Abstractions.

Minos.NET.SystemOne

The /v1/systemone protocol for Minos.NET: TypeSafe's Jev API, OpenRouter, vLLM Semantic Router and compatible local servers, with presets, capability checks and DI registration. Native AOT-compatible. Not affiliated with or endorsed by TypeSafe AI, OpenRouter or the vLLM project.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.13.0 1,311 11/6/2026
1.12.7 5,390 10/30/2026
1.12.6 9,329 10/21/2026
1.12.5 1,579 10/18/2026
1.12.4 2,756 10/16/2026
1.12.3 2,222 10/15/2026
1.12.2 3,033 10/12/2026
1.12.1 1,412 10/11/2026
1.12.0 3,493 10/10/2026
1.11.0 10,358 10/1/2026
1.10.0 992 10/1/2026
1.9.0 119 10/1/2026
1.8.0 160 9/30/2026
1.7.0 4,602 9/27/2026
1.6.4 1,038 9/26/2026
1.6.3 4,399 9/20/2026
1.6.2 1,588 9/19/2026
1.6.1 5,094 8/8/2026
1.6.0 281 8/7/2026
1.5.0 210 8/7/2026
Loading failed