Skip to content
Merged
137 changes: 66 additions & 71 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ under Unreleased and move into a version section at release time.

## Unreleased

### Changed

- The llama.cpp Python integration is now named `llama_cpp` in Python, CLI,
and environment configuration. `gguf` remains a compatibility alias; `all`
selects the integration once under its new name. Model format metadata
remains `gguf`.

- Automatic integrations no longer attach raw payloads, including GGUF prompts,
chat messages and replies. `attachments_enabled=True` enables uploads only for
attachments explicitly passed to `track_inference(attachments=[...])`.
Apps relying on automatic GGUF capture must supply attachments explicitly.
## 0.3.0 - 2026-10-21

### Added

Expand All @@ -24,19 +14,42 @@ under Unreleased and move into a version section at release time.
`BatchedInferencePipeline`. Transcriptions record duration, language, word
count and audio metadata. Audio and transcript attachments must be supplied
explicitly through the manual tracking API. See docs/whisper.md.
- The OpenAI integration now tracks `responses.create()` for synchronous and
asynchronous clients, including streaming. Records input/output token usage,
cached and reasoning tokens, response status or incomplete reason, resolved
model metadata, and time to first output delta for streams. Older OpenAI SDKs
without Responses remain supported.
- OpenAI sync and async `embeddings.create()` instrumentation records latency,
input token usage, batch size, vector dimensions, model metadata and errors.
Embedding vectors and raw inputs are never attached by this adapter.
`EmbeddingOutputMeta` now accepts optional `tokens_in` for analytics.
- Anthropic native `messages.stream()` helpers are now instrumented for sync
and async clients, including event iteration, `text_stream`, and final-message
helpers, with the shared streaming lifecycle contract.
- Process-wide integrations and hub patches now support sequential SDK client
replacement after the previous owner closes. Reinitialization replaces a
closed default. Existing models and provider clients keep their original
destination and must be recreated. Attempts to use a closed telemetry
destination warn once instead of silently dropping inference and error
events.

### Fixed

- Changing a model's metadata (for example `register_model(..., version="v2")`)
now takes effect after a restart. With offline persistence on (the default),
the model registry saved by an earlier process kept the first metadata ever
registered for each model on that machine, so later changes were ignored.
This includes anthropic models already saved as `"unknown"`.
### Changed

- `import wildedge` no longer imports every installed ML framework and API
client. Each library is imported when its integration is activated or a
model from it is registered, so SDK import is faster and a broken unrelated
package no longer stops the SDK from starting.
- The llama.cpp Python integration is now named `llama_cpp` in Python, CLI,
and environment configuration. `gguf` remains a compatibility alias; `all`
selects the integration once under its new name. Model format metadata
remains `gguf`.
- Automatic integrations no longer attach raw payloads, including GGUF prompts,
chat messages and replies. `attachments_enabled=True` enables uploads only for
attachments explicitly passed to `track_inference(attachments=[...])`.
Apps relying on automatic GGUF capture must supply attachments explicitly.
- `wildedge.init(dsn=...)` reuses the existing default client when the DSN
points to the same project, for example `dsn=os.environ["WILDEDGE_DSN"]`
under `wildedge run`. It used to create a second client.
- Enabling an integration or hub on a second client while another live client
owns process-wide instrumentation now logs a warning. Automatic events keep
going to the owner's project, as before, but this used to happen without a
word. With `wildedge run --strict-integrations` it raises `RuntimeError`.
- Quantization labels are defined once in `wildedge.quantizations` and used
by every integration. Behaviour changes:
- MLX-LM reports N-bit weights as `int4`/`int8`, like Transformers, instead
Expand All @@ -46,73 +59,50 @@ under Unreleased and move into a version section at release time.
reports `int8`.
- faster-whisper reports weight precision (`int8`, `f16`) instead of
CTranslate2 compute types such as `int8_float32`.
- The ultralytics integration now requires ultralytics 8.0.200 or later
(was 8.0.0). Earlier 8.0.x releases keep their helpers under
`ultralytics.yolo.utils`, and the integration turned itself off on them
without a word. `instrument("ultralytics")` now logs a warning naming the
installed version instead.

### Fixed

