Skip to main content

Deep visibility into your Airflow task changes

Project description

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"))

# Configure DAGs to track
dag_configs = {
    "example_dag": DagConfig(
        path=Path("/path/to/dag.py"),
        tasks=["task1", "task2"]  # Optional: specify tasks to track
    )
}

# Track tasks and get references
references = tracker.track_tasks(dag_configs)

# Check for changes
changes = tracker.check_for_changes(references)

# Save the new state
tracker.save_history(references)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dagsonar-0.0.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dagsonar-0.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file dagsonar-0.0.1.tar.gz.

File metadata

  • Download URL: dagsonar-0.0.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dagsonar-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2c82f47b66954398786945d6eb98178c29fa8577519577965e0339671ee0f58e
MD5 402a0c0458669365077b0440c518682a
BLAKE2b-256 0ec11012ee6e92ab6bc7e7746577ece706d90499d3dbc5204ee894ed778a9fa0

See more details on using hashes here.

File details

Details for the file dagsonar-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dagsonar-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dagsonar-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 faac9197819d80ec4e738f7f3af8da3bedbf7ad449a58d7da21d976089bd2a07
MD5 5a66e5a795cf25cf795ad2882a806e63
BLAKE2b-256 a393536656f2163d4ad52f0c9b541dcadc7ce669ec35d2cefced97db4ecec2fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page