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.

2.x NServiceBus.Metrics
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}'");
                });
        }
    });
1.1 NServiceBus.Metrics
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}'");
                });
        }
    });

Last modified