Skip to content

Commit f30c934

Browse files
committed
Clarify singleton accessor rule only applies to zero-arg field accessors
1 parent 4018236 commit f30c934

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
1717
`"io.opentelemetry.<module-name>"`.
1818
- For exported collaborators, keep the field `private`, use a lower camel case field name, and
1919
give the accessor method the exact same name as the field. Do not prefix these accessors with
20-
`get`.
20+
`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).
2123
- `instrumenter` -> `instrumenter()`
2224
- `helper` -> `helper()`
2325
- `setter` -> `setter()`
@@ -34,6 +36,9 @@ Javaagent modules keep shared `Instrumenter` instances and related collaborators
3436
- Keep verb-named helper methods as verbs when they perform work instead of returning a stored
3537
field. These methods are not singleton accessors and should not be static imported under this
3638
rule.
39+
- Methods on a `*Singletons` class that take arguments (for example `addressAndPort(client)` or
40+
`getAddressAndPort(client)`) are not singleton accessors. Do not apply the field-style
41+
accessor naming rule to them, and do not flag their `get*` prefix on that basis.
3742

3843
## Preferred Pattern
3944

@@ -103,7 +108,8 @@ class MyInstrumentation implements TypeInstrumentation {
103108
final` field would be clearer and matches the naming guidance, including semantic keys/handles
104109
and immutable value constants.
105110
- Accessor methods named `getInstrumenter()`, `getHelper()`, `getSetter()`, and similar when they
106-
simply return a backing field.
111+
simply return a backing field. Do not flag `get*`-prefixed methods that take arguments or
112+
compute a value rather than returning a stored singleton field.
107113
- Call sites that qualify singleton accessor or uppercase constant-like field usage with the holder
108114
class instead of static importing the accessor or field.
109115
- Static imports of non-accessor helper methods on a `*Singletons` class when the method performs

.github/agents/knowledge/metadata-yaml-format.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ For `otel.instrumentation.*` properties not in SPECIAL_MAPPINGS:
4848

4949
1. Strip `otel.instrumentation.` prefix
5050
2. Replace `-` with `_` (kebab-case → snake_case)
51-
3. Handle `experimental`:
52-
- `experimental.` path segment → remove, add `/development` to next segment
53-
- `experimental-` in name → add `/development` to that segment
51+
3. Handle `experimental` per path segment:
52+
53+
- a segment that is exactly `experimental` is removed, and `/development` is appended to the following segment
54+
- a segment that already contains `experimental` keeps that text in the segment name, and `/development` is appended to that same segment
55+
5456
4. Prepend `java.`
5557

5658
Examples:
@@ -59,6 +61,7 @@ Examples:
5961
|------------------------------------------------------------------------------|-------------------------------------------------------------|
6062
| `otel.instrumentation.grpc.emit-message-events` | `java.grpc.emit_message_events` |
6163
| `otel.instrumentation.grpc.experimental-span-attributes` | `java.grpc.experimental_span_attributes/development` |
64+
| `otel.instrumentation.http.client.emit-experimental-telemetry` | `java.http.client.emit_experimental_telemetry/development` |
6265
| `otel.instrumentation.logback-appender.experimental.capture-code-attributes` | `java.logback_appender.capture_code_attributes/development` |
6366
| `otel.instrumentation.common.experimental.controller-telemetry.enabled` | `java.common.controller_telemetry/development.enabled` |
6467

@@ -81,9 +84,19 @@ Add `examples` only for module-specific configs with non-obvious format (lists,
8184
8285
### 1. Validate experimental markers match
8386
84-
- `/development` in declarative_name ↔ `experimental` in flat name (MUST match both ways)
87+
- `/development` in `declarative_name` means the flat property must be experimental, but there are two valid shapes:
88+
- standalone `experimental` segment before the target segment:
89+
`java.common.controller_telemetry/development.enabled` ↔ `otel.instrumentation.common.experimental.controller-telemetry.enabled`
90+
- `experimental` already embedded in the target segment:
91+
`java.grpc.experimental_span_attributes/development` ↔ `otel.instrumentation.grpc.experimental-span-attributes`
92+
- another embedded example:
93+
`java.http.client.emit_experimental_telemetry/development` ↔ `otel.instrumentation.http.client.emit-experimental-telemetry`
8594
- WRONG: `otel.instrumentation.servlet.capture-request-parameters` + `java.servlet.capture_request_parameters/development`
95+
- WRONG: `otel.instrumentation.grpc.span-attributes` + `java.grpc.experimental_span_attributes/development`
8696
- RIGHT: `otel.instrumentation.servlet.experimental.capture-request-parameters` + `java.servlet.capture_request_parameters/development`
97+
- RIGHT: `otel.instrumentation.grpc.experimental-span-attributes` + `java.grpc.experimental_span_attributes/development`
98+
99+
This matches `translateName()` in `ConfigPropertiesBackedDeclarativeConfigProperties`: when a `/development` segment already contains `experimental`, do not insert an extra `experimental.` path segment in the flat property.
87100

88101
### 2. Verify config is used
89102

0 commit comments

Comments
 (0)