Class DatadogLogClient

java.lang.Object
codes.grow.packages.datadoglogs.DatadogLogClient
All Implemented Interfaces:
LogClient, AutoCloseable

public final class DatadogLogClient extends Object implements LogClient
LogClient that ships records to the Datadog logs intake through a DatadogLogExporter and a background BatchProcessor. Create it with DatadogLogsClient.logClient(Options); DatadogLogsClient.close() flushes and closes it.

 DatadogLogClient logs = client.logClient();
 logs.logger("checkout").info("user signed in", Map.of("user", Map.of("id", 42)));
 logs.flush();
 
  • Method Details

    • exporter

      public DatadogLogExporter exporter()
      Returns the intake exporter used by this client.
      Returns:
      the exporter
    • processor

      public BatchProcessor processor()
      Returns the batch processor (queue, stats).
      Returns:
      the processor
    • resource

      public Map<String,Object> resource()
      Returns the resource merged into every record.
      Returns:
      immutable map
    • send

      public void send(LogEntry entry)
      Description copied from interface: LogClient
      Enqueues one record or input. Applies redaction and defaults (timestamp = now, resource from the client, trace correlation for inputs when a span is active). Never throws for a full queue or a closed client; the record is dropped and counted instead.
      Specified by:
      send in interface LogClient
      Parameters:
      entry - a LogRecord or LogInput
    • sendBatch

      public void sendBatch(Collection<? extends LogEntry> entries)
      Description copied from interface: LogClient
      Enqueues several records or inputs.
      Specified by:
      sendBatch in interface LogClient
      Parameters:
      entries - records or inputs
    • flush

      public void flush()
      Description copied from interface: LogClient
      Exports everything queued now, waiting at most the export timeout.
      Specified by:
      flush in interface LogClient
    • flush

      public void flush(Duration timeout)
      Description copied from interface: LogClient
      Exports everything queued now.
      Specified by:
      flush in interface LogClient
      Parameters:
      timeout - maximum wait
    • flushAsync

      public CompletableFuture<Void> flushAsync(Duration timeout)
      Description copied from interface: LogClient
      Specified by:
      flushAsync in interface LogClient
      Parameters:
      timeout - maximum wait
      Returns:
      completes when the queued records were exported
    • close

      public void close()
      Description copied from interface: LogClient
      Flushes and shuts down; idempotent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface LogClient
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Description copied from interface: LogClient
      Asynchronous LogClient.close().
      Specified by:
      closeAsync in interface LogClient
      Returns:
      completes when the client is closed
    • stats

      public BatchStats stats()
      Description copied from interface: LogClient
      Current counters.
      Specified by:
      stats in interface LogClient
      Returns:
      stats