Package com.newrelic.telemetry
Class TelemetryClient
- java.lang.Object
-
- com.newrelic.telemetry.TelemetryClient
-
public class TelemetryClient extends java.lang.ObjectThis class should be the go-to spot for sending telemetry to New Relic. It includes the canonical implementation of retry-logic that we recommend being used when interacting with the ingest APIs.Note: This class creates a single threaded scheduled executor on which all sending happens. Be sure to call
shutdown()if you don't want this background thread to keep the VM from exiting.
-
-
Constructor Summary
Constructors Constructor Description TelemetryClient(MetricBatchSender metricBatchSender, SpanBatchSender spanBatchSender, EventBatchSender eventBatchSender, LogBatchSender logBatchSender)Create a new TelemetryClient instance, with four senders.TelemetryClient(MetricBatchSender metricBatchSender, SpanBatchSender spanBatchSender, EventBatchSender eventBatchSender, LogBatchSender logBatchSender, int shutdownSeconds, boolean useDaemonThread)Create a new TelemetryClient instance, with four senders and seconds to wait for shutdown.TelemetryClient(MetricBatchSender metricBatchSender, SpanBatchSender spanBatchSender, EventBatchSender eventBatchSender, LogBatchSender logBatchSender, int shutdownSeconds, boolean useDaemonThread, int maxTelemetryBuffer)Create a new TelemetryClient instance, with four senders and seconds to wait for shutdown.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TelemetryClientcreate(java.util.function.Supplier<HttpPoster> httpPosterCreator, BaseConfig baseConfig)Create a fully operationalTelemetryClientfrom a BaseConfig instancestatic TelemetryClientcreate(java.util.function.Supplier<HttpPoster> httpPosterCreator, java.lang.String insertApiKey)Create a fully operationalTelemetryClientwith all default options.voidsendBatch(EventBatch batch)Send a batch ofEventinstances, with standard retry logic.voidsendBatch(LogBatch batch)Send a batch ofLogentries, with standard retry logic.voidsendBatch(MetricBatch batch)Send a batch ofMetricinstances, with standard retry logic.voidsendBatch(SpanBatch batch)Send a batch ofSpaninstances, with standard retry logic.voidshutdown()Cleanly shuts down the background Executor thread.voidwithNotificationHandler(NotificationHandler notificationHandler)
-
-
-
Constructor Detail
-
TelemetryClient
public TelemetryClient(MetricBatchSender metricBatchSender, SpanBatchSender spanBatchSender, EventBatchSender eventBatchSender, LogBatchSender logBatchSender)
Create a new TelemetryClient instance, with four senders. Note that if you don't intend to send one of the telemetry types, you can pass in a null value for that sender.- Parameters:
metricBatchSender- The sender for dimensional metrics.spanBatchSender- The sender for distributed tracing spans.eventBatchSender- The sender for custom events.logBatchSender- The sender for log entries.
-
TelemetryClient
public TelemetryClient(MetricBatchSender metricBatchSender, SpanBatchSender spanBatchSender, EventBatchSender eventBatchSender, LogBatchSender logBatchSender, int shutdownSeconds, boolean useDaemonThread)
Create a new TelemetryClient instance, with four senders and seconds to wait for shutdown.- Parameters:
metricBatchSender- The sender for dimensional metrics.spanBatchSender- The sender for distributed tracing spans.eventBatchSender- The sender for custom eventslogBatchSender- The sender for log entries.shutdownSeconds- num of seconds to wait for graceful shutdown of its executoruseDaemonThread- A flag to decide user-threads or daemon-threads
-
TelemetryClient
public TelemetryClient(MetricBatchSender metricBatchSender, SpanBatchSender spanBatchSender, EventBatchSender eventBatchSender, LogBatchSender logBatchSender, int shutdownSeconds, boolean useDaemonThread, int maxTelemetryBuffer)
Create a new TelemetryClient instance, with four senders and seconds to wait for shutdown. You can also specify if the backing threads should be daemon threads, and the max number of telemetry to buffer.- Parameters:
metricBatchSender- The sender for dimensional metrics.spanBatchSender- The sender for distributed tracing spans.eventBatchSender- The sender for custom eventslogBatchSender- The sender for log entries.shutdownSeconds- num of seconds to wait for graceful shutdown of its executoruseDaemonThread- A flag to decide user-threads or daemon-threadsmaxTelemetryBuffer- The max number of telemetry to buffer
-
-
Method Detail
-
sendBatch
public void sendBatch(MetricBatch batch)
Send a batch ofMetricinstances, with standard retry logic. This happens on a background thread, asynchronously, so currently there will be no feedback to the caller outside of the logs.- Parameters:
batch- batch metrics to be applied
-
sendBatch
public void sendBatch(SpanBatch batch)
Send a batch ofSpaninstances, with standard retry logic. This happens on a background thread, asynchronously, so currently there will be no feedback to the caller outside of the logs.- Parameters:
batch- to be sent
-
sendBatch
public void sendBatch(EventBatch batch)
Send a batch ofEventinstances, with standard retry logic. This happens on a background thread, asynchronously, so currently there will be no feedback to the caller outside of the logs.- Parameters:
batch- to be sent
-
sendBatch
public void sendBatch(LogBatch batch)
Send a batch ofLogentries, with standard retry logic. This happens on a background thread, asynchronously, so currently there will be no feedback to the caller outside of the logs.- Parameters:
batch- to be sent
-
shutdown
public void shutdown()
Cleanly shuts down the background Executor thread.
-
create
public static TelemetryClient create(java.util.function.Supplier<HttpPoster> httpPosterCreator, java.lang.String insertApiKey)
Create a fully operationalTelemetryClientwith all default options.- Parameters:
httpPosterCreator- ASupplierused to create anHttpPosterinstance.insertApiKey- The New Relic Insert API to use.- Returns:
- A fully operational TelemetryClient instance.
-
create
public static TelemetryClient create(java.util.function.Supplier<HttpPoster> httpPosterCreator, BaseConfig baseConfig)
Create a fully operationalTelemetryClientfrom a BaseConfig instance- Parameters:
httpPosterCreator- ASupplierused to create anHttpPosterinstance.baseConfig- the base configuration- Returns:
- A fully operational TelemetryClient instance.
-
withNotificationHandler
public void withNotificationHandler(NotificationHandler notificationHandler)
- Parameters:
notificationHandler- TheNotificationHandlerto use
-
-