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, add Autodiscovery Docker labels/pod annotations. For example: "com.datadoghq.ad.logs"='[{"service": "service-name"}]'
  • 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 a tracer version that supports new configurations of the reserved tags. More information can be found per language in the setup instructions.

LanguageMinimum Tracer 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

If you deployed the Datadog Cluster Agent with Admission Controller enabled, the Admission Controller mutates the pod manifests and injects all required environment variables (based on configured mutation conditions). In that case, manual configuration of DD_ environment variables in pod manifests is unnecessary. For more information, see the Admission Controller documentation.

Full configuration

To get the full range of unified service tagging when using Kubernetes, add environment variables to both the deployment object level and the pod template spec level:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    tags.datadoghq.com/env: "<ENV>"
    tags.datadoghq.com/service: "<SERVICE>"
    tags.datadoghq.com/version: "<VERSION>" 
...
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>"
Note: The OTEL_SERVICE_NAME environment variable takes precedence over the service.name attribute in the OTEL_RESOURCE_ATTRIBUTES environment variable.
Partial configuration
Pod-level metrics

To configure pod-level metrics, add the following standard labels (tags.datadoghq.com) to the pod spec of a Deployment, StatefulSet, or Job:

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

These labels cover pod-level Kubernetes CPU, memory, network, and disk metrics, and can be used for injecting DD_ENV, DD_SERVICE, and DD_VERSION into your service’s container through Kubernetes’s downward API.

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 
State metrics

To configure Kubernetes State Metrics:

  1. Set join_standard_tags to true in your configuration file. See this example configuration file for the setting location.

  2. Add the same standard labels to the collection of labels for the parent resource, for example: Deployment.

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>" 
APM tracer and StatsD client

To configure APM tracer 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'] 
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 if you’d also like to have the git SHA included, embed Git information in your build artifacts
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.

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 if you’d also like to have the git SHA included, embed Git information in your build artifacts
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>"
}
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 if you’d also like to have the git SHA included, 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 APM Tracer 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 tracer (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 APM Tracer. 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 APM tracer 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 APM Tracer. Then, the APM Tracer 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

PREVIEWING: mcretzman/DOCS-9337-add-cloud-info-byoti