CI Visibility is not available in the selected site () at this time.

Overview

Before you begin, make sure that Test Visibility is already set up for your language. This guide walks you through adding and using custom metrics for your tests.

These custom metrics are not Datadog metrics. They are numerical tags (also known as measures) that represent things like memory usage or request rates.

Add the custom metric to your test

Add the custom metric to your test. The native instrumentation allows you to use the programmatic API:

  it('sum function can sum', () => {
    const testSpan = require('dd-trace').scope().active()
    testSpan.setTag('test.memory.rss', process.memoryUsage().rss)
    // test continues normally
    // ...
  })
// inside your test
final Span span = GlobalTracer.get().activeSpan();
if (span != null) {
  span.setTag("test.memory.usage", 1e8);
}
// test continues normally
// ...
from ddtrace import tracer
import os, psutil

# Declare `ddspan` as argument to your test
def test_simple_case(ddspan):
    # Set your tags
    process = psutil.Process()
    ddspan.set_tag("test.memory.rss", process.memory_info().rss)
    # test continues normally
    # ...
// inside your test
var scope = Tracer.Instance.ActiveScope; // from Datadog.Trace;
if (scope != null) {
    scope.Span.SetTag("test.memory.usage", 1e8);
}
// test continues normally
// ...
require 'datadog/ci'

# inside your test
Datadog::CI.active_test&.set_tag('test.memory.usage', 1e8)
# test continues normally
# ...

For datadog-ci, use the DD_METRICS environment variable or --metrics CLI argument:

DD_METRICS="test.memory.usage:1000" datadog-ci junit upload --service my-service --metrics test.request.rate:30 report.xml

Create a facet

Create a facet for the custom metric you added to the test by navigating to the Test Runs page and clicking + Add on the facet list.

Make sure that the type of facet is Measure, which represents a numerical value:

Click Add to start using your custom metric.

Graph the evolution of your metric

Plot the evolution of your metric across time by selecting the Timeseries visualization:

For example, you can use this visualization to track the evolution of the memory usage in your tests.

Export your graph

You can export your graph to a dashboard or a notebook, and create a monitor based on it by clicking the Export button.

Add a monitor

Get alerted if the value of your metric goes above or below a certain threshold by creating a CI Tests Monitor.

For example, you can use this type of alert to inform you about the memory usage reaching a certain threshold.

Further reading

Additional helpful documentation, links, and articles: