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
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
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
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
Was this helpful?