Class Telemetry
OpenTelemetry tracing for the app: every network request is a span, and carries W3C trace context to the server it reaches, so the app's request and the backend's handling of it are one trace.
Usually installed by the build rather than by hand -- put
@OpenTelemetry on the main class and the generated bootstrap calls
install(TelemetryConfig) before the app starts:
@OpenTelemetry(relay = "https://api.example.com", serviceName = "shop-app")
public class ShopApp extends Lifecycle { ... }
Every ConnectionRequest is covered, which is every REST, gRPC-Web and GraphQL
client the build generates. To group the requests a user action causes, time
the action:
Telemetry.run("checkout", () -> cart.submit());
Spans are batched and exported with OTLP/HTTP -- through the app's own backend
by default, which keeps the collector's credentials out of the app (see
TelemetryConfig).
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidflush()Exports what is buffered now, rather than at the next interval.static TelemetrySpanThe spanrun(String, Runnable)made current on this thread, or null.static voidinstall(TelemetryConfig config) Installs telemetry, replacing any earlier installation.static booleanWhether telemetry is installed.static voidRunsworkinside a new span, which is current while it runs: requests queued inside it become its children.static TelemetrySpanA new span, a child of the current one.static voidStops recording, exports what is buffered, and removes the network hook.
-
Method Details
-
install
Installs telemetry, replacing any earlier installation.
Safe to call before
Display.init, which is where the generated bootstrap calls it: nothing that needs the platform -- not even the secure random source the ids come from -- is touched until the first span.Parameters
config: where and how to export; a configuration with no endpoint installs nothing
-
uninstall
public static void uninstall()Stops recording, exports what is buffered, and removes the network hook. -
isInstalled
public static boolean isInstalled()Whether telemetry is installed. -
startSpan
A new span, a child of the current one. It is not made current; the caller must end it. Never null -- with telemetry off it records nothing.
Parameters
name: what the span times
-
run
-
getCurrentSpan
The spanrun(String, Runnable)made current on this thread, or null. -
flush
public static void flush()Exports what is buffered now, rather than at the next interval. Call it when the app is paused: a span still in memory when the process is reclaimed is lost.
-