Skip to content

Replace print() with proper logger in KafkaConsumerHook error_callback#62732

Open
Ironankit525 wants to merge 2 commits intoapache:mainfrom
Ironankit525:fix/kafka-replace-print-with-logger
Open

Replace print() with proper logger in KafkaConsumerHook error_callback#62732
Ironankit525 wants to merge 2 commits intoapache:mainfrom
Ironankit525:fix/kafka-replace-print-with-logger

Conversation

@Ironankit525
Copy link

What happened:
In airflow/providers/apache/kafka/src/airflow/providers/apache/kafka/hooks/consume.py, the error_callback function handles errors from confluent_kafka. For non-authentication errors, it uses a bare print() statement, which bypasses Airflow's logging infrastructure.

Fix:
Replaced print("Exception received: ", err) with log.error("Exception received from Kafka: %s", err) using a module-level logging.getLogger(__name__). This ensures errors are properly captured by Airflow's logging handlers and log aggregation systems.

The error_callback function in KafkaConsumerHook was using a bare
print() statement for non-authentication Kafka errors. This bypasses
Airflow's logging infrastructure, making errors invisible to log
aggregation and alerting systems. Replaced with logging.getLogger
to ensure consistent, structured error reporting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant