or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

concurrency-fibers.mdcontext-services.mddata-structures.mdeffect-core.mderror-observability.mdfunction-utilities.mdindex.mdlayer-system.mdschema-validation.mdstreaming.md
tile.json

error-observability.mddocs/

Error Handling & Observability

Comprehensive error tracking with Cause, structured logging, metrics collection, and distributed tracing for production monitoring and debugging.

Capabilities

Error Cause Tracking

interface Cause<out E> extends Pipeable {}

declare namespace Cause {
  /**
   * Creates a failure cause
   */
  function fail<E>(error: E): Cause<E>;
  
  /**
   * Creates a defect (unexpected error) cause
   */
  function die(defect: unknown): Cause<never>;
  
  /**
   * Creates an interrupt cause
   */
  function interrupt(fiberId: FiberId): Cause<never>;
  
  /**
   * Combines causes in parallel
   */
  function parallel<E>(left: Cause<E>, right: Cause<E>): Cause<E>;
  
  /**
   * Combines causes in sequence
   */
  function sequential<E>(left: Cause<E>, right: Cause<E>): Cause<E>;
  
  /**
   * Checks if cause is a failure
   */
  function isFailure<E>(self: Cause<E>): boolean;
  
  /**
   * Checks if cause is a defect
   */
  function isDie<E>(self: Cause<E>): boolean;
  
  /**
   * Pretty prints a cause
   */
  function pretty<E>(self: Cause<E>): string;
}

Console Operations

declare namespace Console {
  /**
   * Logs a message
   */
  function log(...args: ReadonlyArray<any>): Effect<void>;
  
  /**
   * Logs an error message
   */
  function error(...args: ReadonlyArray<any>): Effect<void>;
  
  /**
   * Logs a warning message
   */
  function warn(...args: ReadonlyArray<any>): Effect<void>;
  
  /**
   * Logs an info message
   */
  function info(...args: ReadonlyArray<any>): Effect<void>;
  
  /**
   * Logs a debug message
   */
  function debug(...args: ReadonlyArray<any>): Effect<void>;
}

Metrics System

interface Metric<in Type, out Out> {}

declare namespace Metric {
  /**
   * Creates a counter metric
   */
  function counter(name: string, description?: string): Metric<number, MetricState.Counter>;
  
  /**
   * Creates a gauge metric
   */
  function gauge(name: string, description?: string): Metric<number, MetricState.Gauge>;
  
  /**
   * Creates a histogram metric
   */
  function histogram(name: string, boundaries: Chunk<number>, description?: string): Metric<number, MetricState.Histogram>;
  
  /**
   * Tags a metric
   */
  function tagged<Type, Out>(key: string, value: string): (self: Metric<Type, Out>) => Metric<Type, Out>;
  
  /**
   * Increments a counter
   */
  function increment<Type, Out>(metric: Metric<Type, Out>): Effect<void>;
  
  /**
   * Sets a gauge value
   */
  function set<Type, Out>(metric: Metric<Type, Out>, value: number): Effect<void>;
}

Usage Examples:

import { Effect, Console, Cause, Metric } from "effect";

// Basic logging
const logProgram = Effect.gen(function* () {
  yield* Console.log("Application starting");
  yield* Console.info("Processing data");
  yield* Console.warn("Low memory warning");
  yield* Console.error("Operation failed");
});

// Error cause analysis
const handleError = (cause: Cause<string>) => {
  if (Cause.isFailure(cause)) {
    console.log("Application error occurred");
  } else if (Cause.isDie(cause)) {
    console.log("Unexpected defect occurred");
  }
  console.log(Cause.pretty(cause));
};

// Metrics collection
const requestCounter = Metric.counter("http_requests_total", "Total HTTP requests");
const responseTimeHistogram = Metric.histogram("http_request_duration", 
  [0.1, 0.5, 1.0, 2.0, 5.0], "HTTP request duration");

const handleRequest = Effect.gen(function* () {
  yield* Metric.increment(requestCounter);
  const startTime = Date.now();
  
  // Process request
  yield* processRequest();
  
  const duration = Date.now() - startTime;
  yield* Metric.set(responseTimeHistogram, duration);
});

Types

declare namespace MetricState {
  interface Counter {
    readonly _tag: "Counter";
    readonly count: number;
  }
  
  interface Gauge {
    readonly _tag: "Gauge"; 
    readonly value: number;
  }
  
  interface Histogram {
    readonly _tag: "Histogram";
    readonly buckets: ReadonlyArray<readonly [number, number]>;
    readonly count: number;
    readonly sum: number;
  }
}