Link Search Menu Expand Document

TelemetryTrace


An ITrace implementation that hooks into the BeforeExecution()/AfterExecution() pipeline, buffers a TelemetryItem per operation, and flushes the buffer to an IPublisherRepository on a timer. See the Telemetry feature page for the full picture.

Creating an Instance

var option = new TelemetryOption("MyApp")
{
    Host = "https://your-collector-host",
    ApiKey = "YOUR_API_KEY"
};

var trace = new TelemetryTrace(option, errorCallback: ex => logger.LogError(ex, "Telemetry error"));
trace.Start();

Methods

NameDescription
StartStarts the internal flush timer, using the Frequency from the passed TelemetryOption.
BeforeExecutionCaptures the start of an operation. Implements ITrace.
AfterExecutionCaptures the result/elapsed time of an operation. Implements ITrace.

Attaching to Operations

Pass it explicitly to an operation call.

connection.QueryAll<Customer>(trace: trace);

Or register it so it applies to every operation across the application.

GlobalConfiguration
    .Setup(new GlobalConfigurationOptions { UseRegisteredGlobalTraces = true });

GlobalTraceRegistration.Register(trace);

RepoDb.Telemetry.Default uses DefaultTelemetryTrace, a singleton subclass of this class, wired up automatically via UseDefaultTelemetry().