The official TypeScript SDK provides type-safe event tracking for Node.js and edge runtime applications.
npm install @opstrails/sdkimport { OpsTrailsClient } from '@opstrails/sdk'
const client = new OpsTrailsClient({
apiKey: process.env.OPSTRAILS_API_KEY!,
})
await client.trackEvent({
type: 'deployment',
source: '//github.com/your-org/your-repo',
subject: 'production',
version: 'v1.2.3',
})| Option | Type | Description |
|---|---|---|
apiKey | string | API key with READ_WRITE scope (required) |
baseUrl | string | API base URL (defaults to https://api.opstrails.dev) |
Records an event on the timeline. The SDK automatically sets specversion to"1.0" and time to"NOW" if not provided.
| Field | Type | Required | Description |
|---|---|---|---|
type | string | required | Event type |
source | string | required | Event source URI |
subject | string | optional | Context label |
version | string | optional | Release version |
severity | string | optional | LOW, MINOR, MAJOR, CRITICAL |
time | string | optional | ISO 8601 timestamp (defaults to "NOW") |
data | object | optional | Arbitrary JSON payload |
await client.trackEvent({
type: 'deployment',
source: '//github.com/acme/api-service',
subject: 'production',
version: 'v2.1.0',
severity: 'LOW',
data: {
description: 'Deployed API service to production',
},
})await client.trackEvent({
type: 'rollback',
source: '//github.com/acme/api-service',
subject: 'production',
version: 'v2.0.9',
severity: 'MAJOR',
data: {
description: 'Rolled back due to elevated error rate',
},
})await client.trackEvent({
type: 'data-load',
source: '//airflow/etl-pipeline',
subject: 'warehouse',
data: {
description: 'Loaded 2.3M rows into analytics warehouse',
},
})✅ Tip
OpsTrailsError with the error code and message.