Skip to content

Commit

Permalink
fix: log Kafka errors according to severity
Browse files Browse the repository at this point in the history
  • Loading branch information
José Massada authored and filipeesch committed Oct 7, 2020
1 parent 185e7b3 commit 7300d3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/KafkaFlow/Consumers/KafkaConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ public KafkaConsumer(
this.consumerBuilder
.SetPartitionsAssignedHandler((consumer, partitions) => this.OnPartitionAssigned(consumer, partitions))
.SetPartitionsRevokedHandler((consumer, partitions) => this.OnPartitionRevoked(partitions))
.SetErrorHandler((p, error) => this.logHandler.Error("Kafka Consumer Error", null, new { Error = error }));
.SetErrorHandler((p, error) =>
{
if (error.IsFatal)
{
this.logHandler.Error("Kafka Consumer Fatal Error", null, new { Error = error });
}
else
{
this.logHandler.Warning("Kafka Consumer Error", new { Error = error });
}
});
}

private void OnPartitionRevoked(IReadOnlyCollection<TopicPartitionOffset> topicPartitions)
Expand Down
5 changes: 1 addition & 4 deletions src/KafkaFlow/Producers/MessageProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ private IProducer<byte[], byte[]> EnsureProducer()
{
this.dependencyResolverScope.Resolver
.Resolve<ILogHandler>()
.Error(
"Kafka Producer Error",
new KafkaException(error),
new { Error = error });
.Warning("Kafka Producer Error", new { Error = error });
}
})
.Build();
Expand Down

0 comments on commit 7300d3e

Please sign in to comment.