Skip to content
Documentation

Java SDK

The SDK has no runtime dependencies and never lets a monitoring problem break the integration it reports on.

Report the executions of your integrations and background jobs to IntegrationGuard from Java code. The SDK needs Java 21 or later and has no dependencies: it uses java.net.http for HTTP and System.Logger for its few log lines. Applications on older Java versions can report through the REST API instead.

Before you start

  1. Create the integration or job in the console. Open Integrations (or Background jobs), choose New, and give it a key such as invoice-sync. The key is what your code reports under. Set the schedule you expect (every 15 minutes, a cron expression, or none), the grace period, and optionally the expected duration, a timeout and a threshold for failed records.
  2. Create an API key under Settings → API keys with the Ingest scope. Limit it to the project of the integration when you can: a project key cannot report anywhere else. Keep the key out of source code, for example in an environment variable.

Add the SDK

Until it is published to a Maven repository, build it from this repository (the SDK has no dependencies, so the jar works on its own):

cd backend
mvn -pl sdk-java -am install      # installs com.integrationguard:integrationguard-sdk into ~/.m2
<dependency>
    <groupId>com.integrationguard</groupId>
    <artifactId>integrationguard-sdk</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle: implementation("com.integrationguard:integrationguard-sdk:1.0.0") with mavenLocal().

Report an integration

IntegrationGuardClient client = IntegrationGuardClient.builder()
        .baseUrl("https://monitoring.example.com")
        .apiKey(System.getenv("INTEGRATIONGUARD_API_KEY"))
        .build();

IntegrationExecution execution = client.startExecution("invoice-sync");

try {
    // Existing integration logic.

    execution.recordProcessed(5000);
    execution.recordSuccessful(4850);
    execution.recordFailed(150);

    execution.complete();

} catch (Exception e) {
    execution.fail(e);
}

startExecution reports the execution as running; complete, fail, cancel and timedOut report how it ended. The counts are added up (call recordProcessed once per batch if you like) and sent as totals. IntegrationGuard shows the duration, the records, the error with its stack trace, and the last success and failure, and raises alerts according to your alert rules.

Create one client per application and share it; it is immutable and thread-safe. Close it when the application stops (client.close()), or use it in try-with-resources.

Let the SDK finish the execution

int imported = client.track("invoice-sync", execution -> {
    int count = importInvoices();
    execution.recordProcessed(count);
    return count;
});

track completes the execution when the work returns and reports the failure (then rethrows) when it throws. An execution used in try-with-resources is reported as failed if it is closed without an outcome:

try (IntegrationExecution execution = client.startExecution("invoice-sync")) {
    syncInvoices(execution);
    execution.complete();
}

Metadata and your own execution ids

IntegrationExecution execution = client.startExecution("invoice-sync", ExecutionOptions.builder()
        .executionId("invoices-" + LocalDate.now())   // reports with the same id update the same execution
        .metadata("batch", "B-1042")
        .build());
execution.putMetadata("file", "invoices-1042.csv");
execution.putMetadata("dryRun", false);

Metadata entries are shown with the execution: up to 50, with names of letters, digits and _ . : -, and values that are text (up to 500 characters), numbers, booleans or null. Without an execution id the SDK generates a random one. Choose your own when a retry of the whole run (after a crash, for example) should update the same execution.

Long runs can send their progress: execution.reportProgress() sends the current counts while it is running.

Report a background job

Jobs work the same way with startJobExecution, trackJob, and heartbeats.

// A Spring Boot scheduled job
@Scheduled(cron = "0 15 1 * * *")
public void closeLedger() throws Exception {
    client.trackJob("ledger-close", execution -> {
        int entries = ledger.close();
        execution.recordProcessed(entries);
        return null;
    });
}

When a job only needs to prove it is alive, send a heartbeat at the end of each run:

client.heartbeat("cache-warmup");
client.heartbeat("cache-warmup", Duration.ofMillis(1250), Map.of("host", "app01"));

Give the job an interval schedule in the console (for example every 5 minutes with a grace period of 2 minutes). IntegrationGuard reports a missing heartbeat when none arrives in time.

What IntegrationGuard detects

