For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging.md. A documentation index is available at /llms.txt.

Overview

Unified service tagging ties Datadog telemetry together by using three reserved tags: env, service, and version.

With these three tags, you can:

  • Identify deployment impact with trace and container metrics filtered by version
  • Navigate seamlessly across traces, metrics, and logs with consistent tags
  • View service data based on environment or version in a unified fashion

Notes:

  • The version tag is expected to change with each new application deployment. Two different versions of your application’s code should have distinct version tags.
  • The official service of a log defaults to the container short-image if no Autodiscovery logs configuration is present. To override the official service of a log, use the Unified Service Tagging options below or add a full custom Docker or Kubernetes Autodiscovery log configuration.
  • Host information is excluded for database and cache spans because the host associated with the span is not the database/cache host.

Requirements

  • Unified service tagging requires the setup of a Datadog Agent that is 6.19.x/7.19.x or higher.

  • Unified service tagging requires an SDK version that supports new configurations of the reserved tags. More information can be found per language in the setup instructions.

LanguageMinimum SDK Version
.NET1.17.0+
C++0.1.0+
Go1.24.0+
Java0.50.0+
Node0.20.3+
PHP0.47.0+
Python0.38.0+
Ruby0.34.0+
  • Unified service tagging requires knowledge of configuring tags. If you are unsure of how to configure tags, read the Getting Started with Tagging and Assigning Tags documentation before proceeding to configuration.

Configuration

To start configuring unified service tagging, choose your environment:

Containerized environment

In containerized environments, env, service, and version are set through the service’s environment variables or labels (for example, Kubernetes deployment and pod labels, Docker container labels). The Datadog Agent detects this tagging configuration and applies it to the data it collects from containers.

To setup unified service tagging in a containerized environment:

  1. Enable Autodiscovery. This allows the Datadog Agent to automatically identify services running on a specific container and gathers data from those services to map environment variables to the env, service, and version tags.

  2. If you are using Docker, make sure the Agent can access your container’s Docker socket. This allows the Agent detect the environment variables and map them to the standard tags.

  3. Configure your environment that corresponds to your container orchestration service based on either full configuration or partial configuration as detailed below.

Configuration

Full configuration

To get the full range of unified service tagging in Kubernetes, add the following labels to both the parent workload and the pod template.

  • tags.datadoghq.com/env: "<ENV>"
  • tags.datadoghq.com/service: "<SERVICE>"
  • tags.datadoghq.com/version: "<VERSION>"

For APM-enabled applications additionally set the environment variables DD_ENV, DD_SERVICE, and DD_VERSION for the Datadog tracers.

You can set these environment variables manually or with the Kubernetes’s downward API. If you are using the Cluster Agent’s Admission Controller to mutate your pods, those three environment variables are automatically injected to match your labels.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    tags.datadoghq.com/env: "<ENV>"
    tags.datadoghq.com/service: "<SERVICE>"
    tags.datadoghq.com/version: "<VERSION>" 
# (...)
spec: 
  template:
    metadata:
      labels:
        tags.datadoghq.com/env: "<ENV>"
        tags.datadoghq.com/service: "<SERVICE>"
        tags.datadoghq.com/version: "<VERSION>" 
    containers:
    - # (...)
      env:
        - name: DD_ENV
          valueFrom:
            fieldRef:
              fieldPath: metadata.labels['tags.datadoghq.com/env']
        - name: DD_SERVICE
          valueFrom:
            fieldRef:
              fieldPath: metadata.labels['tags.datadoghq.com/service']
        - name: DD_VERSION
          valueFrom:
            fieldRef:
              fieldPath: metadata.labels['tags.datadoghq.com/version']

You can also use the OpenTelemetry Resource Attributes environment variables to set the env, service, and version tags:

  containers:
  -  ...
     env:
         - name: OTEL_RESOURCE_ATTRIBUTES
           value: "service.name=<SERVICE>,service.version=<VERSION>,deployment.environment=<ENV>"
         - name: OTEL_SERVICE_NAME
           value: "<SERVICE>"
The OTEL_SERVICE_NAME environment variable takes precedence over the service.name attribute in the OTEL_RESOURCE_ATTRIBUTES environment variable.

These labels cover Kubernetes CPU, memory, network, and disk metrics, as well as general container tagging and log collection. These labels are also used by the Cluster Agent and its reported Kubernetes State Metrics.

Partial configuration
Global env handling

If your Kubernetes cluster is entirely a single environment, for example, only env:production nodes and workloads, you can provide this to your Agent configuration rather than tagging each workload individually.

With the Datadog Operator:

#(...)
spec:
  global:
    tags:
      - "env:<ENV>"

With the Datadog Helm Chart:

datadog:
  #(...)
  tags:
    - "env:<ENV>"

This establishes this as a host-level tag inherited on all your data associated with each host. This is also applied to all Kubernetes State Metrics and is the default env on your APM spans. Take care with these tags, as if you have a global env tag set and a different env tag set on your pod, that pod’s data contains both env tags.

Pod-level metrics

