Metadata-Version: 2.5
Name: watchtower-lite
Version: 0.1.0
Summary: Zero-dependency Watchtower client (OTLP/HTTP JSON) for small Python services
License: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# watchtower-lite

Zero-dependency (stdlib only, Python >= 3.9) Watchtower client for small services that cannot take
the full OpenTelemetry SDK. It sends OTLP/HTTP JSON to the ingest gateway from a background thread
and never raises into your code. For richer instrumentation use `watchtower-observability` instead.

```
pip install watchtower-lite
```

```python
import watchtower_lite as wt

wt.init()  # reads WT_INGEST_KEY, WT_SERVICE, WT_ENVIRONMENT, WT_RELEASE, WT_OTLP_ENDPOINT; no-op without a key
wt.log("started", level="info", port=8080)

try:
    risky()
except Exception:
    wt.capture_exception(job="nightly")   # becomes an issue

with wt.span("infer", attrs={"model": "x"}, headers=request.headers):  # continues incoming traceparent
    requests.get(url, headers={"traceparent": wt.traceparent()})
# an exception inside the block marks the span as error, records it, and is re-raised
wt.flush(timeout=2.0)   # also flushed at exit
```

Default endpoint: `https://ingest.watchtowerops.net` (key set), override with `WT_OTLP_ENDPOINT`
(use `http://localhost:4318` for a local gateway). The key is sent as `x-watchtower-key`.

Batches flush every 2 s or 256 items. The queue holds 2048 items; when full the oldest is dropped
(`wt.dropped()` counts drops, including failed sends). Delivery is best effort, no retries.
Resource attributes: `service.name`, `deployment.environment`, `service.version`,
`telemetry.sdk.name=watchtower-lite`.

## Plain HTTP recipe

No library needed; any language can do this:

```
curl -X POST https://ingest.watchtowerops.net/v1/logs \
  -H 'Content-Type: application/json' -H "x-watchtower-key: $WT_INGEST_KEY" \
  -d '{"resourceLogs":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"my-svc"}}]},
       "scopeLogs":[{"logRecords":[{"timeUnixNano":"1760000000000000000","severityNumber":9,
       "severityText":"INFO","body":{"stringValue":"hello"}}]}]}]}'
```

Spans go to `/v1/traces` the same way (`resourceSpans` / `scopeSpans` / `spans`). An exception is a
span event named `exception` with `exception.type`, `exception.message` and `exception.stacktrace`.

## Test

`python3 -m unittest discover -s tests`
