# 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

{% hint style="success" %}
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.
{% endhint %}

### MeasureAsync

{% hint style="info" %}
Increment the value of a defined metric.&#x20;

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.
{% endhint %}

```csharp
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

{% hint style="info" %}
Record a value at an instant in time.&#x20;

Captures the current value at a point in time, like a fuel gauge in a vehicle
{% endhint %}

```csharp
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

{% hint style="info" %}
Increment a named counter

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

```csharp

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);
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.toggly.io/metrics/metrics-in-c-.net/business-metrics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