The DD_ENV, DD_SERVICE, and DD_VERSION environment variables are only required if you are using APM in your applications; otherwise, you can omit them. Add the following standard labels (tags.datadoghq.com) to the pod spec, as well as optionally to the parent workload, like the Deployment, StatefulSet, or Job:

template:
  metadata:
    labels:
      tags.datadoghq.com/env: "<ENV>"
      tags.datadoghq.com/service: "<SERVICE>"
      tags.datadoghq.com/version: "<VERSION>" 

If you have multiple containers per pod, you can specify standard labels by container:

tags.datadoghq.com/<CONTAINER_NAME>.env
tags.datadoghq.com/<CONTAINER_NAME>.service
tags.datadoghq.com/<CONTAINER_NAME>.version 
Datadog SDK and StatsD client

To configure Datadog SDK and StatsD client environment variables, use the Kubernetes’s downward API in the format below:

containers:
-  ...
    env:
        - name: DD_ENV
          valueFrom:
            fieldRef:
              fieldPath: metadata.labels['tags.datadoghq.com/env']
        - name: DD_SERVICE
          valueFrom:
            fieldRef:
              fieldPath: metadata.labels['tags.datadoghq.com/service']
        - name: DD_VERSION
          valueFrom:
            fieldRef:
              fieldPath: metadata.labels['tags.datadoghq.com/version'] 
Full configuration

Set the DD_ENV, DD_SERVICE, and DD_VERSION environment variables and corresponding Docker labels for your container to get the full range of unified service tagging.

The values for service and version can be provided in the Dockerfile:

ENV DD_SERVICE <SERVICE>
ENV DD_VERSION <VERSION> 

LABEL com.datadoghq.tags.service="<SERVICE>"
LABEL com.datadoghq.tags.version="<VERSION>" 

Since env is likely determined at deploy time, you can inject the environment variable and label later:

docker run -e DD_ENV=<ENV> -l com.datadoghq.tags.env=<ENV> ...

You may also prefer to set everything at deploy time:

docker run -e DD_ENV="<ENV>" \
           -e DD_SERVICE="<SERVICE>" \
           -e DD_VERSION="<VERSION>" \ 
           -l com.datadoghq.tags.env="<ENV>" \
           -l com.datadoghq.tags.service="<SERVICE>" \
           -l com.datadoghq.tags.version="<VERSION>" \ 
           ...
Partial configuration

If your service has no need for the Datadog environment variables (for example, third party software like Redis, PostgreSQL, NGINX, and applications not traced by APM) you can use the Docker labels:

com.datadoghq.tags.env
com.datadoghq.tags.service
com.datadoghq.tags.version 

As explained in the full configuration, these labels can be set in a Dockerfile or as arguments for launching the container.

On ECS Fargate using Fluent Bit or FireLens, unified service tagging is only available for metrics and traces, not log collection.
Full configuration

Set the DD_ENV, DD_SERVICE, and DD_VERSION (optional with automatic version tagging) environment variables and corresponding Docker labels in the runtime environment of each service’s container to get the full range of unified service tagging. For instance, you can set all of this configuration in one place through your ECS task definition:

"environment": [
  {
    "name": "DD_ENV",
    "value": "<ENV>"
  },
  {
    "name": "DD_SERVICE",
    "value": "<SERVICE>"
  },
  {
    "name": "DD_VERSION",
    "value": "<VERSION>"
  }
   
],
"dockerLabels": {
  "com.datadoghq.tags.env": "<ENV>",
  "com.datadoghq.tags.service": "<SERVICE>",
  "com.datadoghq.tags.version": "<VERSION>"
}
On ECS Fargate, you must add these tags to your application container, not the Datadog Agent container.
Partial configuration

If your service has no need for the Datadog environment variables (for example, third party software like Redis, PostgreSQL, NGINX, and applications not traced by APM) you can use the Docker labels in your ECS task definition:

"dockerLabels": {
  "com.datadoghq.tags.env": "<ENV>",
  "com.datadoghq.tags.service": "<SERVICE>",
  "com.datadoghq.tags.version": "<VERSION>"
}
Automatic version tagging for APM data in containerized environments
This feature is only enabled for Application Performance Monitoring (APM) data.

You can use the version tag in APM to monitor deployments and to identify faulty code deployments through Automatic Faulty Deployment Detection.

For APM data, Datadog sets the version tag for you in the following priority order. If you manually set version, Datadog does not override your version value.

PriorityVersion Value
1{your version value}
2{image_tag}_{first_7_digits_of_git_commit_sha}
3{image_tag} or {first_7_digits_of_git_commit_sha} if only one is available

Requirements:

  • Datadog Agent Version 7.52.0 or greater
  • If your services run in a containerized environment and image_tag is sufficient for tracking new version deployments, no further configuration is needed.
  • If your services are not running in a containerized environment, or to include the Git SHA, embed Git information in your build artifacts.

Non-containerized environment

Depending on how you build and deploy your services’ binaries or executables, you may have several options available for setting environment variables. Since you may run one or more services per host, Datadog recommends scoping these environment variables to a single process.

