# Optional Rust SDK

The SDK is an in-process `tracing` exporter. It is optional; the [HTTP contract](/docs/api-contract/) remains the integration boundary. `logmastctl` is a management CLI and never captures or tails logs.

## What the SDK adds

| Behavior | Bound or guarantee |
| --- | --- |
| Batching | Up to 100 events, approximately 512 KiB, or one second. |
| Compression | Gzip for bodies at least 1 KiB, only when smaller and advertised by the target catalog. |
| Queue | 1,024 events and 16 MiB, held through delivery attempts. |
| Retry | Bounded exponential backoff with jitter, up to 15 minutes. |
| Acknowledgment | Non-nil receipt, matching counts, and a 16 KiB response-read cap. |
| Shutdown | A bounded drain, with a ten-second deadline. |

Compression runs on the background export path. The prepared batch and event identities stay unchanged across retries. If capabilities cannot be discovered, the SDK sends plain JSON. A server rejecting gzip with HTTP 415 receives the same request retried uncompressed.

## Configure the application

Use the [public client source](https://github.com/albrisllc/logmast-clients) and pin a released revision. Import the `logmast-reporting` crate alongside your application's existing tracing setup. Configure it once in the executable; libraries return typed errors and do not install a global subscriber.

```text
LOGMAST_ENDPOINT=https://app.logmast.com/api/v1/ingest/batches
LOGMAST_SERVICE_ID=<service-uuid>
LOGMAST_TOKEN=<ingest-only-secret>
LOGMAST_ENVIRONMENT=production
LOGMAST_RELEASE=<release-identifier>
```

The token belongs in secret storage. Preserve ordinary application logging. Emit explicitly selected reports using the `logmast::report` tracing target or the crate's reporting helpers.

## Report once at the owning boundary

Report the terminal failure of a request, job, startup operation, or supervised task. A retry that eventually succeeds is not an unrecovered failure. Expected business rejections should not become operational errors.

Stable codes describe conditions, occurrence IDs describe reports, and correlation IDs connect related operations. Keep variable identifiers out of codes and fingerprints. Select safe context explicitly; do not export raw request bodies, provider errors, credentials, or unrestricted debug dumps.

## Understand loss and shutdown

The queue is in memory, not a durable spool. Abrupt termination can lose reports. Retain the exporter handle, drain it on planned shutdown, and inspect its delivered and dropped counters. Invalid events, permanent rejection, queue overflow, expiration, and shutdown limits are observable losses.

Exporter diagnostics remain local to avoid recursively reporting exporter failures. This SDK does not create heartbeats automatically; applications explicitly submit their own checks through HTTP.
