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);
}
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);
}
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
throwable Error
required
The error being reported to Highlight.
secureSessionId string
optional
A randomized id representing the Highlight session in which an error was thrown.
requestId string
optional
A randomized id generated by the Highlight client representing the request for which an error was thrown.
import io.highlight.sdk.Highlight;
try {
Integer.parseInt("string");
} catch (Exception e) {
Highlight.captureException(e);
}
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
severity Severity
required
The log being reported to Highlight.
message string
required
The log being reported to Highlight.
secureSessionId string
optional
A randomized id representing the Highlight session in which an error was thrown.
requestId string
optional
A randomized id generated by the Highlight client representing the request for which an error was thrown.
import io.highlight.sdk.Highlight;
import io.highlight.sdk.common.Severity;
Highlight.captureLog(Severity.DEBUG, "Request '/info' finished.");
Highlight.captureRecord
Highlight.captureRecord() reports an log or error to Highlight.
Method Parameters
record HighlightRecord
required
A record being reported to Highlight.
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."));
HighlightRecord.log
HighlightRecord.log() is a helper method that can be used to create log records.
Method Parameters
record HighlightLogRecord
optional
When an argument is provided, the new record created is abstracting its previous values.
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);
HighlightRecord.error
HighlightRecord.error() is a helper method that can be used to create error records.
Method Parameters
record HighlightErrorRecord
optional
When an argument is provided, the new record created is abstracting its previous values.
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);
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
text String
optional
Represents the identifier of a log message. The log message identifier represents a unique identifier that can be used to identify and search for specific log messages, thereby enabling better logging results.
priority Priority
optional
Represents the priority of a log message. The priority can be one of LOW, NORMAL, MEDIUM, or HIGH, and each priority level have an associated numeric difference value that is added to the severity ID when calculating the overall priority of a log message.
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