0
0
Apache Airflowdevops~10 mins

Task documentation and tags in Apache Airflow - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Task documentation and tags
Define Task
Add Documentation
Add Tags
Run DAG
View Docs & Tags in UI
This flow shows how to define a task, add documentation and tags, then run the DAG to see docs and tags in Airflow UI.
Execution Sample
Apache Airflow
from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime

dag = DAG('example_dag', start_date=datetime(2024,1,1))

task = BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag,
    doc_md='''This task prints the current date.''',
    tags=['example', 'date']
)
Defines a BashOperator task with documentation and tags inside a DAG.
Process Table
StepActionCode LineResult
1Import modulesfrom airflow import DAG from airflow.operators.bash import BashOperator from datetime import datetimeModules ready
2Create DAG objectdag = DAG('example_dag', start_date=datetime(2024,1,1))DAG 'example_dag' created
3Define task with doc and tagstask = BashOperator(..., doc_md='This task prints the current date.', tags=['example', 'date'])Task 'print_date' created with docs and tags
4Run DAG in Airflow UIairflow dags trigger example_dagDAG run started, task executes
5View task docs in UIOpen Airflow UI > DAGs > example_dag > print_date > Documentation tabDocumentation visible: 'This task prints the current date.'
6View task tags in UIOpen Airflow UI > DAGs > example_dag > Tags columnTags visible: 'example', 'date'
7EndN/ATask docs and tags successfully applied and visible
💡 All steps completed, task documentation and tags are set and visible in Airflow UI
Status Tracker
VariableStartAfter Step 2After Step 3Final
dagNoneDAG object createdDAG object unchangedDAG object unchanged
taskNoneNoneBashOperator task with doc and tagsTask ready to run with docs and tags
Key Moments - 3 Insights
Why does the task documentation not appear if I forget to use 'doc_md'?
The execution_table row 3 shows that documentation is added via 'doc_md'. Without it, Airflow has no text to display in the docs tab.
Can I add multiple tags to a task and how are they shown?
Yes, as shown in row 3 and 6, tags are a list of strings. They appear in the Airflow UI tags column separated by commas.
Does adding tags affect task execution?
No, tags are metadata only. The execution_table row 4 shows task runs normally regardless of tags.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the task created with documentation and tags?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Check the 'Action' column in execution_table row 3 for task creation details.
According to variable_tracker, what is the value of 'task' after step 3?
ADAG object
BBashOperator task with doc and tags
CNone
DString with documentation text
💡 Hint
Look at variable_tracker row for 'task' under 'After Step 3' column.
If you remove the 'tags' list from the task, what changes in the execution_table?
AStep 6 will show no tags in UI
BStep 3 will not create the task
CStep 4 will fail to run the DAG
DStep 5 will not show documentation
💡 Hint
Refer to execution_table rows 3 and 6 about tags presence and UI display.
Concept Snapshot
Task documentation and tags in Airflow:
- Use 'doc_md' parameter in task to add markdown docs.
- Use 'tags' parameter as list of strings for metadata.
- Docs appear in Airflow UI under task Documentation tab.
- Tags appear in DAGs list and task details.
- Tags do not affect task execution.
Full Transcript
This visual execution shows how to add documentation and tags to an Airflow task. First, we import necessary modules and create a DAG object. Then, we define a BashOperator task with the 'doc_md' parameter to add documentation and 'tags' parameter to add tags. When the DAG runs, the task executes normally. In the Airflow UI, the documentation is visible under the task's Documentation tab, and tags appear in the DAGs list and task details. Tags are metadata only and do not affect execution. The variable tracker confirms the task object holds the documentation and tags after creation. Key moments clarify common confusions about missing docs, multiple tags, and execution impact. The quiz tests understanding of when docs and tags are set and their UI visibility.