Skip to content

Beam native error handling

Beam has a native error handling: some transforms and IOs (e.g. KafkaIO, BigQueryIO) can send their bad records to an ErrorHandler, as BadRecord objects. Asgarde and the Beam error handling work together: the Asgarde failures can be added to the same ErrorHandler, for a single dead letter queue for the whole pipeline.

Need Use
Errors of your own transformation steps (map, flatMap, filter, DoFn) Asgarde: the failures of all the steps in a fluent flow, without boilerplate
Bad records of a Beam IO or transform supporting the ErrorHandler The Beam ErrorHandler
Both in the same pipeline Asgarde, with its failures converted to BadRecords and added to the Beam ErrorHandler

Add the Asgarde failures to a Beam ErrorHandler

Section titled “Add the Asgarde failures to a Beam ErrorHandler”

FailureTransforms.toBadRecords() converts the failures to Beam BadRecords:

final BadRecordErrorHandler<?> errorHandler = pipeline.registerBadRecordErrorHandler(new WriteBadRecordsToBigQuery());
// Bad records of a Beam IO supporting the error handler.
pipeline.apply("Read Kafka", KafkaIO.<String, String>read()
// ...
.withBadRecordErrorHandler(errorHandler));
// Failures of the Asgarde steps, added to the same error handler.
final WithFailures.Result<PCollection<Order>, Failure> result = CollectionComposer.of(messages)
.apply("Parse", MapElementFn.into(TypeDescriptor.of(Order.class)).via(OrderParser::parse))
.getResult();
errorHandler.addErrorCollection(result.failures().apply("To bad records", FailureTransforms.toBadRecords()));
errorHandler.close();

The mapping of a Failure to a BadRecord:

BadRecord From the Failure
record.humanReadableJsonRecord The origin element when it’s tracked, the input element otherwise
record.encodedRecord Empty: Asgarde keeps the elements as strings
failure.exception The exception, as a string
failure.exceptionStacktrace The stack trace
failure.description The pipeline step