dd-trace-java
AGENTS.md739 starsChanged 6 days agoApache-2.0View on GitHub
Datadog Java APM agent (dd-trace-java): a Java agent that auto-instruments JVM applications at runtime via bytecode manipulation. It ships ~120 integrations (~200 instrumentations) for tracing, profiling, AppSec, IAST, CI Visibility, USM, and LLM Observability. See ARCHITECTURE.md for detailed module descriptions. When working on a topic above, read the linked file first — they are the source of truth maintained by humans.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,774 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository17 other files it gives its agents.
- build-logic/AGENTS.mdAGENTS.md
- buildSrc/AGENTS.mdAGENTS.md
- build-logic/CLAUDE.mdCLAUDE.md
- buildSrc/CLAUDE.mdCLAUDE.md
- .claude/CLAUDE.mdCLAUDE.md
- apm-integrationsSkill
- clarify-java-commentsSkill
- fix-continuation-leakageSkill
- java-lintSkill
- migrate-groovy-to-javaSkill
- migrate-junit-source-to-tabletestSkill
- perf-reviewSkill
- reproduce-ci-flakinessSkill
- resolve-muzzle-ciSkill
- review-groovy-migrationSkill
- techdebtSkill
- fix-continuation-leakageSkill
The file
We split this AGENTS.md into the rules it gives an agent
12 rules. About 0 are common, 4 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 63
Static imports: Prefer static imports over class-qualified calls for call-style helpers, in both test (Assertions.assertEquals, …
- Very specific: line 64
Documentation: Use concise Javadoc comments (/ ...
- Distinctive: line 67
Test frameworks: Always use JUnit 5 for unit tests.
- Very specific: line 69
Forked tests: Use ForkedTest suffix when tests need a separate JVM
- Distinctive: line 76
Write for a human reviewer first: short, plain and skimmable.
- Very specific: line 80
Use tag: no release notes for internal/refactoring changes
- Distinctive: line 87
CI flakiness: use reproduce-ci-flakiness for local reproduction of intermittent timeouts, races, or asynchronous test failures.
- Very specific: line 89
Technical debt: run /techdebt over branch changes before marking a PR ready to catch code duplication, unnecessary complexity, and dead …
- Very specific: line 90
Performance: run /perf-review over branch changes before marking a PR ready (advisory, not a merge gate) — see …
- Very specific: line 100
Every curl that runs in CI (.gitlab-ci.yml, .gitlab/, GitHub Actions, the scripts they call, and the Dockerfiles they build) should:
- Very specific: line 112
Bootstrap: never use java.util.logging.*, java.nio.file.*, or javax.management.* in premain code — see docs/bootstrap_design_guidelines.md.
- Very specific: line 113
Advice: never call a static interface method from advice — can cause a VerifyError — see docs/instrumentation_design_guidelines.md.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Agent context for dd-trace-java
What is this project?
Datadog Java APM agent (dd-trace-java): a Java agent that auto-instruments JVM applications at runtime via bytecode manipulation.
It ships ~120 integrations (~200 instrumentations) for tracing, profiling, AppSec, IAST, CI Visibility, USM, and LLM Observability.
Project layout
See ARCHITECTURE.md for detailed module descriptions.
dd-java-agent/ Main agent (shadow jar, instrumentations, product modules)
dd-trace-api/ Public API & configuration constants
dd-trace-core/ Core tracing engine (spans, propagation, writer)
dd-trace-ot/ Legacy OpenTracing compatibility library
internal-api/ Internal shared API across modules
components/ Shared low-level components (context, environment, json)
products/ Sub-products (feature flagging, metrics)
communication/ HTTP transport to Datadog Agent
remote-config/ Remote configuration support
telemetry/ Agent telemetry
utils/ Shared utility modules (config, time, socket, test, etc.)
dd-smoke-tests/ Smoke tests (real apps + agent)
docs/ Developer documentation (see below)Key documentation (read on demand, don't load upfront)
| Topic | File |
| Architecture & design | ARCHITECTURE.md |
| Building from source | BUILDING.md |
| Contributing & PR guidelines | CONTRIBUTING.md |
| How instrumentations work | docs/how_instrumentations_work.md |
| Adding a new instrumentation | docs/add_new_instrumentation.md |
| Adding a new configuration | docs/add_new_configurations.md |
| Testing guide (6 test types) | docs/how_to_test.md |
| Reproducing timing-sensitive CI flakes | Reproduction guide |
| Writing JUnit tests | docs/how_to_test_with_junit.md |
| Writing a smoke test | docs/how_to_smoke_test.md |
| Working with Gradle | docs/how_to_work_with_gradle.md |
| Bootstrap/premain constraints | docs/bootstrap_design_guidelines.md |
| Instrumentation/advice constraints | docs/instrumentation_design_guidelines.md |
| CI/CD workflows | .github/workflows/README.md |
When working on a topic above, read the linked file first — they are the source of truth maintained by humans.
Build quick reference
./gradlew clean assemble # Build without tests
./gradlew :dd-java-agent:shadowJar # Build agent jar only (dd-java-agent/build/libs/)
./gradlew :path:to:module:test # Run tests for a specific module
./gradlew :path:to:module:test -PtestJvm=11 # Test on a specific JVM version
./gradlew spotlessApply # Auto-format code (google-java-format)
./gradlew spotlessCheck # Verify formattingCode conventions
- Formatting: google-java-format enforced via Spotless. Run
./gradlew spotlessApplybefore committing. - Static imports: Prefer static imports over class-qualified calls for call-style helpers, in both test (Assertions.assertEquals, Mockito.mock) and production code (Collections.emptyList). Wildcard imports disallowed — see CONTRIBUTING.md.
- Documentation: Use concise Javadoc comments (
/** ... */) for class, method, and field documentation. - Instrumentation layout:
dd-java-agent/instrumentation/{framework}/{framework}-{minVersion}/ - Instrumentation pattern: Type matching → Method matching → Advice class (bytecode advice, not AOP)
- Test frameworks: Always use JUnit 5 for unit tests. Only use Groovy / Spock tests for instrumentation and smoke tests.
- Parameterized tests: Prefer
@TableTestfor multi-column literal data, with named scenarios and aligned columns. Prefer a simple@TypeConverterover switching to@MethodSourcewhen it can turn table values into the required arguments. Use@MethodSourcefor cases requiring complex object construction, builders, or mocks. See the JUnit testing guide. - Forked tests: Use
ForkedTestsuffix when tests need a separate JVM - Flaky tests: Annotate with
@Flaky— they are skipped in CI by default
PR conventions
- Title: imperative verb sentence describing user-visible change (e.g. "Fix span sampling rule parsing")
- Description: follow the section guidance in the PR template. Write for a human reviewer first: short, plain and skimmable. Explain the intent and rationale of the change, not its content: the diff already shows the code, so don't walk through it file by file or list the classes and methods touched.
- Size: keep PRs small (under 1000 added lines), split larger changes into stacked PRs.
- Labels: always add
tag: ai generatedand at least onecomp:orinst:label + onetype:label - Use
tag: no release notesfor internal/refactoring changes - Open as draft first, convert to ready when reviewable
- Dependency changes: when adding, updating, or removing dependencies, regenerate all affected
gradle.lockfilefiles and include them in the same PR. See lockfile updates.
Review Guidelines
- CI flakiness: use reproduce-ci-flakiness for local reproduction of intermittent timeouts, races, or asynchronous test failures. Match the CI task/JDK first, then compare bounded reruns with
-Xintand reduced JVM-visible CPUs. See the testing guide for commands and CPU-limit distinctions. - Technical debt: run
/techdebtover branch changes before marking a PR ready to catch code duplication, unnecessary complexity, and dead code (refactor-only, never changes behavior) — see .agents/skills/techdebt/SKILL.md. - Performance: run
/perf-reviewover branch changes before marking a PR ready (advisory, not a merge gate) — see .agents/skills/perf-review/SKILL.md.
Core performance rules
These rules are strict for shipped runtime code in dd-trace-core/src/main/ and internal-api/src/main/. Elsewhere, including those modules' tests, benchmarks and build files, treat them as advice.
- Measure performance claims. A PR that claims to be faster or to allocate less must include JMH before/after results from the same machine, JDK, JVM flags and benchmark settings, with time and allocation (
-Pjmh.profilers=gc). Without them, reviewers should flag the claim as unmeasured and the author should either add numbers or drop the claim.
CI scripts
Every curl that runs in CI (.gitlab-ci.yml, .gitlab/, GitHub Actions, the scripts they call, and the Dockerfiles they build) should:
- Fail on HTTP errors: pass
-f/--fail. Without it, a 4xx/5xx exits 0 and the error page is used as if it were the real response (e.g. piped intobashorjq). - Retry transient errors: pass
--retry 5 --retry-delay 2(add--retry-connrefusedfor remote endpoints). - Propagate the failure: the job must stop when curl fails. Never pipe
curlstraight intobash/sh: download to a file with-f, then run it.
Example: curl -fsSL --retry 5 --retry-delay 2 --retry-connrefused -o out.tar.gz "$url"
Exception: a script that checks the HTTP status itself (-w "%{http_code}", e.g. .gitlab/check_test_agent_results.sh) may skip --fail, but still needs --retry.
Critical constraints
- Bootstrap: never use
java.util.logging.*,java.nio.file.*, orjavax.management.*inpremaincode — see docs/bootstrap_design_guidelines.md. - Advice: never call a static interface method from advice — can cause a
VerifyError— see docs/instrumentation_design_guidelines.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

