Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Metrics Upgrade Version 1 to 2

Component: Metrics

RegisterObservers replaces basic methods

The EnableMetricTracing, EnableCustomReport and EnableLogTracing methods have been deprecated and replaced with the more extensible RegisterObservers.

Also note that the older methods supported an interval TimeSpan. It is now the responsibility of the implementing code to batch metrics and flush them as needed.

Changes in RegisterObservers

The RegisterObservers API has changed to take ref events.

// For Metrics version 2.x
var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
    register: context =>
    {
        foreach (var duration in context.Durations)
        {
            duration.Register(
                observer: (ref DurationEvent @event) =>
                {
                    log.Info($"Duration: '{duration.Name}'. Value: '{@event.Duration}'");
                });
        }
        foreach (var signal in context.Signals)
        {
            signal.Register(
                observer: (ref SignalEvent @event) =>
                {
                    log.Info($"Signal: '{signal.Name}'. Type: '{@event.MessageType}'");
                });
        }
    });

// For Metrics version 1.x
var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
    register: context =>
    {
        foreach (var duration in context.Durations)
        {
            duration.Register(
                observer: length =>
                {
                    log.Info($"Duration: '{duration.Name}'. Value: '{length}'");
                });
        }
        foreach (var signal in context.Signals)
        {
            signal.Register(
                observer: () =>
                {
                    log.Info($"signal: '{signal.Name}'");
                });
        }
    });