To form a single point of configuration for all telemetry emitted directly from your services’ runtime for traces, logs, RUM resources, Synthetics tests, StatsD metrics, or system metrics, either:

  1. Export the environment variables in the command for your executable:

    DD_ENV=<env> DD_SERVICE=<service> DD_VERSION=<version> /bin/my-service
    
  2. Or use Chef, Ansible, or another orchestration tool to populate a service’s systemd or initd configuration file with the DD environment variables. When the service process starts, it has access to those variables.

    When configuring your traces for unified service tagging:

    1. Configure the Datadog SDK with DD_ENV to keep the definition of env closer to the application that is generating the traces. This method allows the env tag to be sourced automatically from a tag in the span metadata.

    2. Configure spans with DD_VERSION to add version to all spans that fall under the service that belongs to the SDK (generally DD_SERVICE). This means that if your service creates spans with the name of an external service, those spans do not receive version as a tag.

      As long as version is present in spans, it is added to trace metrics generated from those spans. The version can be added manually in-code or automatically by the Datadog SDK. When configured, these are used by the APM and DogStatsD clients to tag trace data and StatsD metrics with env, service, and version. If enabled, the Datadog SDK also injects the values of these variables into your logs.

      Note: There can only be one service per span. Trace metrics generally have a single service as well. However, if you have a different service defined in your hosts’ tags, that configured service tag shows up on all trace metrics emitted from that host.

    If you’re using connected logs and traces, enable automatic logs injection if supported for your Datadog SDK. Then, the Datadog SDK automatically injects env, service, and version into your logs, therefore eliminating manual configuration for those fields elsewhere.

    If you’re using connected RUM and traces, specify the browser application in the service field, define the environment in the env field, and list the versions in the version field of your initialization file.

    When you create a RUM application, confirm the env and service names.

    If you’re using connected Synthetic browser tests and traces, specify a URL to send headers to under the APM Integration for Browser Tests section of the Integration Settings page.

    You can use * for wildcards, for example: https://*.datadoghq.com.

    Tags are added in an append-only fashion for custom StatsD metrics. For example, if you have two different values for env, the metrics are tagged with both environments. There is no order in which one tag overrides another of the same name.

    If your service has access to DD_ENV, DD_SERVICE, and DD_VERSION, then the DogStatsD client automatically adds the corresponding tags to your custom metrics.

    Note: The Datadog DogStatsD clients for .NET and PHP do not support this functionality.

    You can add env and service tags to your infrastructure metrics. In non-containerized contexts, tagging for service metrics is configured at the Agent level.

    Because this configuration does not change for each invocation of a service’s process, adding version is not recommended.

    Single service per host

    Set the following configuration in the Agent’s main configuration file:

    env: <ENV>
    tags:
      - service:<SERVICE>
    

    This setup guarantees consistent tagging of env and service for all data emitted by the Agent.

    Multiple services per host

    Set the following configuration in the Agent’s main configuration file:

    env: <ENV>
    

    To get unique service tags on CPU, memory, and disk I/O metrics at the process level, configure a process check in the Agent’s configuration folder (for example, in the conf.d folder under process.d/conf.yaml):

    init_config:
    instances:
        - name: web-app
          search_string: ["/bin/web-app"]
          exact_match: false
          service: web-app
        - name: nginx
          search_string: ["nginx"]
          exact_match: false
          service: nginx-web-app
    

    Note: If you already have a service tag set globally in your Agent’s main configuration file, the process metrics are tagged with two services. Since this can cause confusion with interpreting the metrics, it is recommended to configure the service tag only in the configuration of the process check.

Serverless environment

For more information about AWS Lambda functions, see how to connect your Lambda telemetry using tags.

OpenTelemetry

When using OpenTelemetry, map the following resource attributes to their corresponding Datadog conventions:

OpenTelemetry conventionDatadog convention
deployment.environment 1env
deployment.environment.name 2env
service.nameservice
service.versionversion

1: deployment.environment is deprecated in favor of deployment.environment.name in OpenTelemetry semantic conventions v1.27.0.
2: deployment.environment.name is supported in Datadog Agent 7.58.0+ and Datadog Exporter v0.110.0+.

Datadog-specific environment variables like DD_SERVICE, DD_ENV or DD_VERSION are not supported out of the box in your OpenTelemetry configuration.

To set resource attributes using environment variables, set OTEL_RESOURCE_ATTRIBUTES with the appropriate values:

export OTEL_RESOURCE_ATTRIBUTES="service.name=my-service,deployment.environment=production,service.version=1.2.3"

To set resource attributes in your application code, create a Resource with the desired attributes and associate it with your TracerProvider.

Here’s an example using Python:

from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider

resource = Resource(attributes={
   "service.name": "<SERVICE>",
   "deployment.environment": "<ENV>",
   "service.version": "<VERSION>"
})
tracer_provider = TracerProvider(resource=resource)

To set resource attributes from the OpenTelemetry Collector, use the transform processor in your Collector configuration file. The transform processor allows you to modify attributes of the collected telemetry data before sending it to the Datadog exporter:

processors:
  transform:
    trace_statements:
      - context: resource
        statements:
          - set(attributes["service.name"], "my-service")
          - set(attributes["deployment.environment"], "production")
          - set(attributes["service.version"], "1.2.3")
...

Further Reading