Class OtlpOutput
- All Implemented Interfaces:
LogLifecycle, LogOutput, LogOutput.ProvidesEncoder, Flushable, AutoCloseable
/v1/logs) as protobuf (the default)
or JSON, without the OpenTelemetry SDK or a protobuf library.
Events are buffered and sent as one request per flush(), and as soon as
maxBatchSize events are pending. Use an asynchronous publisher: with the
default synchronous one every log call waits for its own HTTP request. HTTP 429, 502,
503, and 504 responses and network errors are retried up to three times with
exponential backoff with jitter, honoring Retry-After. The timeout bounds the
whole export, including retries and response-body reads. A batch that still fails is
dropped, recorded as an error alert, and counted in "otlp.records.failed". Records
the endpoint reports as rejected (partial success) are a warning alert and counted in
"otlp.records.rejected".
This output encodes events itself, so it does not use an appender encoder. Records have
the same content as OtlpJsonEncoder produces.
-
Nested Class Summary
Nested classes/interfaces inherited from interface LogOutput
LogOutput.AbstractOutputStreamOutput, LogOutput.ContentType, LogOutput.OutputProvider, LogOutput.OutputType, LogOutput.ProvidesEncoder, LogOutput.ThreadSafeLogOutput, LogOutput.WriteMethodModifier and TypeInterfaceDescriptionstatic classAbstract output on output stream.static interfaceThe content type of the binary data passed to the output from an encoder.static interfaceFinds output based on URI.static enumOutput type useful for defaults and categorization.static interfaceMarks an output that supplies its ownLogEncoderinstead of relying entirely onLogAppender.APPENDER_ENCODER_PROPERTYorLogEncoderRegistry.encoderForOutputType(OutputType).static interfaceMarker interface that the output is thread safe.static enumThe preferred write style of an output.Nested classes/interfaces inherited from interface LogOutput.ProvidesEncoder
LogOutput.ProvidesEncoder.PolicyModifier and TypeInterfaceDescriptionstatic enumWhether aLogOutput.ProvidesEncoder'sLogOutput.ProvidesEncoder.encoder(String, LogConfig)can be overridden by another, explicitly configured encoder. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of events per request.static final intDefault export timeout in milliseconds.static final StringMetric counting log records dropped because a request failed.static final StringOutput URI scheme.static final StringMetric counting log records the endpoint rejected in a partial success response.Fields inherited from interface LogOutput
FILE_SCHEME, STDERR_SCHEME, STDERR_URI, STDOUT_SCHEME, STDOUT_URIModifier and TypeFieldDescriptionstatic final StringFile URI scheme.static final StringFileDescriptor.errURI scheme.static final URIStandard ERR URIstatic final StringFileDescriptor.outURI scheme.static final URIStandard OUT URI. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Will close the output and should only be called by the owning appender.The encoder this output supplies, given the samename/configthe output itself was provided with.endpoint()The endpoint requests are sent to.voidflush()Flushes if the output is maintaining a buffer.static LogProvider<OtlpOutput> of(Consumer<OtlpOutputBuilder> consumer) Creates the output with a builder lambda; properties are applied after the lambda.policy()WhetherLogOutput.ProvidesEncoder.encoder(String, LogConfig)can be overridden by an explicitly configured encoder.protocol()The payload encoding.type()Gross categorization of an output.uri()The uri of the output.voidwrite(LogEvent[] events, int count, LogEncoder encoder, LogEncoder.Buffer buffer) Write a batch of events reusing the provided buffer and by default callingLogOutput.write(LogEvent, Buffer)for each event synchronously.voidwrite(LogEvent event, byte[] bytes, int off, int len, LogOutput.ContentType contentType) Analogous toOutputStream.write(byte[], int, int).Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface LogOutput
bufferHints, reopen, start, write, write, write, write, writeModifier and TypeMethodDescriptiondefault LogEncoder.BufferHintsHints to the buffer like what write style of the output and maximum buffer size.default voidreopen()Attempts to reopen the output if supported and SHOULD only be called by the appender!default voidStarts a component.default voidwrite(LogEvent[] events, int count, LogEncoder encoder) Write a batch of events by default callsLogOutput.write(LogEvent[], int, LogEncoder, Buffer).default voidwrite(LogEvent event, byte[] bytes, LogOutput.ContentType contentType) Analogous toOutputStream.write(byte[]).default voidwrite(LogEvent event, LogEncoder.Buffer buffer) Writes a prepared buffer and by default drains the buffer to this output.default voidWrites a string and by default with charsetStandardCharsets.UTF_8.default voidwrite(LogEvent event, ByteBuffer buf, LogOutput.ContentType contentType) Write event with byte buffer.
-
Field Details
-
OTLP_SCHEME
-
FAILED_METRIC
Metric counting log records dropped because a request failed.- See Also:
-
REJECTED_METRIC
Metric counting log records the endpoint rejected in a partial success response.- See Also:
-
DEFAULT_MAX_BATCH_SIZE
Default maximum number of events per request.- See Also:
-
DEFAULT_TIMEOUT
-
-
Method Details
-
of
Creates the output with a builder lambda; properties are applied after the lambda.- Parameters:
consumer- configures the builder.- Returns:
- output provider.
-
endpoint
-
protocol
-
uri
-
type
Description copied from interface:LogOutputGross categorization of an output. -
encoder
Description copied from interface:LogOutput.ProvidesEncoderThe encoder this output supplies, given the samename/configthe output itself was provided with.- Specified by:
encoderin interfaceLogOutput.ProvidesEncoder- Parameters:
name- appender name.config- config.- Returns:
- encoder, see
LogOutput.ProvidesEncoder.policy()for whether it can be overridden.
-
policy
Description copied from interface:LogOutput.ProvidesEncoderWhetherLogOutput.ProvidesEncoder.encoder(String, LogConfig)can be overridden by an explicitly configured encoder. Defaults toLogOutput.ProvidesEncoder.Policy.DEFAULT- an implementation only needs to override this to returnLogOutput.ProvidesEncoder.Policy.MANDATORY.- Specified by:
policyin interfaceLogOutput.ProvidesEncoder- Returns:
- policy.
-
write
public void write(LogEvent event, byte[] bytes, int off, int len, LogOutput.ContentType contentType) Description copied from interface:LogOutputAnalogous toOutputStream.write(byte[], int, int). -
write
Description copied from interface:LogOutputWrite a batch of events reusing the provided buffer and by default callingLogOutput.write(LogEvent, Buffer)for each event synchronously.The batching is usually a result of an asynchronous publisher so the maximum size is configured there with bufferSize. If this method is implemented there are some caveats.
DO NOT MODIFY THE ARRAY. It is reused. Do not use the
lengthof the passed in array but instead usecountparameter. Consequently do not share the array or buffer with other threads however individual events can be shared by callingLogEvent.freeze()to guarantee that which is a safe no-op if it is already immutable.If the output plans on grouping the events into a single blob (byte array or byte buffer) a different output can be passed to the encoder other than itself (which is the default).
-
flush
Description copied from interface:LogOutputFlushes if the output is maintaining a buffer. By default an appender will call this after each event in synchronous mode or after a batched group of events if in asynchronous mode unlessLogAppender.AppenderFlag.DISABLE_IMMEDIATE_FLUSHis set. -
close
Description copied from interface:LogOutputWill close the output and should only be called by the owning appender.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLogLifecycle- Specified by:
closein interfaceLogOutput
-