Class 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 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 events
        logBatchSender - The sender for log entries.
        shutdownSeconds - num of seconds to wait for graceful shutdown of its executor
        useDaemonThread - 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 events
        logBatchSender - The sender for log entries.
        shutdownSeconds - num of seconds to wait for graceful shutdown of its executor
        useDaemonThread - A flag to decide user-threads or daemon-threads
        maxTelemetryBuffer - The max number of telemetry to buffer
    • Method Detail

      • sendBatch

        public void sendBatch​(MetricBatch batch)
        Send a batch of Metric 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 of Span 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 of Event 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 of Log 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 operational TelemetryClient with all default options.
        Parameters:
        httpPosterCreator - A Supplier used to create an HttpPoster 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 operational TelemetryClient from a BaseConfig instance
        Parameters:
        httpPosterCreator - A Supplier used to create an HttpPoster instance.
        baseConfig - the base configuration
        Returns:
        A fully operational TelemetryClient instance.