Because
Node.jsReference

Types

All exported TypeScript types from the Because SDK.

Core

BecauseOptions

type BecauseOptions = {
  apiKey?: string;
  apiUrl?: string;
  debug?: boolean;
};

TraceOptions

type TraceOptions = {
  input?: JsonObject;
  metadata?: Metadata;
  retentionPeriod?: RetentionPeriod;
};

RetentionPeriod

type RetentionPeriod = '1d' | '7d' | '30d' | '90d' | '1y';

IngestResult

type IngestResult = {
  traceId: string;
};

Spans

SpanType

type SpanType =
  'message' | 'json' | 'table' | 'http' | 'chart' | 'llm' | 'image' | 'db';

SpanOptions

type SpanOptions = {
  metadata?: DbSpanMetadata;
  input?: JsonObject;
  output?: JsonObject;
  alerts?: SpanAlert[];
  durationMs?: number;
  redact?: string[];
};

DbSpanOptions

Convenience alias for SpanOptions when typing a db span's options explicitly.

type DbSpanOptions = {
  metadata?: DbSpanMetadata;
  input?: JsonObject;
  output?: JsonObject;
  durationMs?: number;
};

DbSpanMetadata

type DbSpanMetadata = {
  collection?: string;
  table?: string;
  queryType?: 'sql' | 'nosql';
};

Alerts

SpanAlert

type SpanAlert = {
  label?: string;
  level: 'warn' | 'error';
  gt?: number;
  lt?: number;
  checks: SpanAlertCheck[];
};

At least one of gt or lt must be present. See Alerts.

SpanAlertCheck

type SpanAlertCheck = {
  target?: string;
  value: number;
};

HTTP

HttpRequestInput

type HttpRequestInput = {
  method: HttpMethod;
  url: string;
  headers?: Record<string, string>;
  content_type?: HttpContentType;
  body?: JsonObject | string | null;
};

HttpResponseOutput

type HttpResponseOutput = {
  status: number;
  headers?: Record<string, string>;
  content_type?: HttpContentType;
  body?: JsonObject | string | null;
};

HttpMethod

type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';

HttpContentType

type HttpContentType = 'json' | 'form' | 'text' | null;

LLM

LlmSpanInput

type LlmSpanInput = {
  prompt?: string;
  messages?: LlmMessage[];
  provider?: string;
  model?: string;
};

LlmSpanOutput

type LlmSpanOutput = {
  response?: string | JsonObject;
};

LlmMessage

type LlmMessage = {
  role: 'system' | 'user' | 'assistant' | 'tool';
  content: string;
};

Images

ImageSpanData

type ImageSpanData = {
  url: string;
  label?: string;
};

Tables

TableData

type TableData = TableGroup | { tables: TableGroup[] };

TableGroup

type TableGroup = {
  title?: string;
  columns: TableColumn[];
  rows: unknown[][];
  rowHighlights?: (TableHighlight | null)[];
  cellHighlights?: (TableHighlight | null)[][];
};

TableColumn

type TableColumn =
  | string
  | {
      label: string;
      span?: number;
      highlight?: TableHighlight;
    };

TableHighlight

type TableHighlight = 'danger' | 'warn' | 'success' | 'info' | 'muted';

TableCellSpan

type TableCellSpan = {
  readonly __cellSpan: true;
  readonly span: number;
  readonly value: unknown;
};

Charts

ChartData

type ChartData = ChartGroup | { charts: ChartGroup[] };

ChartGroup

type ChartGroup = {
  title?: string;
  type: ChartType;
  labels: string[];
  series: ChartSeries[];
  referenceLines?: ChartReferenceLine[];
};

ChartType

type ChartType = 'line' | 'bar' | 'pie' | 'scatter';

ChartSeries

type ChartSeries = {
  name?: string;
  data: number[];
};

Utilities

JsonObject

type JsonObject = Record<string, unknown> | unknown[];

Metadata

type Metadata = Record<string, string | number | boolean | null>;

Errors

BecauseError

Thrown when the API returns a non-OK response.

import { BecauseError } from '@refactorlabs/because';

try {
  await because.startTrace('...', async () => {
    /* ... */
  });
} catch (err) {
  if (err instanceof BecauseError) {
    console.error(err.status, err.message);
  }
}
class BecauseError extends Error {
  readonly status: number;
}

On this page