Generate Custom Metrics from Spans and Traces

Request access to the Preview!

Custom metrics from traces are in Preview. To request access, submit a ticket to the APM Support team and provide a short description of your use case.

Request Access
Span-based metrics

Generate custom metrics from ingested spans to track trends, power dashboards, and trigger monitors—even for spans and traces that are not retained for full trace analysis.

Custom metrics are created from spans ingested by Datadog APM, regardless of whether a retention filter indexes those spans. Extract numeric values from spans (such as counts, durations, or custom tags) or traces (end-to-end trace duration) and store them as long-lived custom metrics with 15-month retention.

Notes:

  • Datadog automatically generates Trace Metrics that capture request counts, error rates, and latency distributions for 100% of your application traffic.
  • Available spans for custom metric generation depend on your APM ingestion control settings. Dropped spans from sampling or filtering cannot generate metrics.

Use custom metrics from spans for:

  • Fine-grained visibility into span-level latency, error rates, or tag-level performance
  • Powering anomaly or forecast monitors with low-latency, high-resolution metrics.
  • Extracting key signals for trending or alerting without retaining the full span.

When to use custom metrics from traces

Use custom metrics from traces for:

  • Metrics derived from complete trace context, such as total trace duration or operations per trace.
  • Alerting on conditions requiring full trace knowledge (for example, N+1 query detection or fan-out patterns).
  • Extracting key signals for trending or alerting without retaining the full trace.
Custom metrics from spans and traces are custom metrics and billed accordingly. Avoid grouping by high-cardinality values (such as user IDs, request IDs, or timestamps) to prevent billing impact.

Create a metric from spans or traces

How to create a metric
  1. Navigate to APM > Generate Metrics.
  2. Click New Metric.
  3. Name your metric following the metric naming convention. Metric names starting with trace.* are not allowed.
  4. Select the metric type: Spans or Traces. Both use the same query syntax as APM Search and Analytics.
  5. Define the metric query to filter and include only the spans or traces you want to measure.
  6. Choose the value to aggregate:
    • Select * to count all matching spans or traces.
    • Enter a numeric attribute (for example, @cassandra_row_count) to aggregate and track the count, min, max, sum, or percentiles.
  7. Set grouping dimensions. By default, metrics have no tags unless you add them. Use any span attribute or tag to create metric tags.
  8. Preview the result to view the real-time impact of your query through the data visualization and matching spans or traces in the live preview.
  9. Click Create Metric.
Span-based metrics are considered custom metrics and billed accordingly. Avoid grouping by unbounded or extremely high cardinality attributes like timestamps, user IDs, request IDs, or session IDs to avoid impacting your billing.

Update existing metrics

Edit an existing metrics

After a metric is created, only two fields can be updated:

FieldReason
Stream filter queryChange the set of matching spans to be aggregated into metrics.
Aggregation groupsUpdate the tags to manage the cardinality of generated metrics.

Note: To change the metric type or name, create a new metric and delete the old one.

Data availability

Metrics generated from traces are emitted after a trace completes. For long-running traces, the delay increases accordingly (for example, a 45-minute trace’s metric cannot be emitted until trace completion).

When using custom metrics from traces in monitors, account for this latency to avoid false positives.

Further Reading