Skip to content

feat(apm): add adaptive sampling commands#553

Draft
rachelyangdog wants to merge 2 commits into
DataDog:mainfrom
rachelyangdog:rachel/apm-adaptive-sampling-commands
Draft

feat(apm): add adaptive sampling commands#553
rachelyangdog wants to merge 2 commits into
DataDog:mainfrom
rachelyangdog:rachel/apm-adaptive-sampling-commands

Conversation

@rachelyangdog
Copy link
Copy Markdown
Contributor

What does this PR do?

Motivation

Additional Notes

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

Related Issues

rachelyangdog and others added 2 commits June 2, 2026 13:59
Adds `pup apm sampling-rules {list,get,create,update,delete}` for
managing customer per-(service,env,resource) head-based sampling rules.
Backed by Remote Config product APM_TRACING with provenance=customer.
Rules surface on traces with `_dd.p.dm:-11` and
`ingestion_reason:remote_rule`.

## Commands

  pup apm sampling-rules list [--service S --env E]
  pup apm sampling-rules get   <id>
  pup apm sampling-rules create --service S --env E --resource R --sample-rate F
  pup apm sampling-rules update <id> --service S --env E --resource R --sample-rate F
  pup apm sampling-rules delete <id>

When `--service` and `--env` are both given, list narrows via the
backend's `/configs/by_target` endpoint.

## Scopes

  - apm_remote_configuration_read   (added to default + read_only)
  - apm_remote_configuration_write  (added to default)

Both scopes are on pup's OUISvc registrable client allowlist as of the
recent OAuth rollout. Backend support is in place:

  - dd-source PR `rachel.yang/apm-trace-configurations-oauth-auth`
    (Rapid service-default OAuth on trace-configurations)
  - dd-go PR `rachel.yang/rc-api-proxy-apm-tracing-oauth`
    (rc-api-proxy authn_methods on apm_tracing routes)

## Tests

8 tests added in `commands::apm::tests`, matching the
service_remapping_* pattern:

  test_sampling_rules_list
  test_sampling_rules_list_by_target
  test_sampling_rules_get
  test_sampling_rules_get_not_found
  test_sampling_rules_create
  test_sampling_rules_create_api_error
  test_sampling_rules_update
  test_sampling_rules_delete

All pass locally. The 5 unrelated test failures in `cases`, `dbm`,
`logs`, `metrics`, `traces` are pre-existing DNS-resolution flakes
against `unused.local` and not touched by this change.

## Follow-ups

  - `pup apm adaptive-sampling` commands (allotment + onboarding) —
    separate PR. Requires the `apm_service_ingest_{read,write}` scopes
    which are also already on the OUISvc allowlist.
  - Flip the agent-skills `dd-apm/sampling` skill PR from draft to
    ready once these commands ship in a release.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds `pup apm adaptive-sampling` subcommands for managing Datadog's
adaptive sampling (server-driven dynamic sampling) — onboarding
services and configuring the monthly byte/percent allotment. Datadog
auto-tunes per-(service, env, resource) sampling rates to fit the
budget. Generated rules surface on traces with `_dd.p.dm:-12` and
`ingestion_reason:adaptive_rule`.

Builds on the sampling-rules PR (#PR_B1) and the same OAuth rollout.

## Commands

  pup apm adaptive-sampling onboarding-status [--service S --env E]
  pup apm adaptive-sampling onboard            --service S --env E
  pup apm adaptive-sampling offboard           --service S --env E
  pup apm adaptive-sampling get-allotment
  pup apm adaptive-sampling set-allotment      (--bytes N | --percent F)
  pup apm adaptive-sampling check
  pup apm adaptive-sampling preview            (--bytes N | --percent F)

`set-allotment` and `preview` take exactly one of `--bytes` or
`--percent` (enforced via clap `conflicts_with`). Strategy is inferred:
`fixed_target` for bytes, `percent_total` for percent.

## Scopes

  - apm_service_ingest_read   (added to default + read_only)
  - apm_service_ingest_write  (added to default)

Both already on pup's OUISvc registrable client allowlist (added in the
same rollout as `apm_remote_configuration_{read,write}` for the
sampling-rules commands).

The adaptive-sampling endpoints require BOTH `apm_service_ingest_*` AND
`apm_remote_configuration_*` (RoutePermissions with operator AND) —
the latter is added by the sampling-rules PR this builds on.

## Endpoints

  GET/POST /api/ui/adaptive_sampling/onboarding_status
  GET/POST /api/ui/adaptive_sampling/allotment_config
  POST     /api/ui/adaptive_sampling/preview
  GET      /api/ui/adaptive_sampling/allotment_check

All in dd-source `trace-configurations` service, which got
`ValidOAuthAccessToken` in the dd-source-side OAuth PR.

## Tests

9 tests added in `commands::apm::tests`:

  test_adaptive_sampling_onboarding_status_no_filter
  test_adaptive_sampling_onboarding_status_with_filter
  test_adaptive_sampling_onboard
  test_adaptive_sampling_offboard
  test_adaptive_sampling_get_allotment
  test_adaptive_sampling_set_allotment_bytes
  test_adaptive_sampling_set_allotment_percent
  test_adaptive_sampling_check
  test_adaptive_sampling_preview

All pass locally. The same 5 pre-existing DNS-flakes in unrelated
modules (cases/dbm/logs/metrics/traces) remain — not touched here.

## Follow-up

Once both B1 (sampling-rules) and this PR (B2) ship in a pup release,
flip the agent-skills `dd-apm/sampling` skill PR from draft to ready.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rachelyangdog rachelyangdog requested a review from a team as a code owner June 2, 2026 18:14
@rachelyangdog rachelyangdog marked this pull request as draft June 2, 2026 18:14
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented Jun 2, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

CI | Check, Test &amp; Coverage   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). Compilation error in apm.rs: expected close parenthesis, found: async

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8cfbaf5 | Docs | Datadog PR Page | Give us feedback!

@rachelyangdog rachelyangdog changed the title Rachel/apm adaptive sampling commands feat(apm): add adaptive sampling commands Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant