Link Search Menu Expand Document

IPublisherRepository


This interface is used to mark a class to be a telemetry publisher. It gives you full control over how TelemetryItem objects are delivered to your insights solution (e.g. HTTP collector, message queue, file sink, etc).

Methods

Below is the list of methods.

NameDescription
PublishPublishes a single TelemetryItem.
PublishManyPublishes multiple TelemetryItem objects in one batch.

Both methods have their corresponding Async methods.

Use-Cases

Use this interface if the default HTTP collector used by TelemetryPublisherRepository does not fit your infrastructure — for example, publishing to a message queue, a different observability backend, or a custom on-prem endpoint.

How to Implement?

You have to manually create a class that implements this interface.

public class MyPublisherRepository : IPublisherRepository
{
    public void Publish(TelemetryItem telemetryItem)
    {
        // Send to your sink
    }

    public void PublishAsync(TelemetryItem telemetryItem, CancellationToken cancellationToken = default)
    {
        // Send to your sink asynchronously
    }

    public void PublishMany(IEnumerable<TelemetryItem> telemetryItems)
    {
        // Send a batch to your sink
    }

    public void PublishManyAsync(IEnumerable<TelemetryItem> telemetryItems, CancellationToken cancellationToken = default)
    {
        // Send a batch to your sink asynchronously
    }
}

Usability

Use it from your own ITrace-based class, following the same pattern as TelemetryTrace.

Please visit the Telemetry feature page for more information on how publishing fits into the overall pipeline.