-
Enhancement
-
Resolution: Unresolved
-
P3
-
None
-
None
-
None
JDK 25 introduces the concept of contextual information that allows lower-level events in the JVM/JDK, such as lock contention and exceptions, to inherit information in contextual fields from higher-level events, such as the trace or span IDs.
The jfr tool already has support for this. It might look something like this if operationName and traceId in a ScopeEvent and SpanEvent are annotated with @Contextual:
$ jfr print --events jdk.JavaMonitorEnter recording.jfr jdk.JavaMonitorEnter { Context: Scope.traceId = "4bf92f3577b34da6a3ce929d0e0e4736" Context: Span.operationName ="HTTP GET /api/orders" Context: Span.operationName ="Service: order service - getOrders" Context: Span.operationName ="Service: payment service - authorizePayment" Context: Span.operationName ="Service: bank-gateway - requestAuthorization" startTime = 17:51:29.038 (2025-02-07) duration = 50.56 ms monitorClass = java.util.ArrayDeque (classLoader = bootstrap) previousOwner = "Order Thread" (javaThreadId = 56209, virtual = true) address = 0x60000232ECB0 eventThread = "Order Thread" (javaThreadId = 52613, virtual = true) ... }
JMC should add similar capabilities. I can think of several places where it could be visualized:
- Add the contextual information to the Properties View where a single event is inspected.
- Create a "Contextual" page, where there is a combo box at the top where the user can choose the context, for example, "Scope: Trace ID" and "Span: Operation Name". After the selection, the top table displays a histogram keyed by the context value, for example, "4bf92f3577b34da6a3ce929d0e0e4736" if it is the traceId or "HTTP GET /api/orders" if it is the operationName. The user selects a context value in the table, and the table below displays all the events carrying the context. That is, all events happening in the same thread from the beginning to the end of the event with a field annotated with @Contextual with that particular contextual value. It could be an HTTP request URL or a transaction, like ECID.
- Extend the tooltip in the Threads page to display the context when looking at an event, for example, JavaMonitorEvent.
- Extend other pages that display events with contextual data.
For more information about the contextual annotation, see:
https://download.java.net/java/early_access/jdk25/docs/api/jdk.jfr/jdk/jfr/Contextual.html