( tracer: Tracer | null, autoTraceId: string, opts: TraceOptions, fn: (childTrace: typeof autoTrace, ...args: Args) => R, )
| 30 | }; |
| 31 | |
| 32 | function _autoTrace<Args extends any[], R = void>( |
| 33 | tracer: Tracer | null, |
| 34 | autoTraceId: string, |
| 35 | opts: TraceOptions, |
| 36 | fn: (childTrace: typeof autoTrace, ...args: Args) => R, |
| 37 | ): (...args: Args) => R { |
| 38 | return (async (...args: Args) => { |
| 39 | const traceArgs: Fields = { |
| 40 | id: autoTraceId, |
| 41 | name: opts.name, |
| 42 | cat: [opts.category], |
| 43 | args: opts.extraDetails, |
| 44 | tid: autoTraceId.split('-')[autoTraceId.split('-').length - 1], |
| 45 | }; |
| 46 | tracer?.begin(traceArgs); |
| 47 | const childTrace = (opts: TraceOptions, fn: any) => { |
| 48 | return _autoTrace( |
| 49 | tracer?.child(traceArgs) ?? null, |
| 50 | opts.newRoot ? nextRoot() : autoTraceId, |
| 51 | opts, |
| 52 | fn, |
| 53 | ); |
| 54 | }; |
| 55 | (childTrace as any)._autoEnd = true; |
| 56 | (childTrace as any)._end = () => tracer?.end(traceArgs); |
| 57 | try { |
| 58 | return await Promise.resolve(fn(childTrace as any, ...args)); |
| 59 | } finally { |
| 60 | if ((childTrace as any)._autoEnd) { |
| 61 | (childTrace as any)._end(); |
| 62 | } |
| 63 | } |
| 64 | }) as any; |
| 65 | } |
| 66 | |
| 67 | export function delayTraceTillSignal<O extends object, K extends keyof O>( |
| 68 | trace: typeof autoTrace, |
no outgoing calls
no test coverage detected