Skip to main content

DagSonar

Deep visibility into your Airflow task changes through AST parsing and tracking

Python Apache Airflow License

What is DagSonar?

DagSonar is a monitoring tool that provides deep visibility into your Airflow DAG tasks by tracking changes through AST (Abstract Syntax Tree) parsing. It detects modifications in task definitions, external variables, shell scripts, and function calls, ensuring you never miss critical changes to your DAGs.

Key Features

  • AST-Based Detection: Tracks changes by parsing the Abstract Syntax Tree of your DAG files
  • Task Reference Tracking: Monitors task definitions, external variables, and function calls
  • Shell Script Integration: Tracks associated shell scripts referenced in BashOperator tasks
  • Change History: Maintains a JSON-based history of all task modifications
  • Task Hash Generation: Generates unique hashes for each task state to detect changes
  • Support for Multiple DAGs: Track tasks across multiple DAG configurations

Installation

pip install dagsonar

Basic Usage

from pathlib import Path
from dagsonar import TaskTracker, DagConfig

# Initialize the tracker
tracker = TaskTracker(history_file=Path("task_history.json"))

# Define your DAG configuration
config = {
    "tester": DagConfig(
        path=Path("./playground/dag_tester.py"),
        tasks=["task_bash_op"],
    )
}

# Track changes
changes = tracker.track_changes(config, auto_save=False)
print(changes)

Features in Detail

Task Reference Tracking

DagSonar tracks several aspects of your tasks:

  • Task content and structure through AST
  • External variable references
  • Called functions
  • Shell scripts referenced in bash tasks
  • Task-specific hashes for change detection

Supported Task Types

Currently supports tracking of:

  • Function-based task definitions
  • BashOperator task instances
  • Referenced shell scripts
  • External variable dependencies

Configuration

DagConfig

from dagsonar import DagConfig
from pathlib import Path

config = DagConfig(
    path=Path("/path/to/dag.py"),  # Path to DAG file
    tasks=["task1", "task2"]       # Optional: List of specific tasks to track
)

Task History

Task history is stored in JSON format with the following structure:

[
  {
    "dag_id": "example_dag",
    "reference": {
      "dag_id": "example_dag",
      "task_history": [
        {
          "task_id": "task1",
          "content": "<ast_content>",
          "hash": "<computed_hash>",
          "external_variables": [],
          "called_functions": [],
          "shell_scripts": []
        }
      ]
    }
  }
]

Contributing

We welcome contributions! Please check out our Contributing Guide to get started.

Development Setup

  1. Clone the repository:
git clone https://github.com/pesnik/dagsonar.git
cd dagsonar
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or
.\venv\Scripts\activate  # Windows
  1. Install development dependencies:
pip install -e ".[dev]"

Running Tests

pytest tests/

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

  • Apache Airflow community
  • All contributors and users providing valuable feedback

Built for the Airflow community

Metadata

Release files for dagsonar 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dagsonar 0.0.4
File Size Uploaded
dagsonar-0.0.4.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dagsonar 0.0.4
File Interpreter ABI Platform
dagsonar-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 22.2 kB

Release files / dagsonar-0.0.4.tar.gz

Download URL dagsonar-0.0.4.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
29640e55f2881cfd7002f166052edac8f6abd1cb7311b0452fa9a765d3a04a67
BLAKE2b-256 checksum
How to use checksums
3be8f3ecf82724c14facc2673c804ef03ecd2004db273ca685de569d40a304c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / dagsonar-0.0.4-py3-none-any.whl

Download URL dagsonar-0.0.4-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb7a7b76f65a47ca0da92bdeedc4de53636ab22e678e74d5994f36b3fa75e86d
BLAKE2b-256 checksum
How to use checksums
afc80554d8df1757e61200d31f466201801b11cd91382e16c8483b190f5cf714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page