- The llama.cpp integration now tracks `Llama.create_chat_completion()` and
`Llama.create_completion()`, streaming or not. It used to patch only
`Llama.__call__`, so chat apps on llama-cpp-python reported model loads but
no inference events. It now patches `create_completion`, which every entry
point runs, so each call is tracked once.
- llama.cpp inference events now include the stop reason for non-streamed
calls, the generation config (`temperature`, `top_p`, `top_k`, `max_tokens`,
`repeat_penalty`, penalties, `seed`, stop sequence count), and, for chat
calls, `prompt_type="chat"` and `turn_index` measured on the last user
message.
- `import wildedge` no longer imports every installed ML framework and API
client. Each library is imported when its integration is activated or a
model from it is registered, so SDK import is faster and a broken unrelated
package no longer stops the SDK from starting.
- Changing a model's metadata (for example `register_model(..., version="v2")`)
now takes effect after a restart. With offline persistence on (the default),
the model registry saved by an earlier process kept the first metadata ever
registered for each model on that machine, so later changes were ignored.
This includes anthropic models already saved as `"unknown"`.
- MLX-LM models now report the device they run on (`mps` for the Apple GPU)
instead of always `cpu`. Accelerator names are defined once in
`wildedge.accelerators`, and PyTorch, Transformers, Ultralytics,
TensorFlow and Keras share their device detection.

- Process-wide integrations and hub patches now support sequential SDK client
replacement after the previous owner closes. Reinitialization replaces a closed
default; live ownership conflicts raise explicitly. Existing models/provider
clients retain their original destination and must be recreated. Attempts to
use a closed telemetry destination warn once instead of silently dropping
inference/error events.

- timm models now use the requested architecture/variant name for model identity
instead of the Python class name, so models such as resnet18 and resnet50 no
longer share telemetry. Manual registration falls back to timm architecture
metadata, and explicit model IDs retain priority.

- Ultralytics `model.predict()` now records inference telemetry. Instrumentation
patches `predict`, which `model(...)` delegates to, so both entry points are
tracked exactly once.

- Streaming wrappers now finalize once across exhaustion, explicit closure,
cancellation, and iterator errors. Early closure/cancellation records an
unsuccessful inference with partial metadata when available. TTFT ignores
lifecycle/role-only chunks; telemetry callbacks cannot break iteration and
retain the trace context captured at stream creation. Remote API streams
ending without their completion marker record `STREAM_INCOMPLETE`.

### Added

- Anthropic native `messages.stream()` helpers are now instrumented for sync
and async clients, including event iteration, `text_stream`, and final-message
helpers, with the shared streaming lifecycle contract.

- OpenAI sync and async `embeddings.create()` instrumentation records latency,
input token usage, batch size, vector dimensions, model metadata and errors.
Embedding vectors and raw inputs are never attached by this adapter.
`EmbeddingOutputMeta` now accepts optional `tokens_in` for analytics.

- The OpenAI integration now tracks `responses.create()` for synchronous and
asynchronous clients, including streaming. Records input/output token usage,
cached and reasoning tokens, response status or incomplete reason, resolved
model metadata, and time to first output delta for streams. Older OpenAI SDKs
without Responses remain supported.

### Changed

- The ultralytics integration now requires ultralytics 8.0.200 or later
(was 8.0.0). Earlier 8.0.x releases keep their helpers under
`ultralytics.yolo.utils`, and the integration turned itself off on them
without a word. `instrument("ultralytics")` now logs a warning naming the
installed version instead.

### Fixed

