ZeroAlloc.Telemetry.Generator
1.1.1
See the version list below for details.
dotnet add package ZeroAlloc.Telemetry.Generator --version 1.1.1
NuGet\Install-Package ZeroAlloc.Telemetry.Generator -Version 1.1.1
<PackageReference Include="ZeroAlloc.Telemetry.Generator" Version="1.1.1" />
<PackageVersion Include="ZeroAlloc.Telemetry.Generator" Version="1.1.1" />
<PackageReference Include="ZeroAlloc.Telemetry.Generator" />
paket add ZeroAlloc.Telemetry.Generator --version 1.1.1
#r "nuget: ZeroAlloc.Telemetry.Generator, 1.1.1"
#:package ZeroAlloc.Telemetry.Generator@1.1.1
#addin nuget:?package=ZeroAlloc.Telemetry.Generator&version=1.1.1
#tool nuget:?package=ZeroAlloc.Telemetry.Generator&version=1.1.1
ZeroAlloc.Telemetry
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.