oneuptime/JavaSdk
2022-04-11 14:11:16 +01:00
..
.m2
src Rename services 2022-04-11 14:11:16 +01:00
.gitignore Rename services 2022-04-11 14:11:16 +01:00
pom.xml Rename services 2022-04-11 14:11:16 +01:00
README.md Rename services 2022-04-11 14:11:16 +01:00

maven

OneUptime SDK

A oneuptime sdk for application logger that can be used to send logs about your applications created on your fypie dashboard which can also used for error tracking

Installation

Maven Install

You can install to use in your project by adding the following to your pom.xml file:

<dependency>
    <groupId>io.hackerbay.oneuptime</groupId>
    <artifactId>JavaSDK</artifactId>
    <version>CURRENT_VERSION</version>
</dependency>

Others

Check Maven Central Repository for other modes of installation.

Basic Usage for Logging

import com.google.gson.JsonObject;
import io.hackerbay.oneuptime.OneUptimeLogger;
import java.io.IOException;

public class SampleClass {

    // set up the OneUptimeLogger
    public OneUptimeLogger logger = new OneUptimeLogger(
        "API_URL", // https://oneuptime.com/api
        "APPLICATION_LOG_ID",
        "APPLICATION_LOG_KEY"
    );

    // Logging a string information
    public void logStringInformation() throws IOException {
        String content = "Content to be logged";
        JsonObject response = logger.log(content); // returns a JsonObject of response
        System.out.println(response);
    }

    // Logging any object of a class
    public void logACustomClassInformation(CustomClass customClass) throws IOException {
        String content = new Gson().toJson(customClass); // converts your custom class to a json object
        JsonObject response = logger.log(content); // returns a JsonObject of response
        System.out.println(response);
    }

    // Logging a string with a series of tags
    public void logStringInformation() throws IOException {
        String content = "Content to be logged";
        String [] tags = { "server", "monitoring", "logs" };
        JsonObject response = logger.log(content, tags); // returns a JsonObject of response
        System.out.println(response);
    }
}

Basic Usage for Tracking

import com.google.gson.JsonObject;
import io.hackerbay.oneuptime.OneUptimeTracker;
import java.io.IOException;
import io.hackerbay.oneuptime.model.Tag;
import io.hackerbay.oneuptime.model.TrackerOption;


public class SampleClass {

    // set up option
    TrackerOption trackerOption = new TrackerOption(50); // set maximum timeline per event

    // set up the OneUptimeTracker
    public OneUptimeTracker tracker = new OneUptimeTracker(
        "API_URL", // https://oneuptime.com/api
        "ERROR_TRACKER_ID",
        "ERROR_TRACKER_KEY",
        trackerOption
    );

    // set up a timeline to be recorded
    JsonObject object = new JsonObject();
    object.addProperty("account", "debit");
    object.addProperty("amount", "6000.00");
    object.addProperty("userId", 471);
    tracker.addToTimeline("cart", object ," info");

    // setting custom tags
    Tag tag = new Tag("category", "customer");
    tracker.setTag(tag); // a single tag

    // multiple tags
    ArrayList<Tag> sampleTags = new ArrayList<Tag>();

    // create two tags and add to the array
    sampleTags.add(new Tag("type", "notification"));
    sampleTags.add(new Tag("location", "Oslo"));

    // setting the array of tags
    tracker.setTags(sampleTags);

    // capturing errors in a try and catch
    try {
        // some code that might fail
    } catch(Exception e) {
        tracker.captureException(e); // this is sent to your oneuptime dashboard
    }

    // capturing errors using the message signature
    tracker.captureMessage('some error text');

    // capturing errors authomatically

    throw new Exception("Something went wrong"); // calling this will trigger an error and its sent to your oneuptime dashboard
}

API Documentation

Main API to send logs to the server.

Author: HackerBay, Inc.

new OneUptimeLogger(apiUrl, applicationId, applicationKey)

Create a constructor from the class, which will be used to send logs to the server.

Kind: Constructor Returns: null

Param Type Description
apiUrl String The Server URL.
applicationId String The Application Log ID.
applicationKey String The Application Log Key.

logger.log(log, tags)

Logs a request of type info to the server.

Kind: method of new OneUptimeLogger Returns: JsonObject - A response of a success or failure.

Param Type Description
log String The content to the logged on the server.
tags String[] The tag(s) to be attached to the logged item on the server.

logger.warning(warning, tags)

Logs a request of type warning to the server.

Kind: method of new OneUptimeLogger Returns: JsonObject - A response of a success or failure.

Param Type Description
warning String The content to the logged on the server.
tags String[] The tag(s) to be attached to the logged item on the server.

logger.error(error, tags)

Logs a request of type error to the server.

Kind: method of new OneUptimeLogger Returns: JsonObject - A response of a success or failure.

Param Type Description
error String The content to the logged on the server.
tags String[] The tag(s) to be attached to the logged item on the server.

new OneUptimeTracker(apiUrl, errorTrackerId, errorTrackerKey, option)

Create a constructor from the class, which will be used to track errors sent to the server.

Kind: Constructor Returns: null

Param Type Description
apiUrl string The Server URL.
errorTrackerId string The Error Tracker ID.
errorTrackerKey string The Error Trakcer Key.
option TrackerOption The options to be considred by the tracker.

TrackerOption options

Param Type Description
maxTimeline int The total amount of timeline that should be captured, defaults to 5

tracker.setTag(Tag tag)

Set tag for the error to be sent to the server.

Kind: method of new OneUptime\OneUptimeTracker Returns: null

Param Type Description
tag Tag The tag object.

tracker.setTags(ArrayList tags)

Set multiple tags for the error to be sent to the server. Takes in an array

Kind: method of new OneUptime\OneUptimeTracker Returns: null

Param Type Description
tags ArrayList of Tag The list of tags to be added to the tracker.

tracker.setFingerprint(ArrayList fingerprints)

Set fingerprint for the next error to be captured.

Kind: method of new OneUptime\OneUptimeTracker Returns: null

Param Type Description
fingerprint string | ArrayList of strings The set of string used to group error messages on the server.

tracker.addToTimeline(category, content, type)

Add a custom timeline element to the next error to be sent to the server

Kind: method of new OneUptime\OneUptimeTracker Returns: null

Param Type Description
category string The category of the timeline event.
content JsonObject The content of the timeline event.
type string The type of timeline event.

tracker.captureMessage(message)

Capture a custom error message to be sent to the server

Kind: method of new OneUptime\OneUptimeTracker Returns: Promise

Param Type Description
\message string The message to be sent to the server.

tracker.captureException(error)

Capture a custom error object to be sent to the server

Kind: method of new OneUptime\OneUptimeTracker Returns: Promise

Param Type Description
\error Throwable The Error Object to be sent to the server.

Contribution

  • Clone repository
  • run mvn clean install to install dependencies
  • run mvn test to run tests
  • run mvn package to build for production.