Package com.newrelic.telemetry
Class TelemetryClient
- java.lang.Object
-
- com.newrelic.telemetry.TelemetryClient
-
public class TelemetryClient extends java.lang.Object
This 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 TelemetryClient
create(java.util.function.Supplier<HttpPoster> httpPosterCreator, BaseConfig baseConfig)
Create a fully operationalTelemetryClient
from a BaseConfig instancestatic TelemetryClient
create(java.util.function.Supplier<HttpPoster> httpPosterCreator, java.lang.String insertApiKey)
Create a fully operationalTelemetryClient
with all default options.void
sendBatch(EventBatch batch)
Send a batch ofEvent
instances, with standard retry logic.void
sendBatch(LogBatch batch)
Send a batch ofLog
entries, with standard retry logic.void
sendBatch(MetricBatch batch)
Send a batch ofMetric
instances, with standard retry logic.void
sendBatch(SpanBatch batch)
Send a batch ofSpan
instances, with standard retry logic.void
shutdown()
Cleanly shuts down the background Executor thread.void
withNotificationHandler(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 ofMetric
instances, 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 ofSpan
instances, 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 ofEvent
instances, 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 ofLog
entries, 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 operationalTelemetryClient
with all default options.- Parameters:
httpPosterCreator
- ASupplier
used to create anHttpPoster
instance.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 operationalTelemetryClient
from a BaseConfig instance- Parameters:
httpPosterCreator
- ASupplier
used to create anHttpPoster
instance.baseConfig
- the base configuration- Returns:
- A fully operational TelemetryClient instance.
-
withNotificationHandler
public void withNotificationHandler(NotificationHandler notificationHandler)
- Parameters:
notificationHandler
- TheNotificationHandler
to use
-
-