Skip to content

Commit e5018e8

Browse files
committed
Merge remote-tracking branch 'upstream/main' into rename-common-modules
2 parents 609d3b1 + 55060dd commit e5018e8

350 files changed

Lines changed: 1679 additions & 1306 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.fossa.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ targets:
420420
target: ':instrumentation:cassandra:cassandra-4.4:library'
421421
- type: gradle
422422
path: ./
423-
target: ':instrumentation:clickhouse:clickhouse-client-common:javaagent'
423+
target: ':instrumentation:clickhouse:clickhouse-client-common-0.5:javaagent'
424424
- type: gradle
425425
path: ./
426426
target: ':instrumentation:clickhouse:clickhouse-client-v1-0.5:javaagent'
@@ -1131,7 +1131,7 @@ targets:
11311131
target: ':instrumentation:play:play-ws:play-ws-2.1:javaagent'
11321132
- type: gradle
11331133
path: ./
1134-
target: ':instrumentation:play:play-ws:play-ws-common:javaagent'
1134+
target: ':instrumentation:play:play-ws:play-ws-common-1.0:javaagent'
11351135
- type: gradle
11361136
path: ./
11371137
target: ':instrumentation:reactor:reactor-netty:reactor-netty-0.9:javaagent'

.github/agents/knowledge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Load only files relevant to the current scope to reduce noise and avoid over-con
1515
| `gradle-conventions.md` | `build.gradle.kts` or `settings.gradle.kts` changes, custom test task registration or wiring |
1616
| `javaagent-advice-patterns.md` | ByteBuddy `@Advice` class or advice-method changes |
1717
| `javaagent-module-patterns.md` | `InstrumentationModule`, `TypeInstrumentation`, `VirtualField`, `CallDepth` |
18-
| `javaagent-singletons-patterns.md` | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields |
18+
| `javaagent-singletons-patterns.md` | `*Singletons`, `*SpanNaming`, and similar holder classes; singleton accessors; callers of singleton accessors/fields |
1919
| `library-patterns.md` | Library instrumentation telemetry, builder, getter, or setter pattern changes |
2020
| `module-naming.md` | New or renamed modules or packages; settings includes |
2121
| `testing-general-patterns.md` | Test files in scope — assertion style, test method signatures and throws clauses, resource cleanup patterns, attribute assertion patterns, `satisfies()` lambda usage |

.github/agents/knowledge/general-rules.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ When a "Knowledge File" is listed, load it from `knowledge/` before reviewing th
2121
| Naming | Module/package naming | New or renamed modules/packages | `module-naming.md` |
2222
| Javaagent | Advice patterns | `@Advice` classes | `javaagent-advice-patterns.md` |
2323
| Javaagent | Module structure patterns | `InstrumentationModule`, `TypeInstrumentation` | `javaagent-module-patterns.md` |
24-
| Javaagent | Singletons patterns | `*Singletons` holder classes, singleton accessors, callers of singleton accessors/fields | `javaagent-singletons-patterns.md` |
24+
| Javaagent | Singletons patterns | `*Singletons`, `*SpanNaming`, and similar holder classes; singleton accessors; callers of singleton accessors/fields | `javaagent-singletons-patterns.md` |
2525
| Javaagent | Incorrect `classLoaderMatcher()` | `classLoaderMatcher()` override that is redundant (muzzle already handles it) or missing when needed (muzzle cannot distinguish version range) | `javaagent-module-patterns.md` |
2626
| Semconv | Library vs javaagent semconv constant usage | Semconv constants/assertions ||
2727
| Semconv | Dual semconv testing | `SemconvStability`, `maybeStable`, semconv Gradle tasks | `testing-semconv-stability.md` |
@@ -105,7 +105,8 @@ Reason about visibility from "what does the advice method directly reference?".
105105
## [Style] `@SuppressWarnings` Usage
106106

107107
- Place `@SuppressWarnings` on the single member that needs it, or on the class when two
108-
or more members in the class need the same suppression.
108+
or more members in the class need the same suppression. Do not move an existing
109+
suppression from a member to the class unless multiple members need it.
109110
- **Do not add `@SuppressWarnings("deprecation")` unless the build fails without it.**
110111
The project disables javac's `-Xlint:deprecation` globally and uses a custom Error Prone
111112
check (`OtelDeprecatedApiUsage`) instead. Only add the annotation when it is actually

