Cloud FinOps & Optimization
Optimizing Datadog Billing: A Deep Technical Guide to Custom Metrics and Tracing
Master Datadog cost optimization. Learn deep technical strategies for managing custom metrics, APM sampling, log ingestion pipelines, and reducing overall observability spend.
Optimizing Datadog Billing: A Deep Technical Guide to Custom Metrics and Tracing

The Observability FinOps Challenge: Managing the Datadog Beast

In modern cloud-native architectures, observability is no longer a luxury—it is a critical requirement for maintaining uptime, debugging distributed microservices, and understanding system performance. Datadog has emerged as one of the most powerful and ubiquitous observability platforms, offering seamless integration across infrastructure, application performance monitoring (APM), and logging. However, the sheer volume of data generated by Kubernetes clusters, serverless functions, and high-throughput microservices can lead to exponential growth in Datadog billing. Without strict governance and advanced FinOps strategies, organizations often find their observability costs rivaling or even exceeding their actual compute infrastructure costs.

This comprehensive technical guide dives deep into the underlying mechanics of Datadog billing. We will explore the hidden complexities of custom metrics indexing, APM trace sampling algorithms, log ingestion pipelines, and infrastructure host billing. By implementing the advanced optimization techniques detailed below, Cloud Architects and Site Reliability Engineers (SREs) can dramatically reduce their Datadog spend while maintaining full operational visibility.

Demystifying Datadog Custom Metrics Billing

The Definition and Danger of Custom Metrics

Datadog bills for infrastructure on a per-host basis, which includes hundreds of standard integrations (e.g., AWS EC2, Kubernetes node metrics, Redis stats). However, any metric that falls outside these standard integrations is classified as a "Custom Metric." This includes application-level business metrics (e.g., orders.processed, user.login.failures) and custom Prometheus metrics scraped from your workloads. Datadog charges for custom metrics based on the number of unique "metric time series" generated. A metric time series is defined by a unique combination of a metric name and its associated tags.

The trap that catches most engineering teams is the multiplicative effect of high-cardinality tags. If a developer emits a metric called http.request.duration and tags it with service, endpoint, status_code, and—critically—user_id or session_id, the number of unique tag combinations explodes. For a high-traffic service with millions of unique users, a single metric name can spawn millions of billable time series, leading to immediate billing shocks.

Metrics Without Limits: Separation of Ingestion and Indexing

To combat this, Datadog introduced a feature called "Metrics Without Limits." This architecture decouples the ingestion of metrics from the indexing of metrics. Historically, if a metric was ingested, it was fully indexed and queryable by all its tags, and you were billed for all resulting time series. With Metrics Without Limits, you can ingest the raw data stream but define specific rules on which tags to index.

For example, you might ingest the http.request.duration metric with all its tags, but configure Datadog to only index the service and status_code tags. Datadog aggregates the data at the ingestion layer based on the indexed tags before storing it. You are only billed for the indexed time series, which dramatically reduces the cardinality and the cost, while still preserving the aggregate mathematical accuracy (e.g., total request count, average duration across a service).

# Example Datadog Agent Configuration for Metric Tag Stripping (datadog.yaml)
# Instead of doing it in the UI, you can enforce tag stripping at the agent level
# to prevent high-cardinality data from ever leaving your infrastructure.
datadog:
  statsd:
    # Drop problematic tags at the source
    ignore_metrics_by_name:
      - name: "http.request.duration"
        tags: ["user_id", "session_id", "transaction_id"]

Advanced FinOps platforms like CloudAtler provide continuous scanning of Datadog accounts to identify metrics with exploding cardinality. CloudAtler can automatically pinpoint the exact microservice and developer team responsible for introducing a high-cardinality tag, enabling immediate remediation before the billing cycle ends.

Optimizing Application Performance Monitoring (APM) Costs

The Two-Tier APM Billing Model

Datadog APM billing is notoriously complex. It is composed of two primary dimensions:

  • APM Hosts: A flat fee per host (or container/Fargate task) running the APM tracer. This gives you basic APM functionality, including service maps and aggregate performance metrics.

  • Indexed Spans: You are charged per million indexed spans. Spans are the individual units of work within a trace (e.g., a database query, an external API call).

The vast majority of APM cost overruns occur in the "Indexed Spans" category. By default, Datadog uses an intelligent retention filter that captures a representative sample of traces (including errors, high-latency traces, and a baseline of normal traffic). However, many teams inadvertently configure aggressive custom retention filters, storing millions of identical, successful traces that provide zero diagnostic value.

Implementing Head-Based and Tail-Based Sampling

