Skip to content

feat: Add support for JFR contextual information#2739

Open
marschall wants to merge 1 commit intoopen-telemetry:mainfrom
marschall:jfr-contextual
Open

feat: Add support for JFR contextual information#2739
marschall wants to merge 1 commit intoopen-telemetry:mainfrom
marschall:jfr-contextual

Conversation

@marschall
Copy link
Copy Markdown

Description:

Feature addition
Annotate the operationName and traceID event fields with contextual so it shows up when using jfr print.

Existing Issue(s):

#2057

Testing:

Existing unit tests extended.

Documentation:

Attribute documentation in readme updated.

Outstanding items:

See discussion in #2057

To avoid repetition in the presentation, it's probably best to annotate traceId only in a top-level event, such as the ScopeEvent or perhaps a new event that is even higher-level. SpanID is likely not that interesting either. If too much is annotated with @contextual, it will be hard for humans to parse.

Copilot AI review requested due to automatic review settings April 4, 2026 13:35
@marschall marschall requested a review from a team as a code owner April 4, 2026 13:35
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 4, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: marschall / name: Philippe Marschall (f883cde)

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

This PR adds support for JFR contextual information by implementing the @Contextual meta-annotation for OpenTelemetry JFR events. This allows lower-level JVM/JDK events (like lock contention) to inherit trace and span context information when using tools like jfr print in JDK 25+. The implementation annotates the operationName field in SpanEvent and the traceId field in ScopeEvent (as a top-level event) to avoid information repetition.

Changes:

  • Creates a @Contextual meta-annotation that mimics JDK 25's annotation without requiring JDK 25 compilation
  • Annotates operationName in SpanEvent and traceId in ScopeEvent with @Contextual
  • Extends unit tests to verify the presence of @Contextual annotations on these fields
  • Updates README documentation to note which fields have the @Contextual annotation

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
jfr-events/src/main/java/io/opentelemetry/contrib/jfrevent/Contextual.java New meta-annotation to support @Contextual for JFR contextual information
jfr-events/src/main/java/io/opentelemetry/contrib/jfrevent/SpanEvent.java Annotates operationName field with @Contextual
jfr-events/src/main/java/io/opentelemetry/contrib/jfrevent/ScopeEvent.java Annotates traceId field with @Contextual
jfr-events/src/test/java/io/opentelemetry/contrib/jfrevent/JfrSpanProcessorTest.java Adds tests to verify @Contextual annotations are present on fields
jfr-events/README.md Updates documentation to indicate which fields are @contextual; contains an incorrect field reference

Comment on lines +81 to +87
assertThat(events)
.extracting(
e ->
e.getFields().stream()
.filter(f -> f.getName().equals("operationName"))
.map(d -> d.getAnnotation(Contextual.class))
.collect(Collectors.toList()))
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

The test assertion only checks that the extracted list is not null, but does not validate that the @Contextual annotation is actually present on the field. The assertion should verify that the annotation is non-null, not just that the list exists. This could allow the test to pass even if the annotation is missing from the field.

Suggested change
assertThat(events)
.extracting(
e ->
e.getFields().stream()
.filter(f -> f.getName().equals("operationName"))
.map(d -> d.getAnnotation(Contextual.class))
.collect(Collectors.toList()))
assertThat(
events.get(0).getFields().stream()
.filter(f -> f.getName().equals("operationName"))
.map(d -> d.getAnnotation(Contextual.class))
.collect(Collectors.toList()))
.singleElement()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants