OpsTrailsDocs
Console

TypeScript SDK

The official TypeScript SDK provides type-safe event tracking for Node.js and edge runtime applications.

Installation

bash
npm install @opstrails/sdk

Quick Start

typescript
import { 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',
})

Client Options

OptionTypeDescription
apiKeystringAPI key with READ_WRITE scope (required)
baseUrlstringAPI base URL (defaults to https://api.opstrails.dev)

trackEvent()

Records an event on the timeline. The SDK automatically sets specversion to"1.0" and time to"NOW" if not provided.

FieldTypeRequiredDescription
typestringrequiredEvent type
sourcestringrequiredEvent source URI
subjectstringoptionalContext label
versionstringoptionalRelease version
severitystringoptionalLOW, MINOR, MAJOR, CRITICAL
timestringoptionalISO 8601 timestamp (defaults to "NOW")
dataobjectoptionalArbitrary JSON payload

Usage Examples

Track a Deployment

typescript
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',
  },
})

Track a Rollback

typescript
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',
  },
})

Track a Data Load

typescript
await client.trackEvent({
  type: 'data-load',
  source: '//airflow/etl-pipeline',
  subject: 'warehouse',
  data: {
    description: 'Loaded 2.3M rows into analytics warehouse',
  },
})

Tip

The SDK handles retries and error responses automatically. If the API returns an error, the SDK throws a typed OpsTrailsError with the error code and message.

Links