Skip to content
awekrx edited this page May 29, 2026 · 1 revision

trace

Import

import { trace } from '@dev-suite/decorators/trace'

Category

  • method

Use Case

Emit structured start/success/error events around method execution.

Replaces

  • Scattered tracing spans in methods
  • Manual lifecycle events with inconsistent payload

Example 1

Without decorator

class WorkerService {
  async run(taskId: string) {
    tracer.emit({ phase: 'start', taskId });
    try {
      const result = await this.engine.run(taskId);
      tracer.emit({ phase: 'success', taskId });
      return result;
    } catch (error) {
      tracer.emit({ phase: 'error', taskId, error });
      throw error;
    }
  }
}

With decorator

import { trace } from '@dev-suite/decorators/trace';

class WorkerService {
  @trace({ reporter: (event) => tracer.emit(event) })
  async run(taskId: string) {
    return this.engine.run(taskId);
  }
}

Why better

  • Unified trace lifecycle around all method outcomes.
  • Cleaner business logic with less instrumentation noise.

Example 2

Without decorator

class ReconciliationService {
  async reconcile(batchId: string) {
    telemetry.start('reconcile', { batchId });
    const result = await this.core.reconcile(batchId);
    telemetry.end('reconcile', { batchId, count: result.count });
    return result;
  }
}

With decorator

import { trace } from '@dev-suite/decorators/trace';

class ReconciliationService {
  @trace({ reporter: (event) => telemetry.emit('reconcile', event) })
  async reconcile(batchId: string) {
    return this.core.reconcile(batchId);
  }
}

Why better

  • Reporter integration can adapt to current telemetry stack.
  • Consistent event schema improves debugging.

Clone this wiki locally