Java
The Java SDK targets Java 11+ and uses only the JDK — java.net.http for the transport and a hand-rolled JSON writer so you don't pull Jackson or Gson transitively. Installs an uncaught-exception handler at init so the JVM's default thread group's exceptions are captured.
Install
Maven coordinates:
<dependency> <groupId>dev.tinymon</groupId> <artifactId>tinymon</artifactId> <version>0.1.0</version> </dependency>
Gradle:
implementation 'dev.tinymon:tinymon:0.1.0'
Tinymon.init
Call once, early in your main(). The SDK uses a fluent Config builder so adding fields is type-safe.
import dev.tinymon.Tinymon; public class App { public static void main(String[] args) { Tinymon.init(new Tinymon.Config(System.getenv("TINYMON_DSN")) .environment("production") .release("1.0.0") .sampleRate(1.0)); runServer(); } }
Config builder methods
| Method | Type | Description |
|---|---|---|
| Config(dsn) | constructor | Required. Throws if DSN is null or empty. |
| .endpoint(s) | String | Override the ingest URL. Defaults to https://console.tinymon.dev/api/ingest. |
| .environment(s) | String | Free-form tag — production, staging. |
| .release(s) | String | Version string for your app. |
| .sampleRate(d) | double | 0 to 1. Default 1.0. |
| .beforeSend(fn) | UnaryOperator<Map> | Mutate or drop events. Return null to drop. |
Capturing exceptions
try { riskyThing(); } catch (Exception e) { Tinymon.captureException(e); } // Or a plain message: Tinymon.captureMessage("cron job took 28 seconds", "warning");
User & tag context
Tinymon.setUser(Map.of("id", user.getId())); Tinymon.setTag("plan", user.getPlan()); Tinymon.setTag("tenant_id", tenant.getId().toString());
Thread safety. The scope is process-global. For per-request user context in a web app, set the user at request entry and clear it at request exit.
Breadcrumbs
Tinymon.addBreadcrumb(Map.of( "timestamp", System.currentTimeMillis() / 1000.0, "category", "http", "message", "POST /api/orders → 500", "level", "error" ));
Spring Boot
Initialise in @PostConstruct on a @Configuration bean, and add a @ControllerAdvice that captures exceptions before returning a response:
@Configuration public class TinymonConfig { @Value("${tinymon.dsn}") private String dsn; @Value("${tinymon.environment}") private String environment; @PostConstruct public void init() { Tinymon.init(new Tinymon.Config(dsn).environment(environment)); } } @ControllerAdvice public class TinymonAdvice { @ExceptionHandler(Exception.class) public ResponseEntity<String> on(Exception e) { Tinymon.captureException(e); return ResponseEntity.status(500).body("Internal Server Error"); } }