Skip to content

Support sequential auto-instrumentation client replacement - #87

Merged
piotrekno1 merged 1 commit into
develfrom
fix/instrumentation-client-replacement
Oct 20, 2026
Merged

piotrekno1 merged 1 commit into
develfrom
fix/instrumentation-client-replacement

Conversation

@piotrekno1

Copy link
Copy Markdown
Collaborator

Closing the first SDK client leaves process-wide framework patches bound to it, so enabling instrumentation on a replacement client silently produces no telemetry. Introduce a shared weak ownership route that installed factory patches resolve dynamically, without reinstalling the patches.

Ownership contract

  • One live SDK client owns process-wide auto-instrumentation. A second live client attempting to enable it raises RuntimeError; changing the default client alone cannot redirect it.
  • After the owner closes or is collected, a replacement can explicitly enable the integrations/hubs it wants. Prior activations do not carry over.
  • Existing models, provider clients, handles and streams remain bound to their original destination. Recreate auto-instrumented objects after replacement; they are not automatically transferred or promised to rebind through manual re-registration. Old provider references and inference/error publishing warn once when their destination is unavailable.
  • OpenAI/Anthropic provider wrappers snapshot their owner when the provider client is constructed, preventing cached handles on old provider objects from redirecting into a new project.
  • HuggingFace thread-local download provenance is scoped to the owner session so buffered records cannot cross ownership changes.

init() replaces a closed default. Failed initialization closes its newly created client while preserving the prior default and its active sampler. Repeated close is idempotent. Ownership locking resets after fork. In-flight work should finish before closing/replacing the SDK client.

The compatibility suite now constructs and closes a client per test instead of working around #74 with a process-long singleton. Explicit replacement regressions cover real ONNX sessions and OpenAI/Anthropic provider clients, including unchanged old-object ownership.

Fixes #74.

Validation

  • Full SDK suite: 808 passed, 28 skipped.
  • Current OpenAI/Anthropic compatibility suites using real SDKs and mocked provider HTTP: 41 passed.
  • Minimum Anthropic 0.25.0 compatibility suite: 25 passed.
  • Real ONNX 1.31.0, timm 1.0.11 and Ultralytics 8.0.200 compatibility checks: 9 passed (Python 3.12, PyTorch 2.14.1, NumPy 1.26.4).
  • Shared lifecycle tests cover all framework installer routes, hub routes, selective activation, live conflicts, garbage-collected owners, fork-lock reset, concurrent ownership claims, old handles, initialization cleanup and provenance isolation.
  • Local process-compose WildEdge: real ONNX inference before/after replacement; ingest accepted two batches of three events, rejected zero. Queried Iceberg and confirmed six events across two independent SDK sessions: one model load, inference and linked span per client. Reusing the old ONNX session after replacement emitted a warning and no redirected event. Run ID: client-replacement-local-6ea1fbaa70a7.
  • Ruff lint, formatting and whitespace checks pass.

Live OpenAI/Anthropic requests were not made; their compatibility checks use mocked HTTP. Existing objects must be recreated to participate in the new client's telemetry lifecycle.

@github-actions

Copy link
Copy Markdown

Coverage report

  • Total: 89% (11071/12507 lines)

Top uncovered files

  • wildedge/integrations/mlx.py: 28.7% (122 lines missed)
  • wildedge/integrations/transformers.py: 62.9% (112 lines missed)
  • wildedge/integrations/ultralytics.py: 67.7% (86 lines missed)
  • wildedge/integrations/pytorch.py: 66.0% (69 lines missed)
  • wildedge/platforms/macos.py: 56.8% (67 lines missed)

@piotrekno1
piotrekno1 merged commit 665f898 into devel Oct 20, 2026
14 checks passed
@piotrekno1
piotrekno1 deleted the fix/instrumentation-client-replacement branch October 20, 2026 17:34
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A second WildEdge client in the same process records no auto-instrumented events

1 participant