newrelic / newrelic-telemetry-sdk-java

Java library for sending telemetry data to New Relic
Apache License 2.0
41 stars 37 forks source link

Initial commit of IngestWarnings file (checking Ingest API limits) and associated uses in the SDK #277

Closed yamnihcg closed 3 years ago

yamnihcg commented 3 years ago

This PR logs warnings if a user sends data that exceeds the New Relic Ingest API limits. For reference, here are the New Relic Ingest API limits for Events, Metrics, and Logs. In this PR, we are checking if data exceeds the following limits:

The IngestWarnings class contains all of the logic that checks if data exceeds Ingest API limits. The corresponding test file, IngestWarningsTest, contains unit tests to verify the functionality of IngestWarnings.

A user can create an instance of the IngestWarnings class in the SDK. After creating this instance, a user can call the raiseIngestWarnings method to log warnings for a given piece of data. The raiseIngestWarnings method requires 2 arguments. The first argument is the Attributes object associated with the data. The second argument is the data type (Metric, Event, or Log).

Below is a code snippet from the EventBuffer class that shows how IngestWarnings is used to log warnings in the SDK.

private final IngestWarnings ingestWarnings = new IngestWarnings();

public void addEvent(Event event) {
    Map<String, Object> attributes = event.getAttributes().asMap();
    ingestWarnings.raiseIngestWarnings(attributes, "Event");
    events.add(event);
}