Star us on GitHub
Star
Menu

Java SDK API Reference

Java SDK

Highlight's Java SDK makes it easy to monitor errors and metrics on your Java backend.

Just getting started?

Check out our getting started guide to get up and running quickly.

Import our maven dependency from mvnrepository

Highlight.init

Highlight.init() initializes the Highlight backend SDK.

Method Parameters
import io.highlight.sdk.Highlight; HighlightOptions options = HighlightOptions.builder("PROJECT_ID") .build(); if (!Highlight.isInitialized()) { Highlight.init(highlightOptions); }
Copy

Highlight.isInitialized

Highlight.isInitialized() returns true if the Highlight backend SDK has been initialized. This may be handy if your initialization code could be called multiple times, e.g. if it is called conditionally from a request handler when a backend error or metric needs to be recorded.

import io.highlight.sdk.Highlight; HighlightOptions options = HighlightOptions.builder("PROJECT_ID") .build(); if (!Highlight.isInitialized()) { Highlight.init(highlightOptions); }
Copy

Highlight.captureException

Highlight.captureException() reports an error and its corresponding stack trace to Highlight. The secureSessionId and requestId properties are Highlight ids used to link an error to the session in which the error was thrown. These properties are sent via a header and included in every request to your backend once the Highlight client is initialized.

Method Parameters
import io.highlight.sdk.Highlight; try { Integer.parseInt("string"); } catch (Exception e) { Highlight.captureException(e); }
Copy

Highlight.captureLog

Highlight.captureLog() reports an log to Highlight. The secureSessionId and requestId properties are Highlight ids used to link the log to the session in which the log was called. These properties are sent via a header and included in every request to your backend once the Highlight client is initialized.

Method Parameters
import io.highlight.sdk.Highlight; import io.highlight.sdk.common.Severity; Highlight.captureLog(Severity.DEBUG, "Request '/info' finished.");
Copy

Highlight.captureRecord

Highlight.captureRecord() reports an log or error to Highlight.

Method Parameters
import io.highlight.sdk.Highlight; import io.highlight.sdk.common.Severity; import io.highlight.sdk.common.record.HighlightRecord; Highlight.captureRecord(HighlightRecord.log() .severity(Severity.DEBUG) .timeOccured(Instant.now()) .message("Request '/info' finished."));
Copy

HighlightRecord.log

HighlightRecord.log() is a helper method that can be used to create log records.

Method Parameters
import io.highlight.sdk.Highlight; import io.highlight.sdk.common.Severity; import io.highlight.sdk.common.record.HighlightRecord; HighlightLogRecord recordOne = HighlightRecord.log() .severity(Severity.DEBUG) .timeOccured(Instant.now()) .message("Request '/info' finished.") .build(); Highlight.captureRecord(recordOne); HighlightLogRecord recordTwo = HighlightRecord.log(recordOne) .timeOccured(Instant.now()) .build(); Highlight.captureRecord(recordTwo);
Copy

HighlightRecord.error

HighlightRecord.error() is a helper method that can be used to create error records.

Method Parameters
import io.highlight.sdk.Highlight; import io.highlight.sdk.common.Severity; import io.highlight.sdk.common.record.HighlightRecord; HighlightErrorRecord recordOne = HighlightRecord.error() .severity(Severity.DEBUG) .timeOccured(Instant.now()) .message(new NullPointerException("Request '/info' is missing arguments.")) .build(); Highlight.captureRecord(recordOne); HighlightErrorRecord recordTwo = HighlightRecord.error(recordOne) .timeOccured(Instant.now()) .build(); Highlight.captureRecord(recordTwo);
Copy

Severity

Severity of a log message, along with its text and priority. The severity can be one of TRACE, DEBUG, INFO, WARN, ERROR, or FATAL, and each severity level can have an associated identifier and priority level.

Method Parameters
import io.highlight.sdk.common.Severity; Severity.info("route"); Severity.info(Priority.HIGH); Severity.info("route", Priority.HIGH); Severity.TRACE Severity.DEBUG Severity.INFO Severity.WARN Severity.ERROR Severity.FATAL
Copy