TypeScript SDK: Installation
Installation
Section titled “Installation”Or with npm/pnpm/yarn:
The package name is @aires/sdk. It ships as a TypeScript source module ("main": "./src/index.ts") and includes a prebuilt native addon for supported platforms.
Initialization
Section titled “Initialization”Initialize the SDK once at application startup, before logging any events:
InitOptions
Section titled “InitOptions”| Option | Type | Required | Default | Description |
|---|---|---|---|---|
service | string | Yes | — | Service name (e.g. "workforce-api", "billing-worker") |
endpoint | string | Yes | — | Collector gRPC endpoint (e.g. "http://localhost:4317", "https://collector.prod:4317") |
environment | string | No | "production" | Environment name ("production", "staging", "dev") |
batchSize | number | No | 256 | Events per batch before flushing |
queueCapacity | number | No | 8192 | Maximum events buffered in memory |
tls | boolean | No | true | Enable TLS for the gRPC connection |
apiKey | string | No | — | API key for authenticated endpoints |
Bun Compatibility
Section titled “Bun Compatibility”The SDK is designed for Bun as the primary runtime. The native addon is compiled via NAPI-RS and loaded as a .node file using require(). Bun supports NAPI addons natively.
No additional configuration is needed for Bun.
Node.js Compatibility
Section titled “Node.js Compatibility”The SDK also works in Node.js 18+. Ensure your project supports CommonJS require() calls (the native addon is loaded via require()):
If you’re using a bundler that doesn’t handle native addons (e.g. esbuild, Vite), you’ll need to mark @aires/sdk as external:
Native Addon vs. Fallback
Section titled “Native Addon vs. Fallback”The SDK ships with a native addon compiled from Rust via NAPI-RS. This is the high-performance path — events are serialized to Protobuf in native code and shipped over gRPC using Tonic.
If the native addon can’t be loaded (e.g. unsupported platform, missing binary), the SDK falls back to a pure JavaScript mode that buffers events in memory and dumps them as JSON to stdout on flush. This fallback is intended for development and debugging only — it does not ship events to the collector.
To verify that the native addon is loaded, check the logs at startup. The native addon initialization will throw if the binary is missing, and the SDK catches this silently.
Building the Native Addon
Section titled “Building the Native Addon”If you need to build the native addon from source (e.g. for an unsupported platform):
This requires:
- Rust toolchain (1.75+)
- Protobuf compiler (
protoc) - NAPI-RS CLI (
npm install -g @napi-rs/cli)
The built addon will be at native/target/release/aires-sdk-napi.node.
Flushing
Section titled “Flushing”Always flush before your process exits to ensure all buffered events are shipped:
For HTTP servers, flush on SIGTERM:
For Bun:
Next Steps
Section titled “Next Steps”- Logging — All logging patterns and severity levels
- Tracing — Distributed trace propagation
- Metrics — Recording metric values
- HTTP Middleware — Automatic HTTP instrumentation