Situation Status Alert rule condition
The execution failed, or reported itself timed out Down Execution failed or timed out
A running execution sent no result within its timeout (the definition's, or 24 hours) Down Execution failed or timed out
No execution started (or no heartbeat arrived) by the scheduled time plus the grace period Down Scheduled execution missed
It ran longer than the expected duration Degraded Execution slow or with failed records
The share of failed records reached the threshold Degraded Execution slow or with failed records
An execution is still running past the expected duration Degraded Execution slow or with failed records

An execution that starts after its slot was reported missed is recorded as late (delayed). One alert per rule stays open while the condition holds, and you get a recovery notification when the next execution succeeds.

Errors, retries and timeouts

Reporting is synchronous, with timeouts on every request (5 s to connect and 10 s per response by default) and up to 3 retries after network errors, timeouts and temporary server errors (HTTP 408, 429, 500, 502, 503, 504). The waits between retries are random and grow from 250 ms up to 5 s; a Retry-After header is honoured within that limit. Retries are safe because every report names its execution: repeating one never records anything twice.

By default, reporting never throws into your code. A report that cannot be delivered is logged as a warning (without the API key) and the method returns false; the execution still finishes locally, and its final report carries everything, so an execution whose start was lost is recorded when it ends. To fail loudly instead:

IntegrationGuardClient client = IntegrationGuardClient.builder()
        .baseUrl("https://monitoring.example.com")
        .apiKey(apiKey)
        .failOnError(true)          // throw IntegrationGuardException when a report cannot be delivered
        .build();

Check the address and the key at start-up with client.ping(), which always throws on failure and tells you the key's organization, project and scopes.

The SDK sends no wall-clock times: IntegrationGuard records the start and end when the reports arrive, and the SDK measures durations with the JVM's monotonic clock. Clock differences between your servers and IntegrationGuard do not distort the results.

Configuration

Builder method Default Purpose
baseUrl(String) required Address of the IntegrationGuard console. https is required except for localhost.
apiKey(String) required API key with the ingest scope.
connectTimeout(Duration) 5 s Waiting for a connection.
requestTimeout(Duration) 10 s Waiting for each response.
maxRetries(int) 3 Retries after temporary failures (0–10).
backoff(Duration, Duration) 250 ms, 5 s Initial and longest wait between retries.
failOnError(boolean) false Throw instead of logging when a report cannot be delivered.
sendStackTraces(boolean) true Send the stack trace with fail(Throwable).
allowPlainHttp(boolean) false Allow http for hosts other than localhost (trusted networks only).
enabled(boolean) true false sends nothing, for tests and local development.
httpClient(HttpClient) own client Use your own HttpClient, for example with a proxy or a custom trust store.

Log output goes through System.Logger under the name com.integrationguard.sdk.IntegrationGuardClient, which reaches java.util.logging by default and SLF4J or Log4j when the application installs their platform-logging bridge.

Security

  • Use an API key with only the ingest scope, limited to one project where possible. The key travels in the Authorization header over HTTPS; the SDK refuses plain HTTP to remote hosts unless you allow it, and never follows redirects.
  • The key never appears in log lines, exception messages or toString().
  • IntegrationGuard stores error messages, stack traces and metadata with common credential patterns masked (password=…, bearer tokens, passwords in URLs, IntegrationGuard API keys, metadata entries named like secrets). This is a safety net, not a guarantee: do not put credentials into messages or metadata, and use sendStackTraces(false) when traces may hold sensitive data.
  • Error details are limited to 32 KB per report by the SDK (and 64 KB by IntegrationGuard).

REST API

Any HTTP client can report. Send the API key as Authorization: Bearer igk_… (or X-IG-API-Key).

# An execution starts …
curl -X PUT https://monitoring.example.com/api/v1/ingest/integrations/invoice-sync/executions/run-2026-11-21 \
     -H "Authorization: Bearer $INTEGRATIONGUARD_API_KEY" -H "Content-Type: application/json" \
     -d '{"status":"RUNNING"}'

# … and ends (counts are totals, so repeating the request is harmless)
curl -X PUT https://monitoring.example.com/api/v1/ingest/integrations/invoice-sync/executions/run-2026-11-21 \
     -H "Authorization: Bearer $INTEGRATIONGUARD_API_KEY" -H "Content-Type: application/json" \
     -d '{"status":"COMPLETED","processed":5000,"successful":4850,"failed":150}'

# A failed run reported in one request, with the duration measured by the caller
curl -X PUT https://monitoring.example.com/api/v1/ingest/jobs/ledger-close/executions/2026-11-21 \
     -H "Authorization: Bearer $INTEGRATIONGUARD_API_KEY" -H "Content-Type: application/json" \
     -d '{"status":"FAILED","durationMs":93000,"error":{"type":"ExitCode","message":"exit status 2"}}'

# A heartbeat from a cron job: append to the crontab line
… && curl -fsS -X POST https://monitoring.example.com/api/v1/ingest/jobs/cache-warmup/heartbeat \
     -H "Authorization: Bearer $INTEGRATIONGUARD_API_KEY"

status is one of RUNNING, COMPLETED, FAILED, TIMED_OUT and CANCELED. Optional fields: startedAt, finishedAt (ISO-8601 UTC, at most 5 minutes ahead and 7 days back), durationMs, processed, successful, failed, error (type, message, details) and metadata (a flat object). The response is 201 for a new execution and 200 when the report updated or repeated one; reporting a different outcome for a finished execution is a 409 conflict. The full reference is in the REST API documentation.

Troubleshooting

Symptom Cause and fix
HTTP 404 … No integration with the key … The key is not defined in the project of the API key. Check the key in the console, or use a key of that project.
HTTP 409 ambiguous_key Several projects use this key and the API key is organization-wide. Use a project API key.
HTTP 403 insufficient_scope The API key lacks the ingest scope.
HTTP 401 The key is wrong, revoked or expired.
HTTP 429 More than the installation's report limit per key and minute (1200 by default). Report progress less often.
IllegalStateException: Use https … The base URL uses plain HTTP for a remote host.
Runs appear as missed The schedule in the console does not match when the job runs, or the grace period is too short.