- The gguf integration now tracks `Llama.create_chat_completion()` and
`Llama.create_completion()`, streaming or not. It used to patch only
`Llama.__call__`, so chat apps on llama-cpp-python reported model loads but
no inference events. It now patches `create_completion`, which every entry
point runs, so each call is tracked once.
- gguf inference events now include the stop reason for non-streamed calls,
the generation config (`temperature`, `top_p`, `top_k`, `max_tokens`,
`repeat_penalty`, penalties, `seed`, stop sequence count), and, for chat
calls, `prompt_type="chat"` and `turn_index` measured on the last user
message. With attachments enabled, the prompt or chat messages and the reply
are attached.
- A span attribute whose value is a list, dict or other non-scalar no longer
gets the whole event batch rejected. Ingest only accepts scalar attribute
values and answered 422 for the batch, dropping unrelated loads, inferences
Expand All @@ -138,6 +128,11 @@ under Unreleased and move into a version section at release time.
tracked call of its pipeline; other models the pipeline runs, and direct
calls to the model, are still tracked. Generator and dataset inputs, which
run lazily, are not covered yet (#78).
- `flush()` no longer sends a batch the background sender is already sending.
Both used to send the same events and then each removed a batch from the
queue, so events were duplicated and, depending on timing, later events
could be removed without being sent. This showed up when a process started
with events saved by an earlier run and flushed soon after.

## 0.2.2 - 2026-09-30

Expand Down
2 changes: 1 addition & 1 deletion docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ To run the full matrix locally: `python scripts/run_compat_local.py`.
| `tensorflow` | `current` (`py3.10` override) | `tensorflow==2.21.0`, `keras==3.12.4`, `numpy==2.2.6` | 3.10 |
| `llama_cpp` | `min` | `llama-cpp-python==0.2.90`, `numpy==1.26.4` | 3.10, 3.11, 3.12, 3.13 |
| `llama_cpp` | `current` | `llama-cpp-python==0.3.36`, `numpy==2.2.6` | 3.10, 3.11, 3.12, 3.13 |
| `openai` | `min` | `openai==1.30.0` | 3.10, 3.11, 3.12, 3.13 |
| `openai` | `min` | `openai==1.30.0`, `httpx==0.27.2` | 3.10, 3.11, 3.12, 3.13 |
| `openai` | `current` | `openai==3.35.1` | 3.10, 3.11, 3.12, 3.13 |
| `transformers` | `min` | `transformers==4.40.0`, `torch==2.4.1`, `numpy==1.26.4` | 3.10, 3.11, 3.12, 3.13 |
| `transformers` | `min` (`py3.13` override) | `transformers==4.45.0`, `torch==2.5.0`, `numpy==2.1.3` | 3.13 |
Expand Down
20 changes: 12 additions & 8 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ There are three ways a process gets its client, in order of coverage:

All three produce the same thing: one process-wide default client that
`wildedge.span()`, `wildedge.register_model()` and the rest delegate to.
`init()` without `dsn` reuses whatever client already exists, so code written
for in-process init runs unchanged under `wildedge run`.
`init()` without `dsn`, or with the DSN that client already uses, reuses
whatever client already exists, so code written for in-process init runs
unchanged under `wildedge run`.

The lazy mode configures itself from the environment: `WILDEDGE_DSN`,
`WILDEDGE_INTEGRATIONS`, `WILDEDGE_HUBS`. Unset integration variables mean
Expand Down Expand Up @@ -99,12 +100,15 @@ them unwrapped or unset `WILDEDGE_DSN` there.
## One client per process

- Framework patches are installed at most once per process. One live client
owns process-wide auto-instrumentation; another client attempting to enable
it raises `RuntimeError` until that owner is closed. Manual tracking does not
claim ownership.
- `init()` reuses the live default client unless you pass `dsn`
explicitly, so the CLI-installed client and application code share one
client instead of racing.
owns process-wide auto-instrumentation. When another client enables an
integration or hub while that owner is live, it logs a warning and
automatic events keep going to the owner's project. The new client still
sends its manual tracking. With `wildedge run --strict-integrations`, the
conflict raises `RuntimeError` instead. Manual tracking does not claim
ownership.
- `init()` reuses the live default client unless you pass a `dsn` for a
different project, so the CLI-installed client and application code share
one client instead of racing.
- Trace and span correlation lives in contextvars at module level, not on a
client. Auto-instrumented events emitted inside `wildedge.trace(...)` /
`wildedge.span(...)` blocks correlate into the same trace no matter which
Expand Down
4 changes: 2 additions & 2 deletions docs/manual-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ with wildedge.trace(run_id="run-123"):
The default client comes from wherever initialization happened first:

- `wildedge run` installs one before your code loads. A later
`wildedge.init()` without `dsn` reuses it, so the same code works with or
without the CLI wrapper.
`wildedge.init()` without `dsn`, or with the same DSN, reuses it, so the
same code works with or without the CLI wrapper.
- `wildedge.init(...)` creates one (or reuses the existing default) and
registers it.
- Any module-level call (`wildedge.span`, `wildedge.register_model`, ...)
Expand Down
17 changes: 13 additions & 4 deletions examples/whisper_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# /// script
# requires-python = ">=3.10"
# dependencies = ["wildedge-sdk"]
#
# [tool.uv.sources]
# wildedge-sdk = { path = "..", editable = true }
# ///
"""Transcribe a WAV using a local Whisper model with automatic instrumentation.

Install mlx-whisper (Apple Silicon) or faster-whisper, set WILDEDGE_DSN, then:
python examples/whisper_example.py mlx_whisper /path/to/model /path/to/audio.wav
python examples/whisper_example.py faster_whisper /path/to/model /path/to/audio.wav
Set WILDEDGE_DSN, then add the backend you want to run:
uv run --with mlx-whisper examples/whisper_example.py mlx_whisper MODEL AUDIO
uv run --with faster-whisper examples/whisper_example.py faster_whisper MODEL AUDIO

MODEL is a local path or Hugging Face repo, AUDIO is a WAV file.

See docs/whisper.md for lifecycle and explicit attachment examples.
"""
Expand All @@ -20,7 +29,7 @@ def main():
args = parser.parse_args()
client = wildedge.init(integrations=[args.backend])
try:
with client.trace(), client.span(name="transcribe"):
with client.trace(), client.span(kind="agent_step", name="transcribe"):
if args.backend == "mlx_whisper":
import mlx_whisper # noqa: PLC0415 -- optional runtime

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "wildedge-sdk"
version = "0.2.2"
version = "0.3.0"
description = "ML inference monitoring for Python: on-device and remote models"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 2 additions & 0 deletions scripts/build_llms_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
("docs/manual-tracking.md", "manual-tracking", "Manual tracking"),
("docs/llm_api.md", "llm_api", "LLM API tracking"),
("docs/providers.md", "providers", "Providers"),
("docs/streaming.md", "streaming", "Streaming lifecycle"),
("docs/whisper.md", "whisper", "Whisper"),
("docs/compatibility.md", "compatibility", "Compatibility matrix"),
]

