Java
Send errors and logs from Java, Spring Boot, and JVM applications to Squasher.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Send errors and logs from Java, Spring Boot, and JVM applications to Squasher.
curl -L -o opentelemetry-javaagent.jar \
https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
java -javaagent:opentelemetry-javaagent.jar \
-Dotel.exporter.otlp.endpoint=https://ingest.squasher.ai \
-Dotel.exporter.otlp.headers="x-squasher-key=sq_pk_your_api_key" \
-Dotel.service.name=my-java-service \
-jar your-app.jar
<!-- pom.xml -->
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
</dependency>
# application.yml
otel:
exporter:
otlp:
endpoint: https://ingest.squasher.ai
headers:
x-squasher-key: sq_pk_your_api_key
service:
name: my-spring-app
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Squasher {
private static final String ENDPOINT = "https://ingest.squasher.ai/v1/ingest/YOUR_PROJECT_ID";
private static final String API_KEY = "sq_pk_your_api_key";
private static final HttpClient client = HttpClient.newHttpClient();
public static void captureError(Throwable error, String... tags) {
StringBuilder stack = new StringBuilder();
for (StackTraceElement el : error.getStackTrace()) {
stack.append(" at ").append(el.toString()).append("\n");
}
String json = String.format(
"{\"message\":\"%s\",\"type\":\"%s\",\"level\":\"error\",\"stack\":\"%s\"}",
error.getMessage().replace("\"", "\\\""),
error.getClass().getSimpleName(),
stack.toString().replace("\"", "\\\"").replace("\n", "\\n")
);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(ENDPOINT))
.header("Content-Type", "application/json")
.header("x-squasher-key", API_KEY)
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
}
}
try {
processOrder(order);
} catch (Exception e) {
Squasher.captureError(e);
throw e;
}
For Java, prefer the OpenTelemetry Java agent for framework auto-instrumentation. Keep the Squasher key in runtime configuration, set otel.service.name, verify one uncaught exception or error log, and use direct HTTP only for small custom integrations.