Copied to Clipboard
This pattern scales: you can plug in structured logs, metrics counters, or spans with the same hook mechanism.
OpenTelemetry in the Java Ecosystem
OpenTelemetry is the standard for observability across modern platforms. In Java it provides:
-
Tracing via spans
-
Metrics via meters
-
Logs via instrumentation
You configure it once and export telemetry to a backend like Jaeger , Grafana, or the OpenTelemetry Collector. The key benefit here is portability: you are not locked to a single vendor.
How LangGraph4j Hooks Enable OpenTelemetry
LangGraph4j includes a dedicated module, langgraph4j-opentelemetry, that provides hook implementations ready for tracing node and edge execution. Consider it as a reference implementation about how to integrate OpenTelemetry in LangGraph4j
The module includes:
-
OTELWrapCallTraceHook: creates spans for each node and edge call, adding config/state attributes and start/end events.
-
OTELWrapCallTraceSetParentHook: creates a parent span so node/edge spans are grouped inside a workflow scope.
A minimal integration looks like this:
var otelHook = new OTELWrapCallTraceHook<MyState>(serializer);
var parentHook = OTELWrapCallTraceSetParentHook.<MyState>builder()
.scope("MyWorkflow")
.groupName("stream")
.build();
var workflow = new StateGraph<>(MyState.SCHEMA, serializer)
.addWrapCallNodeHook(otelHook)
.addWrapCallEdgeHook(otelHook)
.addWrapCallNodeHook(parentHook)
.addWrapCallEdgeHook(parentHook)
.addNode( "node1", action1 )
.addNode( "node2", action2 )
.addContitionalEdges( "node2", edgeAction,
EdgeMappings.builder()
.to("node1")
.toEnd()
.build() )
...
.compile();
This keeps node logic clean while producing rich, correlated traces for the entire workflow.
Below an example of output in Jaeger tracing platform
jaeger
Conclusion
Hooks are the foundation for observability in LangGraph4j: they give you structured interception points without affect your main workflow code. OpenTelemetry builds on top of this by standardizing how telemetry is collected and exported in the Java ecosystem.
Combined, they deliver production-grade visibility for complex agent workflows.
Checkout project, try it and let me know your feedback and ... happy AI coding! 👋
References
Originally published at https://bsorrentino.github.io on February 4, 2026.