Java SDK
Error tracking SDK for Java applications.
Java 11+
Maven
Gradle
Installation
This package is distributed via JitPack.
Step 1: Add JitPack Repository
Maven
Add the JitPack repository to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Gradle
Add the JitPack repository to your build.gradle:
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
Step 2: Add the Dependency
Maven
<dependency>
<groupId>com.github.hymns</groupId>
<artifactId>alertiqo-java</artifactId>
<version>v1.0.0</version>
</dependency>
Gradle
implementation 'com.github.hymns:alertiqo-java:v1.0.0'
Basic Setup
import io.alertiqo.Alertiqo;
import io.alertiqo.AlertiqoConfig;
public class Main {
public static void main(String[] args) {
// Initialize the client
Alertiqo alertiqo = Alertiqo.init(AlertiqoConfig.builder()
.apiKey("your-api-key")
.endpoint("https://alertiqo.com")
.environment("production")
.release("1.0.0")
.build());
// Your application code...
// Shutdown when app exits
alertiqo.shutdown();
}
}
Usage
Capture Exceptions
try {
// Your code that might throw
riskyOperation();
} catch (Exception e) {
Alertiqo.getInstance().captureException(e);
}
// With additional tags
Map<String, String> tags = new HashMap<>();
tags.put("module", "payment");
Alertiqo.getInstance().captureException(e, tags);
Capture Messages
// Simple message
Alertiqo.getInstance().captureMessage("User signed up");
// With level
Alertiqo.getInstance().captureMessage("Payment failed", "warning");
// With tags
Map<String, String> tags = new HashMap<>();
tags.put("userId", "123");
Alertiqo.getInstance().captureMessage("Order completed", "info", tags);
Add Breadcrumbs
// Simple breadcrumb
Alertiqo.getInstance().addBreadcrumb("User clicked checkout", "ui");
// Detailed breadcrumb
Alertiqo.getInstance().addBreadcrumb(Breadcrumb.builder()
.message("API request")
.category("http")
.level("info")
.data("url", "/api/orders")
.data("method", "POST")
.build());
Set User Context
Alertiqo.getInstance().setUser(User.builder()
.id("12345")
.email("[email protected]")
.username("johndoe")
.build());
Set Tags
// Set a single tag
Alertiqo.getInstance().setTag("version", "2.0.0");
// Set multiple tags
Map<String, String> tags = new HashMap<>();
tags.put("region", "us-east");
tags.put("tier", "premium");
Alertiqo.getInstance().setTags(tags);
Spring Boot Integration
Configuration Bean
import io.alertiqo.Alertiqo;
import io.alertiqo.AlertiqoConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AlertiqoConfiguration {
@Value("${alertiqo.api-key}")
private String apiKey;
@Value("${alertiqo.environment:production}")
private String environment;
@Bean
public Alertiqo alertiqo() {
return Alertiqo.init(AlertiqoConfig.builder()
.apiKey(apiKey)
.endpoint("https://alertiqo.com")
.environment(environment)
.build());
}
}
Global Exception Handler
import io.alertiqo.Alertiqo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class GlobalExceptionHandler {
private final Alertiqo alertiqo;
public GlobalExceptionHandler(Alertiqo alertiqo) {
this.alertiqo = alertiqo;
}
@ExceptionHandler(Exception.class)
public void handleException(Exception e) {
alertiqo.captureException(e);
throw e; // Re-throw or handle as needed
}
}
application.properties
alertiqo.api-key=your-api-key
alertiqo.environment=production
Configuration Options
AlertiqoConfig config = AlertiqoConfig.builder()
.apiKey("your-api-key") // Required
.endpoint("https://alertiqo.com") // Optional, default: https://alertiqo.com
.environment("production") // Optional, default: production
.release("1.0.0") // Optional
.sampleRate(1.0) // Optional, 0.0-1.0, default: 1.0
.timeout(5000) // Optional, milliseconds, default: 5000
.debug(false) // Optional, default: false
.tag("app", "my-app") // Optional, add tags
.beforeSend(report -> { // Optional, modify report before sending
// Return null to drop the report
return report;
})
.build();
API Reference
| Method | Description |
|---|---|
init(config) |
Initialize the Alertiqo client |
getInstance() |
Get the current instance |
captureException(throwable, tags?) |
Capture an exception |
captureMessage(message, level?, tags?) |
Capture a message |
addBreadcrumb(breadcrumb) |
Add a breadcrumb |
setUser(user) |
Set user context |
setTag(key, value) |
Set a single tag |
setTags(tags) |
Set multiple tags |
clearBreadcrumbs() |
Clear all breadcrumbs |
shutdown() |
Shutdown and release resources |
Thread Safety
The Alertiqo client is thread-safe. You can safely call methods from multiple threads.
Shutdown
Always shutdown the client when your application exits to ensure all pending reports are sent:
// In your shutdown hook or @PreDestroy method
Alertiqo.getInstance().shutdown();