Skip to content

Commit

Permalink
Provide documentation for writing metrics (#44)
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Kerkhove <[email protected]>
  • Loading branch information
tomkerkhove authored Mar 23, 2020
1 parent 0222a1e commit 4713e7c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions docs/features/writing-different-telemetry-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Logs are a great way to gain insights, but sometimes they are not the best appro

We provide the capability to track the following telemetry types on top of ILogger with good support on Serilog:

- Dependencies
- [Events](#events)
- Metrics
- [Metrics](#metrics)
- Requests
- Dependencies

For most optimal output, we recommend using our [Azure Application Insights sink](/features/sinks/azure-application-insights).

Expand Down Expand Up @@ -64,4 +64,23 @@ loger.LogSecurityEvent("Invalid Order", telemetryContext);
// Output: "Events Invalid Order (Context: [EventType, Security], [OrderId, OrderId was not in correct format])"
```

## Metrics

Metrics allow you to report custom metrics which allow you to give insights on application-specific metrics.

Here is how you can report an `Invoice Received` metric:

```csharp
var context = new Dictionary<string, object>
{
{ "InvoiceId", "ABC"},
{ "Vendor", "Contoso"},
};

logger.LogMetric("Invoice Received", 133.37, context);
// Output: "Metric Invoice Received: 133.37 (Context: [InvoiceId, ABC], [Vendor, Contoso])"
```

By using contextual information, you can create powerful metrics. When writing to Application Insights, for example, which will report the `Invoice Received` metric as [multi-dimensional metrics](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-platform-metrics#multi-dimensional-metrics) which allow you to filter the metric based on its context.

[&larr; back](/)

0 comments on commit 4713e7c

Please sign in to comment.