Skip to content

Clarify annotation instrumentation method matching#18836

Open
trask wants to merge 1 commit into
open-telemetry:mainfrom
trask:cleanup-annotation-constructor-matching
Open

Clarify annotation instrumentation method matching#18836
trask wants to merge 1 commit into
open-telemetry:mainfrom
trask:cleanup-annotation-constructor-matching

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented May 22, 2026

Resolves confusing implementation around constructor annotations, now that #13941 has documented current behavior.

Comment on lines -126 to +114
.hasTotalAttributeCount(0)));
.hasAttributesSatisfyingExactly(
equalTo(stringKey("methodAttribute"), "method"))));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bug fix

@trask trask marked this pull request as ready for review May 22, 2026 19:04
@trask trask requested a review from a team as a code owner May 22, 2026 19:04
Copilot AI review requested due to automatic review settings May 22, 2026 19:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Clarifies how the javaagent’s annotation-based instrumentations select join points by ensuring only true methods (not constructors) are matched for @WithSpan and @AddingSpanAttributes, aligning behavior with the now-documented constructor-annotation handling.

Changes:

  • Restrict @WithSpan and @AddingSpanAttributes matching to isMethod() to avoid constructor matching.
  • Simplify advice application by relying on the method-only matcher (removing redundant .and(isMethod()) at application sites).
  • Update AddingSpanAttributesInstrumentationTest to assert constructor annotations are ignored and to validate the expected attribute is added.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/AddingSpanAttributesInstrumentationTest.java Updates the test to validate constructor annotations are ignored and asserts the expected method attribute behavior.
instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/v1_16/WithSpanInstrumentation.java Narrows the annotation matcher to methods only and removes redundant method filtering when applying advice.
instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/v1_16/AddingSpanAttributesInstrumentation.java Narrows the annotation matcher to methods only to prevent constructor advice application.

@laurit laurit added this to the v2.29.0 milestone May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants