/agent-skills:dd-instrument-test-optimizationfrom agent-skills
Sets up Datadog Test Optimization in CI pipelines for Node.js, Python, Java, Go, Ruby, .NET, Swift, or JUnit XML. Configures auto-instrumentation or manual tracers, forwards container variables, and verifies test events arrive.
Ships in agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Test Optimization collects per-test traces, failure reasons, and git metadata from CI test runs so Datadog can detect flaky tests and run Test Impact Analysis. No application resource has to be created in Datadog beforehand: the test service appears automatically when a test run sends spans with a valid API key and site.
datadog/test-visibility-github-action@v3, the GitLab script, or the CircleCI orb), run the language tracer in CI Visibility mode (DD_CIVISIBILITY_ENABLED=true and DD_CIVISIBILITY_AGENTLESS_ENABLED=true with the test runner hook), or upload JUnit XML reports (datadog-ci junit upload). Having dd-trace or ddtrace installed for APM or Code Coverage does not turn Test Optimization on.NODE_OPTIONS across steps: for JavaScript and TypeScript on GitHub Actions, datadog/test-visibility-github-action@v3 exports DD_TRACE_PACKAGE (and DD_TRACE_ESM_IMPORT for Vitest), which the test step itself must wire into NODE_OPTIONS. Without that env line on the test step, no test spans are collected.docker run or docker compose, host-level environment variables do not enter the container automatically. The Datadog variables, the runtime injection variable, and the CI provider's git/pipeline variables must be passed into the container, and prebuilt test images must use manual instrumentation inside the container.DD_API_KEY in agentless mode. Reference it from the CI provider's secret store (${{ secrets.DD_API_KEY }}, $DD_API_KEY, or $(DD_API_KEY)); never write a literal key into a workflow or config file.Copy these steps into your reply and tick them off as you go.
Inspect. In a collection of independent projects, ask which one to instrument. Read dependency manifests, test configs, and CI workflow files (.github/workflows/*.yml, .gitlab-ci.yml, .circleci/config.yml, Jenkinsfile, .buildkite/pipeline.yml, buildkite/pipeline.yml, bitbucket-pipelines.yml, .travis.yml, azure-pipelines.yml) to record:
nodejs (JS/TS), python, java (Java/Kotlin/Scala + maven/gradle/sbt), go, ruby, dotnet, swift, or other.jest-circus), Vitest (>=1.6.0), Mocha (>=5.2.0), Playwright (>=1.18.0), Cypress (>=6.7.0), Cucumber, pytest (>=3.0.0), unittest, JUnit 4 (>=4.10) / JUnit 5 (>=5.3), TestNG, Spock, Scalatest, RSpec (>=3.0.0), Minitest (>=5.0.0), go test, xUnit (>=2.2), NUnit (>=3.0), MSTest v2 (>=14), BenchmarkDotNet, or XCTest.docker run or docker compose).<REPO>): normalized lowercase host/owner/repo without scheme or .git (from git remote get-url origin, package.json, go.mod, pyproject.toml, or pom.xml).<SITE>): from DD_SITE or existing Datadog config (default datadoghq.com when unset; if an invalid site is supplied, stop and ask).DD_CIVISIBILITY_ENABLED / ddtrace-run / --ddtrace / orchestrion go test / dd-trace ci run), or datadog-ci junit upload.Check prerequisites and stop conditions.
node --test or an older framework version): stop before editing unless the user explicitly requested JUnit XML upload. Explain the two options—migrating to a supported runner (such as Vitest for Node tests) for full tracing and flaky-test management, or uploading JUnit XML reports via references/junit-xml.md—and ask which path to take.Choose the instrumentation mode.
Datadog:test_optimization_onboarding with the substantiated runtime, language, test_framework, build_tool (for Java), ci_provider, repo_name, instrumentation (auto by default, manual or junitxml when required), and tests_run_in_containers. When the MCP server is not connected or the tool fails, follow the bundled reference files below for the exact setup steps.Wire the CI workflow and test configuration.
datadog-ci junit upload used --xpath-tag, warn that custom XPath tags are not carried over).tests_run_in_containers is true (docker run or docker compose), forward the required Datadog, runtime, and CI provider environment variables into the container as shown in references/ci-autoinstrumentation.md.DD_API_KEY from the CI secret store (for example ${{ secrets.DD_API_KEY }} in GitHub Actions or $DD_API_KEY in GitLab/Buildkite/CircleCI). In Buildkite, write $DD_API_KEY, never $$DD_API_KEY (which escapes substitution).Run local validation. Run the project's test command or configuration check locally (without exposing real keys in command arguments), fix any errors your edits caused, and run it again until it passes.
Record the highest level you actually reached:
Configuration changed: the CI workflow and any dependency/config files are updated and valid YAML.
Tests ran: the test suite ran locally or in CI and exited 0.
Export accepted: in a local run with DD_CIVISIBILITY_ENABLED=true and DD_CIVISIBILITY_AGENTLESS_ENABLED=true, or in a CI run with DD_API_KEY configured, the tracer or datadog-ci junit upload accepted the test payload without authentication errors.
Datadog shows test events: Datadog:search_datadog_test_events, or the Search test events endpoint (POST /api/v2/ci/tests/events/search) when DD_API_KEY and DD_APP_KEY are set, finds @git.repository.id_v2:"<REPO>" in the last 15 minutes:
SITE=<site from step 1> REPO=<lowercase host/owner/repo>
case "$SITE" in
datadoghq.com) API_HOST=api.datadoghq.com ;;
datadoghq.eu) API_HOST=api.datadoghq.eu ;;
us3.datadoghq.com) API_HOST=api.us3.datadoghq.com ;;
us5.datadoghq.com) API_HOST=api.us5.datadoghq.com ;;
ap1.datadoghq.com) API_HOST=api.ap1.datadoghq.com ;;
ap2.datadoghq.com) API_HOST=api.ap2.datadoghq.com ;;
uk1.datadoghq.com) API_HOST=api.uk1.datadoghq.com ;;
ddog-gov.com) API_HOST=api.ddog-gov.com ;;
*) API_HOST= ;;
esac
if [ -n "$API_HOST" ] && [ -n "$DD_API_KEY" ] && [ -n "$DD_APP_KEY" ]; then
keys() { echo "DD-API-KEY: $DD_API_KEY"; echo "DD-APPLICATION-KEY: $DD_APP_KEY"; }
BODY=$(printf '{"filter":{"query":"@git.repository.id_v2:\\"%s\\"","from":"now-15m","to":"now"},"page":{"limit":5}}' "$REPO")
keys | curl -sS -w ' HTTP %{http_code}' -H @- -H 'Content-Type: application/json' -X POST -d "$BODY" "https://$API_HOST/api/v2/ci/tests/events/search"
fi
A local config edit does not trigger CI by itself. Tell the user to add DD_API_KEY to their CI secrets (if not already set) and push a commit to run the workflow.
The app host is app.datadoghq.com for datadoghq.com, app.datadoghq.eu for datadoghq.eu, app.ddog-gov.com for ddog-gov.com, and the site itself for the others, for example us5.datadoghq.com. URL-encode @git.repository.id_v2:"<REPO>" in the query string. End with this summary:
Test Optimization: configured (<auto | manual | junitxml> for <framework> on <ci_provider>) | already configured | waiting for your choice
Changed: <files, or none>
Secret needed: DD_API_KEY in <CI provider secret store> (create key at https://APP_HOST/organization-settings/api-keys)
Evidence: <highest level reached>; not checked: <levels and the step left>
View: https://APP_HOST/ci/test/runs?query=%40git.repository.id_v2%3A%22<URL_ENCODED_REPO>%22
Revert the CI workflow edits and any tracer devDependency added during this run.
| Mistake | Symptom | Fix |
|---|---|---|
Using datadog/test-optimization-action in GitHub Actions | Workflow fails because that action does not exist | Use datadog/test-visibility-github-action@v3 with api_key |
Omitting NODE_OPTIONS on the GitHub Actions test step for JS/TS | Action runs, but 0 test spans are collected | Add NODE_OPTIONS: -r ${{ env.DD_TRACE_PACKAGE }} (plus --import ${{ env.DD_TRACE_ESM_IMPORT }} for Vitest) |
Setting NODE_OPTIONS (-r dd-trace/ci/init) or RUBYOPT (-rdatadog/ci/auto_instrument) in the env: of a step that also installs dependencies | npm or bundle fails on a clean checkout, because the preloaded library is not installed yet | Export the variable on a line after the install command, or prefix only the test command |
Running tests in docker run without -e flags | Container runs tests without Datadog or CI git metadata | Forward Datadog, runtime, and CI provider env vars into the container; use manual setup for prebuilt images |
Writing $$DD_API_KEY in Buildkite env: | Buildkite escapes $$ to a literal string, causing 403 auth failure | Write $DD_API_KEY |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub datadog-labs/agent-skills --plugin agent-skills78 skills in this plugin
/agent-observability-auto-experimentRun an iterative code-improvement hill-climb against real Datadog LLM-Obs data, locally, with Claude Code as the agent. Establishes a baseline eval, makes one focused change, re-scores both splits with the same harness, keeps the change when held-out test improves without overfitting val (labeling within-noise gains tentative), and repeats. This is the skill published as "Autoresearch" in Datadog Agent Observability. Use when the user says "run an auto experiment", "run autoresearch", "hill-climb this code", "iteratively improve X and measure the delta", "optimize this code/agent/pipeline/prompt against my traces", "auto-optimize against LLM-Obs", or wants the local equivalent of the auto_experiments worker. Works from an ml_app, a dataset_id, an annotation_queue_id (a queue of human-labelled interactions), a list of trace_ids, or (by exception) a local dataset file. The corpus and its val/test splits live in Datadog LLM-Obs Datasets, created once per run with a timestamp in their names./agent-observability-build-eval-from-annotationsFit a Datadog LLM-Obs evaluator to human labels. Takes an annotation queue, works out where in the trace the labelled property actually lives, drafts an LLM-judge that predicts the human label, scores that judge against the already-labelled rows with a metric agreed with the user, then hill-climbs it — inspect the errors, make one focused change, re-score, keep it only if it beats the best — for a bounded number of iterations, and finally publishes the winner to Datadog as a DISABLED evaluator (not a Datadog draft — a real evaluator with `enabled: false`). Use when the user says "build an eval from my annotations", "build an evaluator from the annotation queue", "turn my annotations into an evaluator", "learn an evaluator from my labels", "fit a judge to the annotation queue", "auto-label", "auto labelling", "automate this annotation queue", "scale up my human labels", or wants the rest of a queue graded the way the humans graded the first rows. Needs an annotation queue with at least two classes present in the human labels (e.g. one true and one false for a boolean)./agent-observability-eval-bootstrapBootstrap evaluators from production traces — by default propose online LLM-judge evaluators and, after you confirm, create them in Datadog as disabled drafts (never auto-enabled); on request emit Python SDK code or a framework-agnostic JSON spec instead. Use when user says "bootstrap evaluators", "generate evaluators", "create evals from traces", "eval bootstrap", "write evaluators", "build eval suite", "publish evaluators", or wants to generate BaseEvaluator/LLMJudge code or online judge configs from production LLM trace data. Works with ml_app and optional RCA report or failure hypothesis./agent-observability-eval-pipelineEnd-to-end Agent Observability pipeline for an instrumented ml_app — classify production traces, root-cause failures, bootstrap evaluators, then (optionally) sample + publish a dataset, generate + run an experiment, and analyze results. Six narrated phases with a standardized banner and a "continue" checkpoint between each. Pure orchestration over the agent-observability sub-skills (`agent-observability-session-classify`, `agent-observability-trace-rca`, `agent-observability-eval-bootstrap`, `agent-observability-experiment-bootstrap`, `agent-observability-experiment-analyzer`). Use when user says "run the eval pipeline", "go from traces to evals", "bootstrap evals end to end", "classify then RCA then bootstrap", "build an eval set from scratch", "onboard me to datasets and experiments", "walk me through experiments", "I have an ml_app, now what", "Agent Observability onboarding", "guided experiment setup", "from traces to experiments", or wants a deterministic, narrated tour from production data through evaluators, datasets, and experiments. Stop early with `--stop-after <phase>` to short-circuit at evaluators or dataset, or resume mid-flow with `--start-at <phase>`./agent-observability-experiment-analyzerAnalyze LLM experiment results. Handles single or comparative experiments, exploratory or Q&A modes. Use when user says "analyze experiment", "compare experiments", "analyze against baseline", or provides one or two experiment IDs for analysis./agent-observability-experiment-bootstrapBootstrap a reproducible LLM Observability experiment through the Python ddtrace SDK or the Node dd-trace SDK. Use for experiment, dataset, evaluator, benchmark, regression, or LLM-as-a-judge scaffolding. The legacy Python invocation remains supported.Other plugins' skills for the same job