This quickstart verifies Trace events on the JVM with dev.trace:trace. It has no dependencies, so it fits Spring Boot, Quarkus, Micronaut or plain Java.
Before you start
You need a secret key (sk_...) from the dashboard's Keys page and a frontend that sends an eventId (see the Web quickstarts). Java 11 or later.
- 1
Add the dependency
<dependency> <groupId>dev.trace</groupId> <artifactId>trace</artifactId> <version>0.1.0</version> </dependency>implementation("dev.trace:trace:0.1.0") - 2
Verify the event
Javaimport dev.trace.Trace; import java.time.Duration; import java.util.Map; Trace trace = new Trace(System.getenv("TRACE_SECRET_KEY"), "https://id.example.com", Duration.ofMillis(1500)); Map<String, Object> event = null; try { event = trace.getEvent(eventId); } catch (Trace.VerifyException e) { log.warn("Trace check skipped: {}", e.code); // fail open } if (event != null) { double score = ((Number) event.get("suspectScore")).doubleValue(); if (score >= 60) return ResponseEntity.status(403).body(Map.of("error", "blocked")); }In Spring, expose
Traceas a@Beanand inject it. The event is aMapwith the same fields as the API response. - 3
Handle errors
VerifyException.codeis one ofinvalid_event_id,timeout,network,unauthorized,not_found,expired,rate_limited,server_errororinvalid_response. Events can be verified for 60 minutes.