Metadata-Version: 2.5
Name: fetchnode
Version: 0.4.0
Summary: Official Django and Python client SDK for FetchNode monitoring
Project-URL: Homepage, https://fetchnode.com
Project-URL: Repository, https://github.com/remcovanwijk040/fetchnode
Project-URL: Issues, https://github.com/remcovanwijk040/fetchnode/issues
Author-email: Remco van Wijk <remcovanwijk040@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.10
Requires-Dist: django>=4.2
Provides-Extra: celery
Requires-Dist: celery>=5.0; extra == 'celery'
Description-Content-Type: text/markdown

# FetchNode Python & Django SDK

[![PyPI](https://img.shields.io/pypi/v/fetchnode.svg)](https://pypi.org/project/fetchnode/)
[![Python Versions](https://img.shields.io/pypi/pyversions/fetchnode.svg)](https://pypi.org/project/fetchnode/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Official Python and Django client SDK for [FetchNode](https://fetchnode.com), the focused operations and monitoring workspace for Django teams and portfolio operators.

FetchNode captures unhandled exceptions, error logs, slow database queries, Celery background tasks, and business conversions with zero configuration bloat and privacy-safe defaults.

---

## Installation

Install the package using `pip` or `uv`:

```bash
pip install fetchnode
```

*(Or `uv add fetchnode`)*

---

## Quickstart (Django)

### 1. Add to `INSTALLED_APPS`

In your Django `settings.py`:

```python
INSTALLED_APPS = [
    # ...
    "fetchnode",
]
```

### 2. Add the Middleware

Add `FetchNodeMiddleware` near the top of your `MIDDLEWARE` list:

```python
MIDDLEWARE = [
    "fetchnode.middleware.FetchNodeMiddleware",
    "django.middleware.security.SecurityMiddleware",
    # ...
]
```

### 3. Configure `settings.FETCHNODE`

```python
FETCHNODE = {
    "API_KEY": "fn_live_your_project_key_here",
    "ENVIRONMENT": "production",  # e.g. "production", "staging"
    
    # Optional: override endpoint for self-hosted FetchNode instances
    # Defaults to FetchNode Cloud: "https://monitor.fetchnode.com"
    # "ENDPOINT": "https://monitor.fetchnode.com",
}
```

You can also configure via environment variables:
* `FETCHNODE_API_KEY`
* `FETCHNODE_ENVIRONMENT`
* `FETCHNODE_RELEASE`
* `FETCHNODE_ENDPOINT`

---

## Usage

### Milestone & Conversion Tracking

Track business events (form submits, leads, signups, payments) server-side with automatic visitor attribution:

```python
import fetchnode

def contact_view(request):
    form = ContactForm(request.POST)
    if form.is_valid():
        lead = form.save()
        
        # Track authoritative conversion
        fetchnode.track(
            "lead_submitted",
            request=request,
            idempotency_key=str(lead.id),
            properties={"email": lead.email},
            conversion=True,
        )
        return redirect("thank_you")
```

### Manual Exception Capture

```python
import fetchnode

try:
    risky_operation()
except Exception as exc:
    fetchnode.capture_exception(exc)
```

### Celery Task Monitoring

FetchNode automatically instruments Celery when installed. To manually monitor tasks or commands:

```python
from fetchnode import capture_job

@capture_job(name="sync_external_inventory")
def sync_inventory():
    ...
```

---

## Privacy by Default

FetchNode is engineered with privacy-safe defaults:
* Sensitive keys (`password`, `token`, `secret`, `api_key`, `authorization`, `cookie`, `csrfmiddlewaretoken`) are scrubbed before payload transmission.
* Request bodies and raw IP addresses are excluded by default.
* Query string parameters and raw SQL values are normalized.

---

## License

MIT License. See [LICENSE](LICENSE) for details.
