Datadog

Datadog

The App.Metrics.Reporting.Datadog nuget package reports metrics to Datadog using the App.Metrics.Formatting.Datadog nuget package to format metrics.

Datadog URL, API Key

You will need these two to correctly configure App.Metrics to report to Datadog over HTTP.

Create an API key in Datadog here.

The Datadog base URL to report metrics over http is https://api.datadoghq.com/

Getting started

To use the Datadog HTTP reporter, first install the nuget package:

nuget install App.Metrics.Reporting.Datadog

Then enable the reporter using Report.ToDatadogHttp(...):

var metrics = new MetricsBuilder()
    .Report.ToDatadogHttp("base url of datadogs api", "datadog api key")
    .Build();

App Metrics at the moment leaves report scheduling up the the user unless using App.Metrics.AspNetCore.Reporting. To run all configured reports use the ReportRunner on IMetricsRoot:

await metrics.ReportRunner.RunAllAsync();

Report Scheduling will be added when Microsoft.Extensions.Hosting.Background is released, otherwise there are various other scheduling solutions available for C#. For ASP.NET Core reporting see details on the App.Metrics.AspNetCore.Reporting support package.

Configuration

Configuration options are provided as a setup action used with ToDatadogHttp(...).

To configure Datadog reporting options:

var filter = new MetricsFilter().WhereType(MetricType.Timer);
var metrics = new MetricsBuilder()
    .Report.ToDatadogHttp(
        options => {
            options.Datadog.BaseUri = "base url of your datadog";
            options.Datadog.ApiKey = "datadog api key";
            options.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
            options.HttpPolicy.FailuresBeforeBackoff = 5;
            options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
            options.Filter = filter;
            options.FlushInterval = TimeSpan.FromSeconds(20);
        })
    .Build();

The configuration options provided are:

Option Description
MetricsDatadogJsonOutputFormatter The metric payment formatter used when reporting metrics to Datadog
Filter The filter used to filter metrics just for this reporter.
FlushInterval The delay between reporting metrics.
BaseUri The URI of the Datadog’s HTTP api
ApiKey The Api Key which your application will use to authenticate with Datadog.
HttpPolicy.BackoffPeriod The TimeSpan to back-off when metrics are failing to report to the metrics ingress endpoint.
HttpPolicy.FailuresBeforeBackoff The number of failures before backing-off when metrics are failing to report to the metrics ingress endpoint.
HttpPolicy.Timeout The HTTP timeout duration when attempting to report metrics to the metrics ingress endpoint.