Repository navigation
Instruction audit: Cache repeated reflective accessors by their declaring type - #21582
Open
otelbot[bot] wants to merge 2 commits into
Open
otelbot[bot] wants to merge 2 commits into
otelbot[bot] wants to merge 2 commits into
Conversation
Pull request dashboard statusWaiting on reviewers · refreshed 2026-11-28 18:31 UTC Review the latest changes. Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new accessor cache lacks installed-agent tests covering other resource types, missing getters, and repeated operations, leaving per-class isolation of cached results unverified.
1 open issue
What changed in this PR
This PR reduces repeated reflective lookups across instrumentation and agent tooling by caching accessors according to their declaring type.
Changes:
- Cache fixed API accessors once and use
ClassValuefor generated types. - Cache unavailable optional getters while keeping MongoDB writer settings instance-specific.
- Add regression tests for MongoDB settings isolation and Elasticsearch action names.
| File | Description |
|---|---|
| javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RuntimeFieldBasedImplementationSupplier.java | Caches accessors per generated virtual-field class. |
| instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/v6_6/TwilioExperimentalAttributesExtractor.java | Caches available and missing getters per resource class. |
| instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/client/HttpProtocolVersion.java | Shares protocol accessors by Reactor API type. |
| instrumentation/spring/spring-boot-resources/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/boot/resources/SystemHelper.java | Lazily caches optional ProcessHandle accessors. |
| instrumentation/mongo/mongo-3.1/library/src/test/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoDbAttributesGetterTest.java | Verifies writer settings remain independent. |
| instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/internal/MongoDbAttributesGetter.java | Caches writer-builder methods without sharing settings. |
| instrumentation/hbase/hbase-client-common-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hbase/client/common/v1_0/HbaseClientUtil.java | Caches shaded and unshaded descriptor accessors. |
| instrumentation/elasticsearch/elasticsearch-transport-common-5.0/javaagent/src/unitTests/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/common/v5_0/ElasticsearchTransportAttributesGetterTest.java | Tests action-name reuse and incompatible receivers. |
| instrumentation/elasticsearch/elasticsearch-transport-common-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/common/v5_0/ElasticsearchActionNames.java | Caches the version-appropriate action-name accessor. |
Review effort: Balanced
Comment on lines
+29
to
+32
| private static final ClassValue<Map<String, Method>> getters = | ||
| new ClassValue<Map<String, Method>>() { | ||
| @Override | ||
| protected Map<String, Method> computeValue(Class<?> type) { |
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR fixes a finding from an instruction audit run that checked the following repository rule:
Explanation
Cache reflective accessors used by repeated instrumentation calls instead of rediscovering methods. Fixed API types share accessors across compatible implementations; unrelated generated types use
ClassValuewithout a global class-keyed map. Missing optional methods remain unavailable without repeated probes, while Mongo writer settings remain instance-specific.