autotel
Version:
Write Once, Observe Anywhere
64 lines (63 loc) • 1.97 kB
text/typescript
import { n as TraceContext } from "./trace-context-Cijqoi6e.cjs";
import { TracingOptions } from "./functional.cjs";
//#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;
}
/**
* @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
* interface WithTraceContext {
* ctx?: TraceContext
* }
*
* class UserService {
* @Trace()
* async createUser(data: UserData) {
* // Access ctx via this.ctx (available during execution)
* const ctx = (this as unknown as WithTraceContext).ctx
* if (ctx) {
* ctx.setAttribute('user.id', data.id)
* }
* return await db.users.create(data)
* }
* }
* ```
*/
declare function Trace(options?: TraceDecoratorOptions): <T extends (...args: unknown[]) => Promise<unknown>>(originalMethod: T, context: ClassMethodDecoratorContext) => T;
declare function Trace(name?: string, options?: TraceDecoratorOptions): <T extends (...args: unknown[]) => Promise<unknown>>(originalMethod: T, context: ClassMethodDecoratorContext) => T;
//#endregion
export { Trace, type TraceContext, TraceDecoratorOptions, type TracingOptions };
//# sourceMappingURL=decorators.d.cts.map