Package io.opentelemetry.sdk.logs.export
Class BatchLogRecordProcessor
- java.lang.Object
-
- io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor
-
- All Implemented Interfaces:
LogRecordProcessor
,java.io.Closeable
,java.lang.AutoCloseable
public final class BatchLogRecordProcessor extends java.lang.Object implements LogRecordProcessor
Implementation of theLogRecordProcessor
that batches logs exported by the SDK then pushes them to the exporter pipeline.All logs reported by the SDK implementation are first added to a synchronized queue (with a
maxQueueSize
maximum size, if queue is full logs are dropped). Logs are exported either when there aremaxExportBatchSize
pending logs orscheduleDelayNanos
has passed since the last export finished.- Since:
- 1.27.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BatchLogRecordProcessor.Worker
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
isShutdown
private static AttributeKey<java.lang.Boolean>
LOG_RECORD_PROCESSOR_DROPPED_LABEL
private static AttributeKey<java.lang.String>
LOG_RECORD_PROCESSOR_TYPE_LABEL
private static java.lang.String
LOG_RECORD_PROCESSOR_TYPE_VALUE
private BatchLogRecordProcessor.Worker
worker
private static java.lang.String
WORKER_THREAD_NAME
-
Constructor Summary
Constructors Constructor Description BatchLogRecordProcessor(LogRecordExporter logRecordExporter, MeterProvider meterProvider, long scheduleDelayNanos, int maxQueueSize, int maxExportBatchSize, long exporterTimeoutNanos)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BatchLogRecordProcessorBuilder
builder(LogRecordExporter logRecordExporter)
Returns a new Builder forBatchLogRecordProcessor
.CompletableResultCode
forceFlush()
Process all log records that have not yet been processed.(package private) java.util.List<LogRecordData>
getBatch()
LogRecordExporter
getLogRecordExporter()
Return the processor's configuredLogRecordExporter
.void
onEmit(Context context, ReadWriteLogRecord logRecord)
Called when aLogger
LogRecordBuilder.emit()
s a log record.CompletableResultCode
shutdown()
Shutdown the log processor.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.sdk.logs.LogRecordProcessor
close
-
-
-
-
Field Detail
-
WORKER_THREAD_NAME
private static final java.lang.String WORKER_THREAD_NAME
-
LOG_RECORD_PROCESSOR_TYPE_LABEL
private static final AttributeKey<java.lang.String> LOG_RECORD_PROCESSOR_TYPE_LABEL
-
LOG_RECORD_PROCESSOR_DROPPED_LABEL
private static final AttributeKey<java.lang.Boolean> LOG_RECORD_PROCESSOR_DROPPED_LABEL
-
LOG_RECORD_PROCESSOR_TYPE_VALUE
private static final java.lang.String LOG_RECORD_PROCESSOR_TYPE_VALUE
-
worker
private final BatchLogRecordProcessor.Worker worker
-
isShutdown
private final java.util.concurrent.atomic.AtomicBoolean isShutdown
-
-
Constructor Detail
-
BatchLogRecordProcessor
BatchLogRecordProcessor(LogRecordExporter logRecordExporter, MeterProvider meterProvider, long scheduleDelayNanos, int maxQueueSize, int maxExportBatchSize, long exporterTimeoutNanos)
-
-
Method Detail
-
builder
public static BatchLogRecordProcessorBuilder builder(LogRecordExporter logRecordExporter)
Returns a new Builder forBatchLogRecordProcessor
.- Parameters:
logRecordExporter
- theLogRecordExporter
to which the Logs are pushed- Returns:
- a new
BatchLogRecordProcessor
. - Throws:
java.lang.NullPointerException
- if thelogRecordExporter
isnull
.
-
onEmit
public void onEmit(Context context, ReadWriteLogRecord logRecord)
Description copied from interface:LogRecordProcessor
Called when aLogger
LogRecordBuilder.emit()
s a log record.- Specified by:
onEmit
in interfaceLogRecordProcessor
- Parameters:
context
- the context set viaLogRecordBuilder.setContext(Context)
, orContext.current()
if not explicitly setlogRecord
- the log record
-
shutdown
public CompletableResultCode shutdown()
Description copied from interface:LogRecordProcessor
Shutdown the log processor.- Specified by:
shutdown
in interfaceLogRecordProcessor
- Returns:
- result
-
forceFlush
public CompletableResultCode forceFlush()
Description copied from interface:LogRecordProcessor
Process all log records that have not yet been processed.- Specified by:
forceFlush
in interfaceLogRecordProcessor
- Returns:
- result
-
getLogRecordExporter
public LogRecordExporter getLogRecordExporter()
Return the processor's configuredLogRecordExporter
.- Since:
- 1.37.0
-
getBatch
java.util.List<LogRecordData> getBatch()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-