feat: Add support for JFR contextual information#2739
feat: Add support for JFR contextual information#2739marschall wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
|
|
There was a problem hiding this comment.
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
@Contextualmeta-annotation that mimics JDK 25's annotation without requiring JDK 25 compilation - Annotates
operationNamein SpanEvent andtraceIdin ScopeEvent with@Contextual - Extends unit tests to verify the presence of
@Contextualannotations on these fields - Updates README documentation to note which fields have the
@Contextualannotation
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 |
jfr-events/src/main/java/io/opentelemetry/contrib/jfrevent/Contextual.java
Outdated
Show resolved
Hide resolved
| assertThat(events) | ||
| .extracting( | ||
| e -> | ||
| e.getFields().stream() | ||
| .filter(f -> f.getName().equals("operationName")) | ||
| .map(d -> d.getAnnotation(Contextual.class)) | ||
| .collect(Collectors.toList())) |
There was a problem hiding this comment.
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.
| 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() |
jfr-events/src/test/java/io/opentelemetry/contrib/jfrevent/JfrSpanProcessorTest.java
Outdated
Show resolved
Hide resolved
d152a4f to
f883cde
Compare
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