To optimize APM span costs, you must implement rigorous sampling strategies at two levels: at the application level (Head-Based Sampling) and at the Datadog backend level (Tail-Based Sampling).

Head-Based Sampling: This is configured within the Datadog tracing libraries (e.g., dd-trace-go, dd-trace-java) running inside your application. Head-based sampling decides at the start of a request whether to trace it. By reducing the DD_TRACE_SAMPLE_RATE from the default 1.0 (100%) to 0.1 (10%), you prevent 90% of traces from ever leaving your application. This saves both local application CPU overhead and Datadog ingestion costs. However, head-based sampling is blind; it might drop a trace that eventually results in an error.

# Kubernetes Deployment configuring Head-Based Sampling
apiVersion: apps/v1
kind: Deployment
metadata:
  name: payment-service
spec:
  template:
    spec:
      containers:
      - name: payment-api
        env:
        - name: DD_ENV
          value: "production"
        - name: DD_SERVICE
          value: "payment-api"
        # Reduce sampling to 5% for high-throughput, low-error services
        - name: DD_TRACE_SAMPLE_RATE
          value: "0.05"

Tail-Based Sampling (Retention Filters): This happens inside the Datadog backend. All traces that survive head-based sampling are sent to Datadog, but they are not immediately indexed and billed. Datadog evaluates these completed traces using Retention Filters. The optimal FinOps strategy is to configure Retention Filters to index 100% of traces containing an error (HTTP 5xx), 100% of traces exceeding a latency SLA (e.g., > 2 seconds), and a minimal fraction (e.g., 1%) of successful, low-latency traces to establish a baseline.

Using CloudAtler, SRE teams can model the financial impact of adjusting retention filters. CloudAtler simulates historical trace data against proposed filter adjustments, showing exactly how many thousands of dollars will be saved by dropping the indexing rate of standard HTTP 200 responses.

Mastering Log Management Pipelines and Rehydration

Ingestion vs. Indexing in Logging

Similar to metrics, Datadog logging costs are split into Ingestion and Indexing. Ingestion is relatively cheap and charges per GB of data sent to Datadog. Indexing is significantly more expensive and charges per million log events retained for active search. Furthermore, the cost of indexing varies based on the retention period (e.g., 3-day, 7-day, 15-day, or 30-day retention).

The most common and expensive mistake is indexing 100% of ingested logs for 30 days. Most logs (e.g., load balancer access logs, verbose application debug logs) lose their operational value within hours. Keeping them in hot, searchable indexes for a month is purely financial waste.

Strategic Log Routing and Exclusion Rules

The solution lies in Datadog Log Pipelines and Exclusion Rules. All logs should be ingested into Datadog, parsed using Grok rules, and enriched with standard tags. However, before they reach the indexing tier, they must pass through Exclusion Rules.

A mature FinOps implementation involves the following strategy:

  • Critical Errors (FATAL/ERROR): Indexed for 15 or 30 days.

  • Application Warnings (WARN): Indexed for 7 days.

  • Standard Access Logs (HTTP 200/INFO): Excluded from indexing entirely, or sampled at 10%, and retained for only 3 days.

  • Health Checks/Readiness Probes: Excluded completely.

# Example Datadog Log Pipeline Exclusion Rule Logic
# In the Datadog UI or via Terraform, you configure an exclusion filter
# Name: Drop Health Checks
# Query: service:kubelet OR service:ingress-nginx AND path:/healthz
# Exclusion %: 100%

# Name: Sample HTTP 200s
# Query: status:info AND http.status_code:200
# Exclusion %: 95%

Cloud Archives and Log Rehydration

If you exclude logs from indexing, how do you handle compliance requirements or long-term forensic investigations? Datadog provides a feature called Cloud Archives. You can configure Datadog to forward 100% of your ingested logs (before exclusion rules are applied) directly to an AWS S3 bucket, GCP Cloud Storage, or Azure Blob Storage owned by your organization.

Cloud storage is orders of magnitude cheaper than Datadog indexing. If an auditor requests access logs from three months ago, or a security incident requires analyzing historical payload data, SREs can use Datadog's "Log Rehydration" feature to pull the specific timeframe from S3 back into Datadog's hot index for temporary querying. This "cold storage with on-demand warming" architecture drastically slashes logging costs while maintaining total data durability.

Container and Host Billing: The Kubernetes Conundrum

When running Kubernetes, Datadog billing logic becomes intricately tied to your cluster architecture. Datadog bills per underlying worker node (host). However, if a node runs an excessive number of containers, you may incur container overage charges. Datadog includes an allowance of containers per host (typically 5 or 10, depending on the contract). If a host runs 30 containers, the excess containers are billed at a separate, granular rate.

