Metrics Upgrade Version 1 to 2

Component: Metrics

RegisterObservers replaces basic methods

If upgrading from version 1.0 the EnableMetricTracing, EnableCustomReport and EnableLogTracing methods have been deprecated and replaced with the more extensible RegisterObservers. See Upgrade Version 1 to 1.1.

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