For AI agents: A markdown version of this page is available at https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/api/latest/apm-retention-filters/create-a-retention-filter.md. A documentation index is available at /llms.txt.
Language
Datadog site

Create a retention filter

POSThttps://api.datadoghq.com/api/v2/apm/config/retention-filtershttps://api.us3.datadoghq.com/api/v2/apm/config/retention-filtershttps://api.us5.datadoghq.com/api/v2/apm/config/retention-filtershttps://api.datadoghq.eu/api/v2/apm/config/retention-filtershttps://api.ap1.datadoghq.com/api/v2/apm/config/retention-filtershttps://api.ap2.datadoghq.com/api/v2/apm/config/retention-filtershttps://api.uk1.datadoghq.com/api/v2/apm/config/retention-filtershttps://api.ddog-gov.com/api/v2/apm/config/retention-filtershttps://api.us2.ddog-gov.com/api/v2/apm/config/retention-filters

Overview

Create a retention filter to index spans in your organization. Returns the retention filter definition when the request is successful.

Default filters with types spans-errors-sampling-processor and spans-appsec-sampling-processor cannot be created.

This endpoint requires the apm_retention_filter_write permission.

Request

Body Data (required)

The definition of the new retention filter.

Field
Type
Description
data [required]
object

The body of the retention filter to be created.

Response

OK

The retention filters definition.

Field
Type
Description
data
object

The definition of the retention filter.

Code Example

Create a retention filter returns "OK" response
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
Create a retention filter with trace rate returns "OK" response
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF
# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/apm/config/retention-filters" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "filter": {
        "query": "@http.status_code:200 service:my-service"
      },
      "filter_type": "spans-sampling-processor",
      "name": "my retention filter",
      "rate": 1.0,
      "trace_rate": 1.0
    },
    "type": "apm_retention_filter"
  }
}
EOF