What if you could instantly know who changed what and when, without asking anyone?
Why Audit logging in Apache Airflow? - Purpose & Use Cases
Imagine you run a busy kitchen where many chefs add ingredients to dishes. Without notes, if a dish tastes wrong, you can't tell who added what or when.
Manually tracking every change or action is slow and easy to forget. It's hard to find mistakes or prove what happened, especially when many people work together.
Audit logging automatically records every important action with details like who did it and when. This creates a clear history that helps find issues and improve trust.
print('User X started task Y at time Z')
audit_logger.log(user='X', action='start_task', task='Y', timestamp='Z')
Audit logging makes it easy to track changes, find problems fast, and keep your system honest and reliable.
In Airflow, audit logs show who triggered workflows or changed schedules, helping teams quickly spot errors or unauthorized changes.
Manual tracking is slow and error-prone.
Audit logging automatically records detailed action histories.
This helps teams find issues and maintain trust easily.
Practice
Solution
Step 1: Understand audit logging concept
Audit logging is designed to keep track of user actions and system events.Step 2: Identify its purpose in Airflow
This helps with security monitoring and troubleshooting issues by reviewing what happened.Final Answer:
To record user actions for security and troubleshooting -> Option DQuick Check:
Audit logging = record user actions [OK]
- Confusing audit logs with performance logs
- Thinking audit logs store DAG code
- Assuming audit logs speed up tasks
airflow.cfg should you modify to enable audit logging?Solution
Step 1: Locate airflow.cfg configuration file
This file contains sections for different Airflow components.Step 2: Identify the section for logging settings
The[logging]section controls log-related configurations including audit logging.Final Answer:
[logging] -> Option BQuick Check:
Audit logging config is under [logging] [OK]
- Choosing [core] which is for general settings
- Selecting [scheduler] which controls scheduling
- Picking [webserver] which manages UI settings
[logging] audit_log_enabled = True audit_log_location = /var/log/airflow/audit.log
What will happen when a user triggers a DAG run?
Solution
Step 1: Check audit_log_enabled value
It is set to True, so audit logging is active.Step 2: Check audit_log_location setting
Logs will be saved to /var/log/airflow/audit.log as specified.Final Answer:
User action will be recorded in /var/log/airflow/audit.log -> Option AQuick Check:
Enabled True + location set = logs saved there [OK]
- Assuming logs go to default folder ignoring config
- Thinking audit_log_enabled is False
- Believing DAG fails without audit log
Solution
Step 1: Verify audit_log_enabled setting
If it was False, no logs would be created, but question states it is enabled.Step 2: Check file path and permissions
If the path is wrong or Airflow lacks permission to write, logs won't appear.Final Answer:
The audit_log_location path is incorrect or lacks write permission -> Option CQuick Check:
Wrong path or no write permission blocks logs [OK]
- Assuming scheduler not running causes no audit logs
- Blaming DAG definitions for audit logging issues
- Ignoring file system permissions
Solution
Step 1: Understand audit log growth risk
Audit logs can grow large and fill disk space if unmanaged.Step 2: Choose best management method
Configuring log rotation automatically archives and deletes old logs safely.Step 3: Evaluate other options
Disabling logs loses audit trail; storing in DB is not default; manual deletion is error-prone.Final Answer:
Configure log rotation on the audit_log_location file -> Option AQuick Check:
Log rotation prevents disk full from audit logs [OK]
- Disabling audit logs instead of managing size
- Relying on manual deletion which is unreliable
- Assuming database storage is default or better
Ready to prove it?
Pass the test and this pattern moves unknown
