See More

A very common reason is a wrong site baseUrl configuration.\n

Current configured baseUrl = / (default value)\n

We suggest trying baseUrl = \n\n',document.body.prepend(n);var e=document.getElementById("__docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname,o="/"===s.substr(-1)?s:s+"/";e.textContent=o}document.addEventListener("DOMContentLoaded",function(){void 0===window.docusaurus&&insertBanner()})

Skip to main content

ZeroAlloc.Telemetry

Source-generated OpenTelemetry instrumentation for .NET.

Add [Instrument] to any interface and the generator emits a sealed proxy class that records Activity spans and Meter instruments per method — without reflection, params object[] boxing, or runtime attribute inspection.


Contents

PageDescription
Getting StartedInstall and instrument your first interface
Attribute Reference[Instrument], [Trace], [Count], [Histogram]
Source GeneratorWhat the generator emits — input/output examples
TestingAssert spans and metrics with BCL listeners, no exporter needed
AOT & TrimmingNative AOT compatibility

Quick Example

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

The generator emits OrderServiceInstrumented : IOrderService. Wrap your implementation at the DI layer:

services.AddSingleton<OrderServiceImpl>();
services.AddSingleton<IOrderService>(sp =>
new OrderServiceInstrumented(sp.GetRequiredService<OrderServiceImpl>()));

That's all. No OpenTelemetry SDK is required — ActivitySource and Meter are BCL types (net8.0+). Add exporters in your application startup independently.


Instruments at a Glance

AttributeWhat it recordsWhen
[Trace("name")]Activity spanEvery call — Error status on exception
[Count("metric")]Counter<long> +1Success only
[Histogram("metric")]Histogram<double> elapsed msEvery call including on exception