feat: very simple error consumer within context #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a mechanism for handling log export errors via a user-provided error consumer, which can be passed through the OpenTelemetry context. The changes are focused, minimal, and primarily affect the log record processing pipeline.
Key Changes
1. BatchLogRecordProcessor.java
Consumer<Collection<LogRecordData>> errorConsumer
field to the processor's worker.ExportErrorContext.KEY
), allowing per-call customization.2. BatchLogRecordProcessorBuilder.java
setErrorConsumer
method to allow users to configure a global error consumer for the processor.3. ExportErrorContext.java (New File)
ContextKey
for aConsumer<Collection<LogRecordData>>
.4. SimpleLogRecordProcessor.java
Motivation & Impact
This PR enables applications to react programmatically to log export failures, such as by logging, alerting, or retrying failed exports.
By leveraging the OpenTelemetry context, error handling can be customized per operation or request, not just globally.
The change is backward-compatible and opt-in; existing users are unaffected unless they choose to use the new error consumer feature.
Summary
This PR adds a simple but powerful extension point for error handling in log export scenarios. By allowing a
Consumer<Collection<LogRecordData>>
to be attached via context or builder, it gives users fine-grained control over how export failures are managed, without complicating the main processing logic. The implementation is clean, well-contained, and leverages existing OpenTelemetry patterns.Sample usage
This how the client coding could look like: