Metrics Upgrade Version 1.0 to 1.1

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.

EnableMetricTracing

Replace with explicit calls to Trace.WriteLine.

1.1 NServiceBus.Metrics
var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
    register: context =>
    {
        foreach (var duration in context.Durations)
        {
            duration.Register(
                observer: length =>
                {
                    Trace.WriteLine($"Duration '{duration.Name}'. Value: '{length}'");
                });
        }
        foreach (var signal in context.Signals)
        {
            signal.Register(
                observer: () =>
                {
                    Trace.WriteLine($"Signal: '{signal.Name}'");
                });
        }
    });
1.x NServiceBus.Metrics
var metrics = endpointConfiguration.EnableMetrics();
metrics.EnableMetricTracing(TimeSpan.FromSeconds(5));

EnableLogTracing

Replace with explicit calls to an NServiceBus logger.

1.1 NServiceBus.Metrics
//TODO: the logger instance should be a static field
var log = LogManager.GetLogger("LoggerName");

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}'");
                });
        }
    });
1.x NServiceBus.Metrics
var metrics = endpointConfiguration.EnableMetrics();
metrics.EnableLogTracing(TimeSpan.FromSeconds(5), LogLevel.Info);

EnableCustomReport

Replace with explicit calls to the custom method.

1.1 NServiceBus.Metrics
var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
    register: context =>
    {
        foreach (var duration in context.Durations)
        {
            duration.Register(
                observer: length =>
                {
                    ProcessMetric(duration, length);
                });
        }
        foreach (var signal in context.Signals)
        {
            signal.Register(
                observer: () =>
                {
                    ProcessMetric(signal);
                });
        }
    });
1.x NServiceBus.Metrics
var metrics = endpointConfiguration.EnableMetrics();
metrics.EnableCustomReport(
    func: data => ProcessMetric(data),
    interval: TimeSpan.FromSeconds(5));

Last modified