.github/agents/knowledge/gradle-conventions.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ usesService(gradle.sharedServices.registrations["testcontainersBuildService"].se
199199
```
200200

201201
Place the declaration in `withType<Test>().configureEach` when **all** test tasks in the
202-
module use Testcontainers. Otherwise place it on **only** the specific task(s) that do.
202+
module use Testcontainers **and** the module has multiple test tasks. When the module has
203+
only a single test task, put the declaration directly inside `tasks.test { ... }` — do not
204+
introduce a `withType<Test>().configureEach` block just for `usesService`. Otherwise place
205+
it on **only** the specific task(s) that use Testcontainers.
203206

204207
**Do not over-apply.** Adding `usesService` to a task that does not use Testcontainers
205208
unnecessarily throttles it against the 2-slot concurrency limit. A module may have some
@@ -215,9 +218,10 @@ because the dependency may only be used by some suites in the module.
215218

216219
## Prefer `withType<Test>().configureEach` (ONLY when multiple test tasks exist)
217220

218-
When a module has custom test tasks (e.g., `testStableSemconv`), system properties and JVM
219-
args that apply to **all** test tasks should be set once in a `withType<Test>().configureEach`
220-
block, not repeated on each individual task.
221+
When a module has custom test tasks (e.g., `testStableSemconv`), shared configuration
222+
(system properties, JVM args, `usesService` declarations, etc.) that applies to **all**
223+
test tasks should be set once in a `withType<Test>().configureEach` block, not repeated
224+
on each individual task.
221225

222226
If a property or JVM arg is moved into `withType<Test>().configureEach`, remove any now-redundant
223227
copies from individual tasks unless a task intentionally overrides the shared value.

.github/agents/knowledge/javaagent-singletons-patterns.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
## Quick Reference
44

5-
- Use when: reviewing `*Singletons` holder classes and their callers
5+
- Use when: reviewing `*Singletons`, `*SpanNaming`, and similar holder classes and their callers
66
- Review focus: field/accessor naming, eager initialization, singleton accessor call sites
77

88
Javaagent modules keep shared `Instrumenter` instances and related collaborators in a dedicated
9-
`Singletons` holder class such as `MyLibrarySingletons`.
9+
`Singletons` holder class such as `MyLibrarySingletons`. Some modules also use focused helper
10+
holders such as `*ServerSpanNaming` for shared span-name or route-name collaborators; apply the
11+
same accessor and call-site rules when these classes expose stored singleton fields.
1012

1113
## Rules
1214

@@ -18,8 +20,10 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
1820
- For exported collaborators, keep the field `private`, use a lower camel case field name, and
1921
give the accessor method the exact same name as the field. Do not prefix these accessors with
2022
`get`. This rule applies only to zero-arg methods that directly return a stored singleton
21-
field; methods that take arguments or compute a value are not singleton accessors and keep
22-
their normal names (including `get*` when appropriate).
23+
field. It applies regardless of whether the holder class is named `*Singletons`,
24+
`*ServerSpanNaming`, or another focused holder name. Methods that take arguments or compute a
25+
value are not singleton accessors and keep their normal names (including `get*` when
26+
appropriate).
2327
- `instrumenter` -> `instrumenter()`
2428
- `helper` -> `helper()`
2529
- `setter` -> `setter()`
@@ -32,7 +36,9 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
3236
- `RESPONSE_STATUS` stays `RESPONSE_STATUS`
3337
- Callers should static import only exported singleton accessors and uppercase constant-like
3438
fields, and use those members unqualified: accessors for lower camel collaborators, fields for
35-
uppercase constant-like members.
39+
uppercase constant-like members. This includes route/span naming accessors such as
40+
`serverSpanName()` when they simply return a stored `HttpServerRouteGetter` or similar
41+
collaborator.
3642
- Keep verb-named helper methods as verbs when they perform work instead of returning a stored
3743
field. These methods are not singleton accessors and should not be static imported under this
3844
rule.

.github/agents/knowledge/testing-general-patterns.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
`hasAttributesSatisfyingExactly(...)` in the same assertion chain, because the exact
8484
variant already validates the total attribute count. Remove the `hasTotalAttributeCount`
8585
call.
86+
- These rules apply to **span** attribute assertions only. Metric point assertions are
87+
different: metric point assertions do not have a `hasTotalAttributeCount(...)` method, so
88+
the span guidance about preferring `hasTotalAttributeCount(0)` for zero-attribute checks
89+
does not apply. For metric points, used `point.hasAttributes(Attributes.empty())` — it
90+
reads more clearly than the no-arg `hasAttributesSatisfyingExactly()` form.
8691
- For non-semconv attribute keys in `equalTo(...)`, use inline `AttributeKey` factory
8792
methods — `longKey("name")`, `stringKey("name")`, etc. — directly in the assertion.
8893
Do **not** extract them into class-level `private static final AttributeKey<T>` constants.
@@ -92,6 +97,20 @@
9297
`equalTo(AttributeKey<Long>, int)` overload, so `equalTo(longKey("iteration"), iteration)` is
9398
preferred over `equalTo(longKey("iteration"), (long) iteration)`.
9499

100+
## Metric Assertions
101+
102+
- Prefer `InstrumentationExtension.waitAndAssertMetrics(...)` for metric assertions. It waits
103+
until the supplied assertion passes, so fixed sleeps such as `Thread.sleep(100)`
104+
usually unnecessary and make tests slower and more fragile.
105+
- `DbConnectionPoolMetricsAssertions.assertConnectionPoolEmitsMetrics()` already uses
106+
`waitAndAssertMetrics(...)` for each expected pool metric. Keep the pool state being asserted
107+
valid until this method returns; for example, if the assertion expects a `used` connection point,
108+
keep the borrowed connection open until after the assertion.
109+
- After removing a metric-producing source or unregistering an observable callback, call
110+
`testing().clearData()` and then use `waitAndAssertMetrics(..., AbstractIterableAssert::isEmpty)`
111+
for absence checks. Do not add an exporter-interval sleep before or after `clearData()` solely to
112+
wait for metrics; the test runners force-flush metrics when reading them.
113+
95114
## Attribute Assertion `satisfies()` Lambda Parameters
96115

97116
**Attribute-assertion `satisfies()` lambda parameters are `AbstractAssert` instances, not raw

.github/agents/pr-review.agent.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
description: "Review a PR in opentelemetry-java-instrumentation and post a pending GitHub review with inline comments and code suggestions. The review stays as a draft until the caller submits it."
3+
tools: [read, edit, execute, search]
4+
---
5+
6+
You are a code review agent for the `opentelemetry-java-instrumentation` repository.
7+
8+
Primary responsibilities:
9+
10+
- Review PR changes against repository standards and the knowledge base.
11+
- Post a **pending** (draft) GitHub review with inline comments and `suggestion` blocks.
12+
- The caller submits the review manually after inspecting it.
13+
14+
Do not stop until all in-scope files are reviewed and the review is posted.
15+
16+
## Knowledge Loading
17+
18+
Always load first:
19+
20+
- `docs/contributing/style-guide.md`
21+
- `.github/agents/knowledge/general-rules.md` — review checklist and core rules
22+
23+
Then load additional knowledge files **only** when their scope trigger fires.
24+
Use the **Knowledge File** column in the checklist table inside `general-rules.md`.
25+
26+
## Review Workflow
27+
28+
### Phase 1: Resolve PR
29+
30+
1. Get current branch:
31+
32+
```
33+
git branch --show-current
34+
```
35+
36+
2. If branch is `main`, stop with:
37+
> "Aborting: cannot review the main branch. Please check out a PR branch first."
38+
39+
3. Resolve PR:
40+
41+
```
42+
gh pr list --head <branch-name> --json number,title,url,headRefOid --jq '.[0]'
43+
```
44+
45+
4. If no PR exists, stop:
46+
> "No open PR found for branch `<branch-name>`. Push the branch and open a PR first."
47+
48+
5. Announce: `Reviewing PR #<number>: <title>`
49+
50+
### Phase 2: Build Diff Scope
51+
52+
1. Get changed file names:
53+
54+
```
55+
gh pr diff <number> --name-only
56+
```
57+
58+
2. Get the full unified diff:
59+
60+
```
61+
gh pr diff <number> --color never
62+
```
63+
64+
3. Parse the diff to build a map of `file → set of changed right-side line numbers`.
65+
66+
4. For each changed file, also parse the diff **hunk boundaries** (the `@@ ... @@`
67+
headers). Record the right-side line ranges that each hunk covers.
68+
A review comment or suggestion can only target lines **inside a diff hunk**.
69+
70+
### Phase 3: Read Files and Load Knowledge
71+
72+
1. Skip non-reviewable files:
73+
- binary files
74+
- files under `licenses/`
75+
2. Read each changed file's full content.
76+
3. Scan file contents to decide which additional knowledge articles to load
77+
(e.g., load `javaagent-advice-patterns.md` when `@Advice` classes are in scope).
78+
79+
### Phase 4: Review
80+
81+
For each file, apply all rules from the loaded knowledge articles.
82+
Only flag issues on lines that were changed in the PR diff.
83+
84+
Do not flag:
85+
86+
- Non-capturing lambdas or method references as unnecessary allocations.
87+
- Patterns explicitly allowed by the style guide or knowledge articles.
88+
89+
For each finding, record:
90+
91+
- `path` — repo-relative file path
92+
- `line` — right-side line number in the current file
93+
- `start_line` — (optional) first line, if the comment spans multiple lines
94+
- `category` — tag like `[Style]`, `[Concurrency]`, `[Javaagent]`, etc.
95+
- `body` — concise comment text
96+
- `suggestion` — (optional) replacement text for a `suggestion` block
97+
98+
### Phase 5: Build and Post Review
99+
100+
#### Comment Format
101+
102+
Each comment body should be concise. When a concrete fix is possible, include a
103+
GitHub suggestion block:
104+
105+
````
106+
<comment text>
107+
108+
```suggestion
109+
<replacement lines>
110+
```
111+
````
112+
113+
The suggestion block replaces the lines from `start_line` (or `line` if single-line)
114+
through `line` inclusive. The replacement text must be the **exact literal content**
115+
that should appear in those lines — no fenced-code markup inside the suggestion.
116+
117+
#### Hunk Validation
118+
119+
Before adding a comment, verify that **all** lines from `start_line` through `line`
120+
fall inside a diff hunk. If any line is outside a hunk:
121+
122+
- Try narrowing the range (e.g., drop to single-line, remove the suggestion).
123+
- If the line cannot be commented on at all, skip it and note it in the summary.
124+
125+
#### Multi-line Suggestion Rules
126+
127+
- `start_line` and `start_side` are required for multi-line comments.
128+
- Both `side` and `start_side` must be `"RIGHT"`.
129+
- The suggestion text replaces the entire `start_line..line` range.
130+
131+
#### Posting
132+
133+
1. Collect all valid comments into a JSON array.
134+
135+
2. Build the review payload:
136+
137+
```json
138+
{
139+
"commit_id": "<head SHA from Phase 1>",
140+
"body": "<summary text>",
141+
"comments": [ ... ]
142+
}
143+
```
144+
145+
Do **not** include an `"event"` field — omitting it creates a PENDING review.
146+
147+
3. Write the JSON to a temp file in the workspace (e.g., `_review-payload.json`).
148+
149+
4. Post the review:
150+
151+
```
152+
gh api repos/{owner}/{repo}/pulls/{number}/reviews --method POST --input _review-payload.json --jq '.id'
153+
```
154+
155+
5. If the API returns a `422` with `"Line could not be resolved"`:
156+
- One or more comments reference lines outside diff hunks.
157+
- Use binary search: split comments into halves and post each half separately to
158+
identify the offending comment(s).
159+
- Fix or drop the offending comments, then retry.
160+
161+
6. Delete the temp file after a successful post.
162+
163+
7. Report the review ID and comment count:
164+
> Posted pending review `<id>` with N comments on PR #<number>.
165+
> Submit it from the GitHub UI or via:
166+
> `gh api repos/{owner}/{repo}/pulls/{number}/reviews/{id}/events --method POST -f event=COMMENT`
167+
168+
## Review Checklist and Core Rules
169+
170+
Load `knowledge/general-rules.md` — it contains the review checklist table and all
171+
core rules that apply to every review.

0 commit comments

Comments
 (0)