public final class Telemetry
- Object
- 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).
Methods
public static void install(TelemetryConfig config) | Installs telemetry, replacing any earlier installation. |
public static void uninstall() | Stops recording, exports what is buffered, and removes the network hook. |
public static boolean isInstalled() | Whether telemetry is installed. |
public static TelemetrySpan startSpan(String name) | A new span, a child of the current one. |
public static void run(String name, Runnable work) | Runs work inside a new span, which is current while it runs: requests queued inside it become its children. |
public static TelemetrySpan getCurrentSpan() | The span run(String, Runnable) made current on this thread, or null. |
public static void flush() | Exports what is buffered now, rather than at the next interval. |
Inherited methods
Method details
install
public static void install(TelemetryConfig config)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
configTelemetryConfig- where and how to export; a configuration with no endpoint installs nothing
uninstall
public static void uninstall()isInstalled
public static boolean isInstalled()startSpan
public static TelemetrySpan startSpan(String name)Parameters
nameString- what the span times
run
public static void run(String name, Runnable work)work inside a new span, which is current while it runs: requests
queued inside it become its children. A RuntimeException is recorded on
the span and rethrown.Parameters
nameString- what the span times
workRunnable- the work
getCurrentSpan
public static TelemetrySpan getCurrentSpan()run(String, Runnable) made current on this thread, or null.flush
public static void flush()