Grafana Cloud

Adaptive Traces HTTP API

The following topic describes the Adaptive Traces HTTP API.

Before you begin

To interact with the API, gather the following information:

  • URL: In the form https://<your-grafana-cloud-tempo-url>.grafana.net. To find your URL value, go to your Grafana Cloud account and check the Details page of your hosted Tempo endpoint.
  • TENANT: The numeric instance ID where you want to use Adaptive Traces. To find your TENANT value, go to your Grafana Cloud account and check the Details page of your hosted Tempo endpoint for Username / Instance ID.
  • TOKEN: A token from a Grafana Cloud Access Policy that has the adaptive-traces-policies:write scope for your stack ID.

Note

You can create Grafana Cloud Access Policies from the Grafana portal, with the API, or in your Grafana Cloud Stack.

The format of a sampling policy

Each sampling policy looks similar to this:

JSON
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "type": "probabilistic",
  "name": "Sample 10% of all traces",
  "body": {
    "sampling_percentage": 10
  },
  "expires_at": "2025-12-31T23:59:59Z",
  "version_created_at": "2025-01-15T10:30:00Z",
  "version_created_by": "user@example.com"
}

In the preceding example:

  • id is the unique identifier of the policy (set by the server).
  • type is the type of sampling policy. Refer to Policy types for a list of available types.
  • name is a human-readable name for the policy.
  • body is a JSON object containing the policy-specific configuration. The structure depends on the type.
  • expires_at (optional) is an ISO 8601 timestamp indicating when the policy expires.
  • version_created_at is the timestamp when the current version of the policy was created.
  • version_created_by is the user who created the current version of the policy.
  • version_recommendation_id (optional) is the id of the recommendation that created this version of the policy, if it was created by applying a recommendation rather than directly through the API.

Policies

List policies

List all sampling policies using the following command:

Bash
curl -u "$TENANT:$TOKEN" "$URL/adaptive-traces/api/v1/policies"

The response is an array of policy objects:

JSON
[
  {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "type": "probabilistic",
    "name": "Sample 10% of all traces",
    "body": {
      "sampling_percentage": 10
    },
    "version_created_at": "2025-01-15T10:30:00Z",
    "version_created_by": "user@example.com"
  },
  {
    "id": "987fcdeb-51a2-12d3-a456-426614174000",
    "type": "status_code",
    "name": "Keep all error traces",
    "body": {
      "status_codes": ["ERROR"]
    },
    "version_created_at": "2025-01-15T10:35:00Z",
    "version_created_by": "user@example.com"
  }
]

Get a policy

Get a specific policy by ID:

Bash
curl -u "$TENANT:$TOKEN" "$URL/adaptive-traces/api/v1/policies/<policy_id>"

Replace <policy_id> with the UUID of the policy to retrieve.

Create a policy

Create a new sampling policy:

Bash
curl -u "$TENANT:$TOKEN" --request POST \
  --header "Content-Type: application/json" \
  --data @policy.json \
  "$URL/adaptive-traces/api/v1/policies"

The request body must include the type, name, and body fields. For example, the contents of policy.json:

JSON
{
  "type": "probabilistic",
  "name": "Sample 5% of all traces",
  "body": {
    "sampling_percentage": 5
  }
}

If successful, the server returns the created policy including its server-assigned id.

Update a policy

Update an existing policy by ID:

Bash
curl -u "$TENANT:$TOKEN" --request PUT \
  --header "Content-Type: application/json" \
  --data @policy.json \
  "$URL/adaptive-traces/api/v1/policies/<policy_id>"

Replace <policy_id> with the UUID of the policy to update. The request body must include the full policy definition (type, name, and body fields).

Partially update a policy

Update one or more fields of an existing policy by ID, without resending the full policy definition:

Bash
curl -u "$TENANT:$TOKEN" --request PATCH \
  --header "Content-Type: application/json" \
  --data @policy-patch.json \
  "$URL/adaptive-traces/api/v1/policies/<policy_id>"

Replace <policy_id> with the UUID of the policy to update. The request body can include any of type, name, body, and expires_at; only the fields present in the request are changed. For example, the contents of policy-patch.json to change only the name:

JSON
{
  "name": "Sample 10% of all traces (renamed)"
}

List policy versions

List the version history of a policy by ID:

Bash
curl -u "$TENANT:$TOKEN" "$URL/adaptive-traces/api/v1/policies/<policy_id>/versions"

Replace <policy_id> with the UUID of the policy. You can page through results with the page and limit query parameters (page defaults to 1, limit defaults to 25).

The response is an array of version objects, each including the version’s id, the policy body, type, and name at that version, the recommendation_id of the recommendation that created the version (if any), created_at, and created_by, and, if the version was later superseded, deleted_at and deleted_by.

Revert a policy to a previous version

Update a policy by creating a new version based on one of its previous versions:

Bash
curl -u "$TENANT:$TOKEN" --request POST \
  "$URL/adaptive-traces/api/v1/policies/<policy_id>/revert/<version_id>"

Replace <policy_id> with the UUID of the policy, and <version_id> with the id of the version (from List policy versions) to revert to.

Delete a policy

Delete a policy by ID:

Bash
curl -u "$TENANT:$TOKEN" --request DELETE \
  "$URL/adaptive-traces/api/v1/policies/<policy_id>"

Replace <policy_id> with the UUID of the policy to delete.

Recommendations

Adaptive Traces generates recommendations for sampling policies based on your trace data. You can list, apply, or dismiss recommendations using the API.

List recommendations

List all sampling recommendations:

Bash
curl -u "$TENANT:$TOKEN" "$URL/adaptive-traces/api/v1/recommendations"

Note

Recommendations are generated asynchronously; the API call returns the most recently generated set of recommendations.

The response is an array of recommendation objects:

JSON
[
  {
    "id": "abc12345-e89b-12d3-a456-426614174000",
    "message": "Add a probabilistic sampling policy for service 'frontend'",
    "tags": ["cost-reduction"],
    "created_at": "2025-01-15T10:30:00Z",
    "applied": false,
    "dismissed": false,
    "stale": false,
    "actions": [
      {
        "action": "create",
        "recommendation_seed_id": "seed-001",
        "seed": {
          "id": "seed-001",
          "type": "probabilistic",
          "name": "Sample frontend traces",
          "body": {
            "sampling_percentage": 10
          }
        }
      }
    ]
  }
]

Each recommendation contains one or more actions that describe the policy changes that are applied when the recommendation is accepted. The possible action types are create, update, and delete.

A recommendation also includes applied_at and dismissed_at timestamps, set once the recommendation is applied or dismissed respectively.

Get a recommendation

Get a specific recommendation by ID:

Bash
curl -u "$TENANT:$TOKEN" "$URL/adaptive-traces/api/v1/recommendations/<recommendation_id>"

Replace <recommendation_id> with the UUID of the recommendation to retrieve.

Apply a recommendation

Apply a recommendation to modify policies according to its actions:

Bash
curl -u "$TENANT:$TOKEN" --request POST \
  "$URL/adaptive-traces/api/v1/recommendations/<recommendation_id>/apply"

Replace <recommendation_id> with the UUID of the recommendation to apply.

Dismiss a recommendation

Dismiss a recommendation without applying it:

Bash
curl -u "$TENANT:$TOKEN" --request POST \
  "$URL/adaptive-traces/api/v1/recommendations/<recommendation_id>/dismiss"

Replace <recommendation_id> with the UUID of the recommendation to dismiss.