Business Metrics

Metrics represent any numbers you want to track over time originating from your application. They are used in conjunction with experiments to provide value beyond just tracking.

Keeping to the Open Telemetry standards, we support 3 types of metrics, all available via the IMetricsService interface

Metrics are aggregated in the Metrics service, and sent to Toggly's API on an interval. Currently it's at 1 minute, but this may change. Metrics are kept at this granularity for a few days, then rolled up into hourly buckets, and eventually daily buckets.

MeasureAsync

Increment the value of a defined metric.

A value that is aggregated over time. This is more akin to the trip odometer on a car, it represents a value over some defined range.

public class AccountController : Controller
{
    private readonly IMetricsService _metricsService;

    public AccountController(IMetricsService metricsService)
    {
        _metricsService = metricsService;
    }

    public async Task<IActionResult> SignIn(SignInModel model)
    {
        ...
        await _metricsService.MeasureAsync("SignIn", 1);
        ...
    }
}

ObserveAsync

Record a value at an instant in time.

Captures the current value at a point in time, like a fuel gauge in a vehicle

public class AccountController : Controller
{
    private readonly IMetricsService _metricsService;

    public AccountController(IMetricsService metricsService)
    {
        _metricsService = metricsService;
    }

    public async Task<IActionResult> SignIn(SignInModel model)
    {
        ...
        await _metricsService.ObserveAsync("TotalActiveUsers", 30);
        ...
    }
}

IncrementCounterAsync

Increment a named counter

A value that is summed over time – you can think of this like an odometer on a car


public class SignupController : Controller
{
    private readonly IMetricsService _metricsService;

    public SignupController(IMetricsService metricsService)
    {
        _metricsService = metricsService;
    }

    public async Task<IActionResult> SignIn(SignUpModel model)
    {
        await _metricsService.IncrementCounterAsync("TotalSignups", 1);
    }
}

Last updated