Star us on GitHub
Star
Menu

Using highlight.io with Java Frameworks

Learn how to set up highlight.io on your Java backend with Java log ingestion.

1

Configure client-side Highlight. (optional)

If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.

2

Install the Highlight Java SDK.

Add Highlight to your maven pom file.

<dependency> <groupId>io.highlight</groupId> <artifactId>highlight-sdk</artifactId> <version>latest</version> </dependency>
Copy
3

Initialize the Highlight Java SDK.

Highlight.init() initializes the Highlight backend SDK.

HighlightOptions options = HighlightOptions.builder("<YOUR_PROJECT_ID>") .version("1.0.0") .environment("development") .build(); Highlight.init(options);
Copy
4

Add Highlight logger.

Errors will automatically record raised exceptions and send them to Highlight.

Coming soon
Copy
5

Verify your errors are being recorded.

Now that you've set up the Middleware, verify that the backend error handling works by consuming an error from traced code.

6

Record custom errors. (optional)

If you want to explicitly send an error to Highlight, you can use the Highlight.captureException() method.

try { } catch (Exception ex) { Highlight.captureException(exception); }
Copy
7

Using sessions

When everything is finished and working, you can try to use sessions. You can find more information about the SESSION_ID here parseHeaders

HighlightSession session = new HighlightSession("SESSION_ID"); session.captureException(new NullPointerException("This shouldn't happen")); session.captureLog(Severity.INFO, "Just another message"); session.captureRecord(HighlightRecord.log() .severity(Severity.warn("Internal", Priority.HIGH)) .message("Just another message") .requestId("REQUEST_ID") .attributes(attributes -> attributes.put("application.user.name", "NgLoader")) .build());
Copy
8

Set up and call the Highlight Logger.

Highlight.captureLog() will record and send logs to Highlight.

Highlight.captureLog(Severity.INFO, "Just another message");
Copy
9

Set up and call the Highlight custom records.

Highlight.captureRecord() will send custom defined logs to Highlight.

Highlight.captureRecord(HighlightRecord.log() .severity(Severity.warn("Internal", Priority.HIGH)) .message("Just another message") .requestId("REQUEST_ID") .attributes(attributes -> attributes.put("application.user.name", "NgLoader")) .build());
Copy
10

Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.

11

Verify your backend traces are being recorded.

Visit the highlight traces portal and check that backend traces are coming in.