This creates a fascinating intersection between Kubernetes cluster autoscaling (e.g., Karpenter) and Datadog billing. If Karpenter provisions massive nodes (e.g., m5.24xlarge) running 150 pods each, you will save on Datadog host fees (fewer total hosts) but you may get hit with massive container overage fees. Conversely, using many small nodes increases host fees but avoids container overages.

Taming DaemonSet Sprawl

In massive multi-tenant clusters, running the Datadog DaemonSet on every single node might not be necessary. For example, if you have dedicated node pools for batch processing workloads (e.g., Spark jobs) that do not require APM tracing or deep log analysis, you can prevent the Datadog Agent from scheduling on those nodes using Node Selectors and Taints.

# Datadog DaemonSet Configuration - Restricting by Node Label
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: datadog
spec:
  template:
    spec:
      # Only deploy Datadog agent to nodes labeled for core services
      nodeSelector:
        workload-type: "core-services"
      tolerations:
      - key: "node-role.kubernetes.io/master"
        operator: "Exists"
        effect: "NoSchedule"

CloudAtler provides advanced FinOps reporting that correlates Kubernetes node density with Datadog container overage fees. By analyzing these metrics, CloudAtler recommends the mathematically optimal node size and pod density to minimize the combined AWS compute and Datadog observability bill.

Synthetics, RUM, and Serverless Billing Traps

Beyond the core Infrastructure, Metrics, and APM pillars, modern architectures utilize Datadog Synthetics (automated browser/API tests), Real User Monitoring (RUM), and Serverless integrations (AWS Lambda). Each of these has distinct billing models that require strict governance.

Serverless Invocation Costs

When monitoring AWS Lambda functions, Datadog charges based on the number of Lambda invocations, not by the host. If a high-throughput Lambda function (e.g., processing Kinesis streams) receives millions of invocations per hour, the Datadog serverless bill can easily dwarf the actual AWS Lambda compute bill. To mitigate this, teams should utilize Datadog's Serverless Macro-level monitoring (pulling CloudWatch metrics via integration) for high-throughput functions, and reserve the Datadog Serverless Extension (which injects the tracer into the Lambda execution environment) only for complex, business-critical API Gateway-triggered functions where deep trace visibility is absolutely necessary.

RUM Session Replay Optimization

Real User Monitoring (RUM) charges per 1,000 user sessions. However, the premium feature—Session Replay, which records video-like playback of user interactions—is significantly more expensive. A common misconfiguration is enabling Session Replay on 100% of user sessions. Organizations must implement strict sampling for Session Replay. For example, you might capture 100% of sessions that result in an uncaught JavaScript error, 50% of sessions on the critical checkout path, and only 1% of standard browsing sessions. This surgical approach provides developers with the necessary debug data without incurring catastrophic costs.

Building a FinOps Culture Around Observability

Optimizing Datadog billing is not a one-time engineering task; it requires a cultural shift towards FinOps principles. Developers often treat observability as a "free" resource, adding verbose logs and high-cardinality metrics without considering the financial impact.

To build a sustainable model, organizations must implement chargeback or showback mechanisms. Using Datadog tags (e.g., team:payments, cost_center:engineering), infrastructure teams can allocate Datadog costs directly to the specific microservices and teams that generate the data. When a development team sees that their new deployment caused a $5,000 spike in APM indexing costs due to missing head-based sampling, they are incentivized to fix it.

The CloudAtler platform serves as the ultimate bridge in this cultural shift. By aggregating Datadog billing APIs and presenting them in developer-friendly dashboards, CloudAtler democratizes observability cost data. CloudAtler's anomaly detection algorithms can trigger Slack alerts to engineering managers the moment a rogue deployment begins emitting high-cardinality metrics, stopping billing shocks dead in their tracks.

Conclusion: Strategic Visibility

The true goal of observability FinOps is not to fly blind to save money; it is to achieve maximum strategic visibility at the lowest possible cost. Datadog provides a vast array of tools to manage data pipelines, control indexing, and filter noise. By mastering Metrics Without Limits, implementing aggressive APM sampling, utilizing Cloud Archives for cold log storage, and optimizing Kubernetes daemonset deployments, engineering teams can tame the Datadog beast.

As cloud architectures grow in complexity, the integration of advanced FinOps platforms like CloudAtler becomes indispensable. By combining rigorous engineering practices with continuous financial visibility, organizations can ensure that their observability spend scales linearly and predictably, providing maximum value to the business without breaking the bank.

See, Understand, Optimize -
All in One Place

Atler Pilot decodes your cloud spend story by bringing monitoring, automation, and intelligent insights together for faster and better cloud operations.