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(com.newrelic.telemetry.metrics.MetricBatchSender metricBatchSender, com.newrelic.telemetry.spans.SpanBatchSender spanBatchSender)
Deprecated.Use the constructor with all three senders, passing in null to the ones you don't care about.TelemetryClient(com.newrelic.telemetry.metrics.MetricBatchSender metricBatchSender, com.newrelic.telemetry.spans.SpanBatchSender spanBatchSender, com.newrelic.telemetry.events.EventBatchSender eventBatchSender, com.newrelic.telemetry.logs.LogBatchSender logBatchSender)
Create a new TelemetryClient instance, with four senders.TelemetryClient(com.newrelic.telemetry.metrics.MetricBatchSender metricBatchSender, com.newrelic.telemetry.spans.SpanBatchSender spanBatchSender, com.newrelic.telemetry.events.EventBatchSender eventBatchSender, com.newrelic.telemetry.logs.LogBatchSender logBatchSender, int shutdownSeconds, boolean useDaemonThread)
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<com.newrelic.telemetry.http.HttpPoster> httpPosterCreator, java.lang.String insertApiKey)
Create a fully operationalTelemetryClient
with all default options.void
sendBatch(com.newrelic.telemetry.events.EventBatch batch)
Send a batch ofEvent
instances, with standard retry logic.void
sendBatch(com.newrelic.telemetry.logs.LogBatch batch)
Send a batch ofLog
entries, with standard retry logic.void
sendBatch(com.newrelic.telemetry.metrics.MetricBatch batch)
Send a batch ofMetric
instances, with standard retry logic.void
sendBatch(com.newrelic.telemetry.spans.SpanBatch batch)
Send a batch ofSpan
instances, with standard retry logic.void
shutdown()
Cleanly shuts down the background Executor thread.
-
-
-
Constructor Detail
-
TelemetryClient
public TelemetryClient(com.newrelic.telemetry.metrics.MetricBatchSender metricBatchSender, com.newrelic.telemetry.spans.SpanBatchSender spanBatchSender, com.newrelic.telemetry.events.EventBatchSender eventBatchSender, com.newrelic.telemetry.logs.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(com.newrelic.telemetry.metrics.MetricBatchSender metricBatchSender, com.newrelic.telemetry.spans.SpanBatchSender spanBatchSender, com.newrelic.telemetry.events.EventBatchSender eventBatchSender, com.newrelic.telemetry.logs.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
@Deprecated public TelemetryClient(com.newrelic.telemetry.metrics.MetricBatchSender metricBatchSender, com.newrelic.telemetry.spans.SpanBatchSender spanBatchSender)
Deprecated.Use the constructor with all three senders, passing in null to the ones you don't care about.Create a new TelemetryClient instance, with two 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.
-
-
Method Detail
-
sendBatch
public void sendBatch(com.newrelic.telemetry.metrics.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.
-
sendBatch
public void sendBatch(com.newrelic.telemetry.spans.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.
-
sendBatch
public void sendBatch(com.newrelic.telemetry.events.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.
-
sendBatch
public void sendBatch(com.newrelic.telemetry.logs.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.
-
shutdown
public void shutdown()
Cleanly shuts down the background Executor thread.
-
create
public static TelemetryClient create(java.util.function.Supplier<com.newrelic.telemetry.http.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.
-
-