Skip to content

Commit 1163e7b

Browse files
authored
Code review agent: Add declarative config to metadata (open-telemetry#17871)
1 parent 6ef1880 commit 1163e7b

6 files changed

Lines changed: 170 additions & 2 deletions

File tree

.github/agents/knowledge/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Load only files relevant to the current scope to reduce noise and avoid over-con
1111
| `api-deprecation-policy.md` | Public API removal, rename, or deprecation; stable vs alpha breaking changes |
1212
| `config-property-stability.md` | `otel.instrumentation.*` property add, remove, rename, or deprecation |
1313
| `general-rules.md` | Always — review checklist table and core rules enforced on every review |
14+
| `metadata-yaml-format.md` | `metadata.yaml` changes, declarative config name conversion |
1415
| `gradle-conventions.md` | `build.gradle.kts` or `settings.gradle.kts` changes, custom test task registration or wiring |
1516
| `javaagent-advice-patterns.md` | ByteBuddy `@Advice` class or advice-method changes |
1617
| `javaagent-module-patterns.md` | `InstrumentationModule`, `TypeInstrumentation`, `VirtualField`, `CallDepth` |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ When a "Knowledge File" is listed, load it from `knowledge/` before reviewing th
3030
| Library | TelemetryBuilder/getter/setter patterns | Library instrumentation classes | `library-patterns.md` |
3131
| API | Deprecation and breaking-change policy | Public API changes | `api-deprecation-policy.md` |
3232
| Config | Config property stability/renames/removals | `otel.instrumentation.*` property changes, `DeclarativeConfigUtil` or `ConfigProperties` usage | `config-property-stability.md` |
33+
| Config | metadata.yaml format and declarative_name conversion | `metadata.yaml` changes | `metadata-yaml-format.md` |
3334
| Build | Gradle conventions, muzzle, test tasks, plugins | `build.gradle.kts`, `settings.gradle.kts` | `gradle-conventions.md` |
3435
| Build | `testcontainersBuildService` declaration | Testcontainers dependency without `usesService` | `gradle-conventions.md` |
3536
| Style | Prefer instance creation over singletons for stateless interface impls (except on hot paths or Kotlin `object` declarations) | `TextMapGetter`, `TextMapSetter`, `*AttributesGetter`, `AttributesExtractor`, `SpanNameExtractor`, `HttpServerResponseMutator`, enum/static singletons ||
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# [Config] metadata.yaml Format and Declarative Name Conversion
2+
3+
## Quick Reference
4+
5+
- Use when: reviewing or creating `metadata.yaml` files, converting config names
6+
- Review focus: declarative_name format, examples guidelines, special mappings, config validation
7+
8+
## Entry Structure
9+
10+
Each configuration entry includes:
11+
12+
- `name`: Flat system property (e.g., `otel.instrumentation.grpc.emit-message-events`)
13+
- `declarative_name`: YAML key path (e.g., `java.grpc.emit_message_events`)
14+
- `type`: `boolean`, `string`, `list`, `integer`
15+
- `description`: Human-readable explanation
16+
- `default`: Default value
17+
- `examples` (optional): Only for module-specific configs with non-obvious format
18+
19+
## Special Mappings
20+
21+
Non-standard mappings (see `ConfigPropertiesBackedDeclarativeConfigProperties.java` for latest):
22+
23+
| Flat Property | Declarative YAML Key |
24+
|---------------------------------------------------------------------------------|-------------------------------------------------------------------|
25+
| `otel.instrumentation.http.client.capture-request-headers` | `general.http.client.request_captured_headers` |
26+
| `otel.instrumentation.http.client.capture-response-headers` | `general.http.client.response_captured_headers` |
27+
| `otel.instrumentation.http.server.capture-request-headers` | `general.http.server.request_captured_headers` |
28+
| `otel.instrumentation.http.server.capture-response-headers` | `general.http.server.response_captured_headers` |
29+
| `otel.instrumentation.sanitization.url.experimental.sensitive-query-parameters` | `general.sanitization.url.sensitive_query_parameters/development` |
30+
| `otel.semconv-stability.opt-in` | `general.semconv_stability.opt_in` |
31+
| `otel.instrumentation.http.known-methods` | `java.common.http.known_methods` |
32+
| `otel.instrumentation.http.client.experimental.redact-query-parameters` | `java.common.http.client.redact_query_parameters/development` |
33+
| `otel.instrumentation.http.client.emit-experimental-telemetry` | `java.common.http.client.emit_experimental_telemetry/development` |
34+
| `otel.instrumentation.http.server.emit-experimental-telemetry` | `java.common.http.server.emit_experimental_telemetry/development` |
35+
| `otel.instrumentation.messaging.experimental.receive-telemetry.enabled` | `java.common.messaging.receive_telemetry/development.enabled` |
36+
| `otel.instrumentation.messaging.experimental.capture-headers` | `java.common.messaging.capture_headers/development` |
37+
| `otel.instrumentation.genai.capture-message-content` | `java.common.gen_ai.capture_message_content` |
38+
| `otel.instrumentation.experimental.span-suppression-strategy` | `java.common.span_suppression_strategy/development` |
39+
| `otel.instrumentation.opentelemetry-annotations.exclude-methods` | `java.opentelemetry_extension_annotations.exclude_methods` |
40+
| `otel.experimental.javascript-snippet` | `java.servlet.javascript_snippet/development` |
41+
| `otel.jmx.enabled` | `java.jmx.enabled` |
42+
| `otel.jmx.config` | `java.jmx.config` |
43+
| `otel.jmx.target.system` | `java.jmx.target.system` |
44+
45+
## Standard Conversion
46+
47+
For `otel.instrumentation.*` properties not in SPECIAL_MAPPINGS:
48+
49+
1. Strip `otel.instrumentation.` prefix
50+
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
54+
4. Prepend `java.`
55+
56+
Examples:
57+
58+
| Flat Property | Declarative YAML Key |
59+
|------------------------------------------------------------------------------|-------------------------------------------------------------|
60+
| `otel.instrumentation.grpc.emit-message-events` | `java.grpc.emit_message_events` |
61+
| `otel.instrumentation.grpc.experimental-span-attributes` | `java.grpc.experimental_span_attributes/development` |
62+
| `otel.instrumentation.logback-appender.experimental.capture-code-attributes` | `java.logback_appender.capture_code_attributes/development` |
63+
| `otel.instrumentation.common.experimental.controller-telemetry.enabled` | `java.common.controller_telemetry/development.enabled` |
64+
65+
## Examples Guidelines
66+
67+
Add `examples` only for module-specific configs with non-obvious format (lists, patterns, enums).
68+
69+
**Never add for**: `general.*`, `java.common.*`, or boolean configs.
70+
71+
```yaml
72+
- name: otel.instrumentation.grpc.capture-metadata.client.request
73+
declarative_name: java.grpc.capture_metadata.client.request
74+
type: list
75+
examples:
76+
- "custom-request-header"
77+
- "header1,header2,header3"
78+
```
79+
80+
## Validation Procedure
81+
82+
### 1. Validate experimental markers match
83+
84+
- `/development` in declarative_name ↔ `experimental` in flat name (MUST match both ways)
85+
- WRONG: `otel.instrumentation.servlet.capture-request-parameters` + `java.servlet.capture_request_parameters/development`
86+
- RIGHT: `otel.instrumentation.servlet.experimental.capture-request-parameters` + `java.servlet.capture_request_parameters/development`
87+
88+
### 2. Verify config is used
89+
90+
Search module source for `DeclarativeConfigUtil.getInstrumentationConfig()`, `config.getBoolean()`, etc.
91+
92+
If a module has a dependency on other modules (for example, a "-common" module, check those as well since they may read the config.
93+
94+
### 3. Verify type and default
95+
96+
Match type and default value with actual code usage.
97+
98+
## Automated Test (MANDATORY)
99+
100+
**Run after any metadata.yaml changes:**
101+
102+
```bash
103+
./gradlew :instrumentation-docs:test --tests DeclarativeConfigValidationTest
104+
```
105+
106+
This validates round-trip conversion (flat property → bridge → declarative path) and catches:
107+
108+
- Wrong flat property names (e.g., missing `experimental.`)
109+
- Wrong declarative paths
110+
- Type mismatches
111+
112+
Example failure when flat name is wrong:
113+
114+
```
115+
FAIL in ../instrumentation/liberty/liberty-20.0/metadata.yaml:
116+
flat property: otel.instrumentation.servlet.capture-request-parameters
117+
expected: [item1, item2, item3]
118+
got: null
119+
```
120+
121+
**Test must pass before completion.**
122+
123+
## Validation Outcomes
124+
125+
| Issue | Action |
126+
|------------------------------|-----------------------------------------|
127+
| Config not used | Flag for removal |
128+
| Default/type mismatch | Update metadata.yaml to match code |
129+
| Missing config (in code) | Add to metadata.yaml |
130+
| Experimental marker mismatch | Fix flat and declarative names to agree |
131+
132+
## Output Format
133+
134+
```yaml
135+
- name: otel.instrumentation.grpc.emit-message-events
136+
declarative_name: java.grpc.emit_message_events
137+
type: boolean
138+
description: Determines whether to emit a span event for each message.
139+
default: true
140+
- name: otel.instrumentation.grpc.experimental-span-attributes
141+
declarative_name: java.grpc.experimental_span_attributes/development
142+
type: boolean
143+
description: Enable capture of experimental span attributes.
144+
default: false
145+
```
146+
147+
## Edge Cases
148+
149+
- Properties without `otel.instrumentation.` prefix → check SPECIAL_MAPPINGS
150+
- Already has declarative_name → skip conversion

instrumentation/liberty/liberty-20.0/metadata.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,37 @@ semantic_conventions:
88
- HTTP_SERVER_METRICS
99
configurations:
1010
- name: otel.instrumentation.http.known-methods
11+
declarative_name: java.common.http.known_methods
1112
description: >
1213
Configures the instrumentation to recognize an alternative set of HTTP request methods. All
1314
other methods will be treated as `_OTHER`.
1415
type: list
1516
default: "CONNECT,DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT,TRACE"
1617
- name: otel.instrumentation.http.server.capture-request-headers
18+
declarative_name: general.http.server.request_captured_headers
1719
description: List of HTTP request headers to capture in HTTP server telemetry.
1820
type: list
1921
default: ""
2022
- name: otel.instrumentation.http.server.capture-response-headers
23+
declarative_name: general.http.server.response_captured_headers
2124
description: List of HTTP response headers to capture in HTTP server telemetry.
2225
type: list
2326
default: ""
2427
- name: otel.instrumentation.http.server.emit-experimental-telemetry
28+
declarative_name: java.common.http.server.emit_experimental_telemetry/development
2529
description: >
2630
Enable the capture of experimental HTTP server telemetry. Adds the `http.request.body.size`
2731
and `http.response.body.size` attributes to spans, and records `http.server.request.size` and
2832
`http.server.response.size` metrics.
2933
type: boolean
3034
default: false
3135
- name: otel.instrumentation.servlet.experimental-span-attributes
36+
declarative_name: java.servlet.experimental_span_attributes/development
3237
description: Enables capturing the experimental `servlet.timeout` span attribute.
3338
type: boolean
3439
default: false
35-
- name: otel.instrumentation.servlet.capture-request-parameters
40+
- name: otel.instrumentation.servlet.experimental.capture-request-parameters
41+
declarative_name: java.servlet.capture_request_parameters/development
3642
description: List of request parameter names to capture as span attributes.
3743
type: list
3844
default: ""

instrumentation/liberty/liberty-dispatcher-20.0/metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ semantic_conventions:
88
- HTTP_SERVER_METRICS
99
configurations:
1010
- name: otel.instrumentation.http.known-methods
11+
declarative_name: java.common.http.known_methods
1112
description: >
1213
Configures the instrumentation to recognize an alternative set of HTTP request methods. All
1314
other methods will be treated as `_OTHER`.
1415
type: list
1516
default: "CONNECT,DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT,TRACE"
1617
- name: otel.instrumentation.http.server.capture-request-headers
18+
declarative_name: general.http.server.request_captured_headers
1719
description: List of HTTP request headers to capture in HTTP server telemetry.
1820
type: list
1921
default: ""
2022
- name: otel.instrumentation.http.server.capture-response-headers
23+
declarative_name: general.http.server.response_captured_headers
2124
description: List of HTTP response headers to capture in HTTP server telemetry.
2225
type: list
2326
default: ""
2427
- name: otel.instrumentation.http.server.emit-experimental-telemetry
28+
declarative_name: java.common.http.server.emit_experimental_telemetry/development
2529
description: >
2630
Enable the capture of experimental HTTP server telemetry. Adds the `http.request.body.size`
2731
and `http.response.body.size` attributes to spans, and records `http.server.request.size` and

instrumentation/tomcat/tomcat-7.0/metadata.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,37 @@ features:
88
- HTTP_ROUTE
99
configurations:
1010
- name: otel.instrumentation.http.known-methods
11+
declarative_name: java.common.http.known_methods
1112
description: >
1213
Configures the instrumentation to recognize an alternative set of HTTP request methods. All
1314
other methods will be treated as `_OTHER`.
1415
type: list
1516
default: "CONNECT,DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT,TRACE"
1617
- name: otel.instrumentation.http.server.capture-request-headers
18+
declarative_name: general.http.server.request_captured_headers
1719
description: List of HTTP request headers to capture in HTTP server telemetry.
1820
type: list
1921
default: ""
2022
- name: otel.instrumentation.http.server.capture-response-headers
23+
declarative_name: general.http.server.response_captured_headers
2124
description: List of HTTP response headers to capture in HTTP server telemetry.
2225
type: list
2326
default: ""
2427
- name: otel.instrumentation.http.server.emit-experimental-telemetry
28+
declarative_name: java.common.http.server.emit_experimental_telemetry/development
2529
description: >
2630
Enable the capture of experimental HTTP server telemetry. Adds the `http.request.body.size`
2731
and `http.response.body.size` attributes to spans, and records `http.server.request.body.size`
2832
and `http.server.response.body.size` metrics.
2933
type: boolean
3034
default: false
3135
- name: otel.instrumentation.servlet.experimental-span-attributes
36+
declarative_name: java.servlet.experimental_span_attributes/development
3237
description: Enables capturing the experimental `servlet.timeout` span attribute.
3338
type: boolean
3439
default: false
35-
- name: otel.instrumentation.servlet.capture-request-parameters
40+
- name: otel.instrumentation.servlet.experimental.capture-request-parameters
41+
declarative_name: java.servlet.capture_request_parameters/development
3642
description: List of request parameter names to capture as span attributes.
3743
type: list
3844
default: ""

0 commit comments

Comments
 (0)