Expand Down
2 changes: 1 addition & 1 deletion scripts/compat_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"current": ["llama-cpp-python==0.3.36", "numpy==2.2.6"],
},
"openai": {
"min": ["openai==1.30.0"],
"min": ["openai==1.30.0", "httpx==0.27.2"],
"current": ["openai==3.35.1"],
},
"transformers": {
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ def client_with_stubbed_runtime():
def isolate_instrumentation_owner(monkeypatch):
monkeypatch.setattr(instrumentation, "_owner", None)
monkeypatch.setattr(instrumentation, "_enabled", set())
monkeypatch.setattr(instrumentation, "_strict_ownership", False)
monkeypatch.setattr(huggingface, "_client_route", None)
32 changes: 31 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from wildedge import cli, constants
from wildedge import cli, constants, instrumentation
from wildedge.defaults import peek_default_client
from wildedge.integrations.registry import IntegrationSpec
from wildedge.platforms.device_info import DeviceInfo
Expand Down Expand Up @@ -237,6 +237,36 @@ def instrument(self, name): # type: ignore[no-untyped-def]
bootstrap.install_runtime()


@pytest.mark.parametrize("strict", ["0", "1"])
def test_install_runtime_records_strict_ownership(monkeypatch, strict):
class FakeWildEdge:
SUPPORTED_INTEGRATIONS = {"onnx"}

def __init__(self, *, dsn, app_version, debug, sampling_interval_s=None): # type: ignore[no-untyped-def]
pass

def instrument(self, name): # type: ignore[no-untyped-def]
pass

def flush(self, timeout): # type: ignore[no-untyped-def]
pass

def close(self): # type: ignore[no-untyped-def]
pass

monkeypatch.setattr(bootstrap, "WildEdge", FakeWildEdge)
monkeypatch.setenv(constants.ENV_DSN, "https://secret@ingest.wildedge.dev/key")
monkeypatch.setenv(constants.ENV_INTEGRATIONS, "onnx")
monkeypatch.setenv(constants.ENV_STRICT_INTEGRATIONS, strict)
monkeypatch.setattr(bootstrap.importlib.util, "find_spec", lambda _: object())

context = bootstrap.install_runtime()
try:
assert instrumentation.strict_ownership() is (strict == "1")
finally:
context.shutdown()


def test_doctor_reports_missing_dsn_and_unknown_integration(monkeypatch, capsys):
monkeypatch.delenv("WILDEDGE_DSN", raising=False)
rc = cli.main(["doctor", "--integrations", "madeup"])
Expand Down
Loading
Loading