For AI agents: A markdown version of this page is available at https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/fr/api/latest/tag-rules/create-a-tag-rule.md. A documentation index is available at /llms.txt.
Language
Datadog site

Create a tag rule

WARNINGNote: This endpoint is in preview and is subject to change. If you have any feedback, contact Datadog support.
POSThttps://api.datadoghq.com/api/v2/governance/tag_ruleshttps://api.us3.datadoghq.com/api/v2/governance/tag_ruleshttps://api.us5.datadoghq.com/api/v2/governance/tag_ruleshttps://api.datadoghq.eu/api/v2/governance/tag_ruleshttps://api.ap1.datadoghq.com/api/v2/governance/tag_ruleshttps://api.ap2.datadoghq.com/api/v2/governance/tag_ruleshttps://api.uk1.datadoghq.com/api/v2/governance/tag_ruleshttps://api.ddog-gov.com/api/v2/governance/tag_ruleshttps://api.us2.ddog-gov.com/api/v2/governance/tag_rules

Présentation

Create a new tag rule for the organization. The caller's organization is derived from the authenticated user; cross-organization creation is not supported. Fields such as rule_id, version, and the timestamp/audit fields are assigned by the server.

This endpoint requires the telemetry_rules_create permission.

Requête

Body Data (required)

Champ
Type
Description
data [required]
object

Data object for creating a tag rule.

Réponse

Created

A single tag rule.

Champ
Type
Description
data [required]
object

A tag rule resource.

included
[object]

Related resources fetched alongside the primary tag rules. Populated when an include query parameter is supplied.

Exemple de code

Create a tag rule
# 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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
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/governance/tag_rules" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "enabled": true,
      "name": "Service tag must be one of api or web",
      "negated": false,
      "required": true,
      "rule_type": "surfacing",
      "scope": "env",
      "source": "logs",
      "tag_key": "service",
      "tag_value_patterns": [
        "api",
        "web"
      ]
    },
    "type": "tag_rule"
  }
}
EOF