UNPKG

autotel

Version:
67 lines 2.15 kB
import { n as TraceContext } from "./trace-context-CqCblIQE.js"; import { h as TracingOptions } from "./functional-DN_ztd9C.js"; //#region src/decorators.d.ts /** * Options for @Trace method decorator */ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> { /** * Custom span name. If not provided, uses the method name. */ name?: string; } /** * The receiver of a decorated method. `@Trace` lends the method its span's * context for the duration of the call, and puts back whatever was there. */ interface WithTraceContext { ctx?: TraceContext; } /** The decorator a `@Trace(...)` call produces. */ type TraceDecorator = <TArgs extends unknown[], TResult>(originalMethod: (...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext) => (...args: TArgs) => Promise<TResult>; /** * @Trace - Method decorator for fine-grained tracing * * Wraps a class method with automatic tracing. Supports both patterns: * - Simple: method doesn't use ctx * - Advanced: method accesses ctx via this.ctx * * @example Simple usage (no ctx) * ```typescript * class OrderService { * @Trace() * async createOrder(data: OrderData) { * return await db.orders.create(data) * } * } * ``` * * @example With custom name and options * ```typescript * class PaymentService { * @Trace('payment.charge', { withMetrics: true }) * async chargeCard(amount: number) { * return await stripe.charges.create({ amount }) * } * } * ``` * * @example Accessing ctx * ```typescript * class UserService { * @Trace() * async createUser(this: WithTraceContext, data: UserData) { * // Access ctx via this.ctx (available during execution) * const ctx = this.ctx * if (ctx) { * ctx.setAttribute('user.id', data.id) * } * return await db.users.create(data) * } * } * ``` */ declare function Trace(options?: TraceDecoratorOptions): TraceDecorator; declare function Trace(name?: string, options?: TraceDecoratorOptions): TraceDecorator; //#endregion export { Trace, type TraceContext, TraceDecorator, TraceDecoratorOptions, type TracingOptions, WithTraceContext };