Metadata-Version: 2.4
Name: struct-sdk-native
Version: 0.2.0
Requires-Dist: bytecode==0.19.1 ; python_full_version >= '3.12' and python_full_version < '3.14'
License-File: LICENSE
Summary: Native capture runtime for the Struct observability SDK
Author-email: Struct <support@struct.ai>
License-Expression: Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://struct.ai/docs
Project-URL: Homepage, https://struct.ai
Project-URL: Issues, https://struct.ai/support

# struct-sdk-native

Native capture runtime for the [Struct](https://struct.ai) observability SDK. `struct-sdk`
installs it automatically; you do not need to install or import it yourself.

Public `struct.init(api_url=...)` composes authenticated Observation configuration with native
function-boundary hooks, boundary-plan lowering and the function lifecycle. The SDK
emits outputs through OpenTelemetry and owns export and health. Capability depends on the
interpreter, platform and verified adapter:

```python
from struct_sdk_native import capability_report

capability_report().available  # True only on a supported, verified native build
```

The internal lifecycle disarms inherited hooks after fork and requires explicit
`initialize(fresh_consumer)` in each worker. It supplies synchronous `suppress_capture()` scopes
and `shutdown(deadline)` using an absolute `time.monotonic()` deadline. The native outcome counts
describe consumer handoff, not export acknowledgement. Initialization establishes the process-owned
cleanup worker; shutdown and cleanup retries never start threads on the deadline-bound caller.
Retain the lifecycle and output adapter while cleanup is pending: active spans keep terminal hooks
until their original function returns and restores context, even after the delivery deadline.
Public `struct.init()` owns this composition; call it explicitly in each forked worker and call
`struct.shutdown()` during application teardown. This native package installs no signal or exit handler.

CPython 3.12 and 3.13 install a compiled wheel on Linux (x86_64 and ARM64; glibc 2.28 or newer, or
musl 1.2 or newer such as Alpine) and on macOS 11 or newer (Apple silicon and Intel). Every other
platform, including Python 3.14, free-threaded builds and Windows, installs a pure Python
wheel that reports the capability as unavailable. Neither case needs a Rust compiler, and no
source distribution is published.

Interior observations can capture at verified exception handlers, supported await assignments
and exact source statements. They require source that matches the loaded code; missing or
unverifiable source leaves the candidate unavailable. These independent points do not provide
paired coroutine or generator lifetimes.

### Coexistence with tools that replace function code

Struct preserves another tool's replacement when it can see that replacement before cleanup.
One narrow case is unsupported: another tool changes the same function inside Python's audit
callback for Struct's own code assignment. Python can finish Struct's assignment and overwrite
that nested edit. Installation then leaves Struct's verified code installed; rollback or cleanup
restores the prior or original application code. The other tool's instrumentation can disappear,
and Struct may report success without a conflict warning.

This limitation does not permit instrumentation errors to escape into the application. If an
audit callback rejects a change, Struct contains the failure. Rejected cleanup remains retryable
with capture inactive. Application return values and escaping exceptions must be preserved.

The server's publication path uses `struct_sdk_native.sil.prepare_definition(bytes)` to revalidate
immutable stored artifacts outside database locks, then a fresh `configuration_index()` to check
every enabled observation's prepared versions together. Preparation preserves existing identities;
the index retains only target/metric signatures. Both call the shared Rust compiler with the GIL
released and report typed refusals. The customer SDK never imports this compiler surface.

