/** * @module * This module provides functions for instrumenting methods and functions. */ import { Level } from "./level.js"; import { type SubscriberData } from "./span.js"; type AnyFunction = (this: any, ...args: any[]) => any; declare const AttributeKind: { Message: 0; Target: 1; Level: 2; Skip: 3; SkipAll: 4; Field: 5; LogEnter: 6; LogExit: 7; LogReturnValue: 8; LogError: 9; Log: 10; Redact: 11; SubscriberData: 12; }; type AttributeKind = typeof AttributeKind; type MessageAttribute = { kind: AttributeKind["Message"]; message: string; }; type TargetAttribute = { kind: AttributeKind["Target"]; } & ({ class: string; method: string; private?: boolean; } | { function: string; }); type LevelAttribute = { kind: AttributeKind["Level"]; level: Level; }; type SkipByMask = { [index in keyof TArgs]: boolean; }; type SkipAttribute = { kind: AttributeKind["Skip"]; skip: SkipByMask | string[] | number[]; }; type SkipAllAttribute = { kind: AttributeKind["SkipAll"]; }; type FieldAttribute = { kind: AttributeKind["Field"]; name: string; value: unknown | ((args: TArgs[]) => unknown); }; type LogEnterAttribute = { kind: AttributeKind["LogEnter"]; message?: string | ((args: TArgs) => string); level?: Level; }; type LogExitAttribute = { kind: AttributeKind["LogExit"]; message?: string | ((args: TArgs) => string); level?: Level; }; type LogReturnValueAttribute = { kind: AttributeKind["LogReturnValue"]; map?: (returnValue: TReturn extends Promise ? TReturnPromise : TReturn, args: TArgs) => unknown; }; type LogErrorAttribute = { kind: AttributeKind["LogError"]; message?: string | ((args: TArgs) => string); level?: Level; }; type LogAttribute = { kind: AttributeKind["Log"]; level?: Level; }; type RedactProxy = { [key: string | number | symbol]: RedactProxy; } & Record; type RedactAttribute = { kind: AttributeKind["Redact"]; param: string | number; redact?: (param: RedactProxy) => RedactProxy | RedactProxy[]; }; /** * Attribute containing additional subscriber specific data. * * This can be used to wrap the `subscriberData` attribute e.g.: * * ```ts * export function exampleSubscriberData(data: Mydata): SubscriberDataAttribute { * return subscriberData({ example: data }); * } * ``` */ export type SubscriberDataAttribute = { kind: AttributeKind["SubscriberData"]; subscriberData: SubscriberData; }; type Attributes = MessageAttribute | TargetAttribute | LevelAttribute | SkipAttribute | SkipAllAttribute | FieldAttribute | LogEnterAttribute | LogExitAttribute | LogReturnValueAttribute | LogErrorAttribute | LogAttribute | RedactAttribute | SubscriberDataAttribute; /** * The message attribute is used to override the message of the span created by the instrumented method or function. * * @example Instrument a method with a custom message * ```ts * import { instrument, message } from "@bcheidemann/tracing"; * * class Example { * @instrument(message("Custom message")) * test() { * // ... * } * } * ``` * * @example Instrument a function with a custom message * ```ts * import { instrumentCallback, message } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [message("Custom message")], * function test() { * // ... * } * ); * ``` * * @param message The message to use for the span created by the instrumented method or function * @returns The message attribute */ export declare function message(message: string): MessageAttribute; /** * The target attribute is used to override the target of the span created by the instrumented method or function. * * @example Instrument a method with a custom target * ```ts * import { instrument, target } from "@bcheidemann/tracing"; * * class Example { * @instrument(target("Example", "test")) * test() { * // ... * } * } * ``` * * @example Instrument a function with a custom target * ```ts * import { instrumentCallback, target } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [target("test")], * function test() { * // ... * } * ); * ``` * * @param className The class name to use for the target field * @param method The method name to use for the target field * @returns The target attribute */ export declare function target(className: string, method: string): TargetAttribute; /** * The target attribute is used to override the target of the span created by the instrumented method or function. * * @example Instrument a method with a custom target * ```ts * import { instrument, target } from "@bcheidemann/tracing"; * * class Example { * @instrument(target("Example", "test")) * test() { * // ... * } * } * ``` * * @example Instrument a function with a custom target * ```ts * import { instrumentCallback, target } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [target("test")], * function test() { * // ... * } * ); * ``` * * @param functionName The function name to use for the target field * @returns The target attribute */ export declare function target(functionName: string): TargetAttribute; /** * The level attribute is used to override the level of the span created by the instrumented method or function. * * @example Instrument a method with a custom level * ```ts * import { instrument, level, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(level(Level.TRACE)) * test() { * // ... * } * } * ``` * * @example Instrument a function with a custom level * ```ts * import { instrumentCallback, level, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [level(Level.TRACE)], * function test() { * // ... * } * ); * ``` * * @param level The level to use for the span created by the instrumented method or function * @returns The level attribute */ export declare function level(level: Level): LevelAttribute; /** * The skip attribute is used to skip logging of specific arguments of the instrumented method or function. * * The skip attribute supports the following syntax: * - `skip("arg0")`: Skip arguments by name (doesn't work in minified code) * - `skip(0)`: Skip arguments by index * - `skip(true, false, false)`: Skip arguments by mask * * @example Instrument a method and skip logging of the first argument * ```ts * import { instrument, skip } from "@bcheidemann/tracing"; * * class Example { * @instrument("arg0") * test(arg0: string, arg1: number) { * // ... * } * } * ``` * * @example Instrument a function and skip logging of the first argument * ```ts * import { instrumentCallback, skip } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [skip("arg0")], * function test(arg0: string, arg1: number) { * // ... * } * ); * ``` * * @param paramNames The arguments to skip by name * @returns The skip attribute */ export declare function skip(...paramNames: string[]): SkipAttribute; /** * The skip attribute is used to skip logging of specific arguments of the instrumented method or function. * * The skip attribute supports the following syntax: * - `skip("arg0")`: Skip arguments by name (doesn't work in minified code) * - `skip(0)`: Skip arguments by index * - `skip(true, false, false)`: Skip arguments by mask * * @example Instrument a method and skip logging of the first argument * ```ts * import { instrument, skip } from "@bcheidemann/tracing"; * * class Example { * @instrument(0) * test(arg0: string, arg1: number) { * // ... * } * } * ``` * * @example Instrument a function and skip logging of the first argument * ```ts * import { instrumentCallback, skip } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [skip(0)], * function test(arg0: string, arg1: number) { * // ... * } * ); * ``` * * @param paramIndices The arguments to skip by index * @returns The skip attribute */ export declare function skip(...paramIndices: number[]): SkipAttribute; /** * The skip attribute is used to skip logging of specific arguments of the instrumented method or function. * * The skip attribute supports the following syntax: * - `skip("arg0")`: Skip arguments by name (doesn't work in minified code) * - `skip(0)`: Skip arguments by index * - `skip(true, false, false)`: Skip arguments by mask * * @example Instrument a method and skip logging of the first argument * ```ts * import { instrument, skip } from "@bcheidemann/tracing"; * * class Example { * @instrument(true, false) * test(arg0: string, arg1: number) { * // ... * } * } * ``` * * @example Instrument a function and skip logging of the first argument * ```ts * import { instrumentCallback, skip } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [skip(true, false)], * function test(arg0: string, arg1: number) { * // ... * } * ); * ``` * * @param mask The arguments to skip * @returns The skip attribute */ export declare function skip(...mask: SkipByMask): SkipAttribute; /** * The skipAll attribute is used to skip logging of all arguments of the instrumented method or function. * * @example Instrument a method and skip logging of all arguments * ```ts * import { instrument, skipAll } from "@bcheidemann/tracing"; * * class Example { * @instrument(skipAll) * test(arg0: string, arg1: number) { * // ... * } * } * ``` * * @example Instrument a function and skip logging of all arguments * ```ts * import { instrumentCallback, skipAll } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [skipAll], * function test(arg0: string, arg1: number) { * // ... * } * ); * ``` */ export declare const skipAll: SkipAllAttribute; /** * The field attribute is used to add custom fields to the span created by the instrumented method or function. * * The field attribute supports the following syntax: * - `field("fieldName", "fieldValue")`: Add a field with a static value * - `field("fieldName", (args) => args[0])`: Add a field with a dynamic value * * @example Instrument a method with a custom field * ```ts * import { instrument, field } from "@bcheidemann/tracing"; * * class Example { * @instrument(field("fieldName", "fieldValue")) * test() { * // ... * } * } * ``` * * @example Instrument a function with a custom field * ```ts * import { instrumentCallback, field } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [field("fieldName", "fieldValue")], * function test() { * // ... * } * ); * ``` * * @param name The name of the field * @param mapValue The value of the field * @returns The field attribute */ export declare function field(name: string, mapValue: (args: NoInfer) => unknown): FieldAttribute; /** * The field attribute is used to add custom fields to the span created by the instrumented method or function. * * The field attribute supports the following syntax: * - `field("fieldName", "fieldValue")`: Add a field with a static value * - `field("fieldName", (args) => args[0])`: Add a field with a dynamic value * * @example Instrument a method with a custom field * ```ts * import { instrument, field } from "@bcheidemann/tracing"; * * class Example { * @instrument(field("fieldName", (args) => args[0])) * test() { * // ... * } * } * ``` * * @example Instrument a function with a custom field * ```ts * import { instrumentCallback, field } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [field("fieldName", (args) => args[0]))], * function test() { * // ... * } * ); * ``` * * @param name The name of the field * @param mapValue The value of the field * @returns The field attribute */ export declare function field(name: string, value: TValue extends AnyFunction ? never : TValue): FieldAttribute; /** * The logEnter attribute is used to log a message when entering the instrumented method or function. * * The logEnter attribute supports the following syntax: * * - `logEnter()`: Log the default message when entering with the default log level * - `logEnter("Custom message")`: Log a custom message when entering with the default log level * - `logEnter(Level.TRACE)`: Log the default message when entering with a custom log level * - `logEnter(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logEnter } from "@bcheidemann/tracing"; * * class Example { * @instrument(logEnter()) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logEnter } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logEnter()], * function test() { * // ... * } * ); * ``` * * @returns The logEnter attribute */ export declare function logEnter(): LogEnterAttribute; /** * The logEnter attribute is used to log a message when entering the instrumented method or function. * * The logEnter attribute supports the following syntax: * * - `logEnter()`: Log the default message when entering with the default log level * - `logEnter("Custom message")`: Log a custom message when entering with the default log level * - `logEnter((args) => arg[0])`: Log a custom message mapped from arguments when entering with the default log level * - `logEnter(Level.TRACE)`: Log the default message when entering with a custom log level * - `logEnter(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logEnter(Level.TRACE, (args) => arg[0])`: Log a custom message mapped from arguments when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logEnter } from "@bcheidemann/tracing"; * * class Example { * @instrument(logEnter("my message")) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logEnter } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logEnter("my message")], * function test() { * // ... * } * ); * ``` * * @param message The message to log when entering * @returns The logEnter attribute */ export declare function logEnter(message: string): LogEnterAttribute; /** * The logEnter attribute is used to log a message when entering the instrumented method or function. * * The logEnter attribute supports the following syntax: * * - `logEnter()`: Log the default message when entering with the default log level * - `logEnter("Custom message")`: Log a custom message when entering with the default log level * - `logEnter((args) => arg[0])`: Log a custom message mapped from arguments when entering with the default log level * - `logEnter(Level.TRACE)`: Log the default message when entering with a custom log level * - `logEnter(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logEnter(Level.TRACE, (args) => arg[0])`: Log a custom message mapped from arguments when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logEnter } from "@bcheidemann/tracing"; * * class Example { * @instrument(logEnter((args) => `entering with ${args.length} args`)) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logEnter } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logEnter((args) => `entering with ${args.length} args`)], * function test() { * // ... * } * ); * ``` * * @param message Callback to map function arguments to the message to log when entering the function * @returns The logEnter attribute */ export declare function logEnter(message: (args: TArgs) => string): LogEnterAttribute; /** * The logEnter attribute is used to log a message when entering the instrumented method or function. * * The logEnter attribute supports the following syntax: * * - `logEnter()`: Log the default message when entering with the default log level * - `logEnter("Custom message")`: Log a custom message when entering with the default log level * - `logEnter((args) => arg[0])`: Log a custom message mapped from arguments when entering with the default log level * - `logEnter(Level.TRACE)`: Log the default message when entering with a custom log level * - `logEnter(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logEnter(Level.TRACE, (args) => arg[0])`: Log a custom message mapped from arguments when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logEnter, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(logEnter(Level.TRACE)) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logEnter, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logEnter(Level.TRACE)], * function test() { * // ... * } * ); * ``` * * @param level The log level to use when logging the message * @returns The logEnter attribute */ export declare function logEnter(level: Level): LogEnterAttribute; /** * The logEnter attribute is used to log a message when entering the instrumented method or function. * * The logEnter attribute supports the following syntax: * * - `logEnter()`: Log the default message when entering with the default log level * - `logEnter("Custom message")`: Log a custom message when entering with the default log level * - `logEnter((args) => arg[0])`: Log a custom message mapped from arguments when entering with the default log level * - `logEnter(Level.TRACE)`: Log the default message when entering with a custom log level * - `logEnter(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logEnter(Level.TRACE, (args) => arg[0])`: Log a custom message mapped from arguments when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logEnter, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(logEnter(Level.TRACE, "my message")) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logEnter, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logEnter(Level.TRACE, "my message")], * function test() { * // ... * } * ); * ``` * * @param level The log level to use when logging the message * @param message The message to log when entering * @returns The logEnter attribute */ export declare function logEnter(level: Level, message: string | ((args: TArgs) => string)): LogEnterAttribute; /** * The logExit attribute is used to log a message when exiting the instrumented method or function. * * The logExit attribute supports the following syntax: * * - `logExit()`: Log the default message when entering with the default log level * - `logExit("Custom message")`: Log a custom message when entering with the default log level * - `logExit((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logExit(Level.TRACE)`: Log the default message when entering with a custom log level * - `logExit(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logExit(Level.TRACE, (args) => args[0])`: Log a custom message mapped from args when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logExit } from "@bcheidemann/tracing"; * * class Example { * @instrument(logExit()) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logExit } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logExit()], * function test() { * // ... * } * ); * ``` * * @returns The logExit attribute */ export declare function logExit(): LogExitAttribute; /** * The logExit attribute is used to log a message when exiting the instrumented method or function. * * The logExit attribute supports the following syntax: * * - `logExit()`: Log the default message when entering with the default log level * - `logExit("Custom message")`: Log a custom message when entering with the default log level * - `logExit((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logExit(Level.TRACE)`: Log the default message when entering with a custom log level * - `logExit(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logExit(Level.TRACE, (args) => args[0])`: Log a custom message mapped from args when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logExit } from "@bcheidemann/tracing"; * * class Example { * @instrument(logExit("my message")) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logExit } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logExit("my message")], * function test() { * // ... * } * ); * ``` * * @param message The message to log when exiting * @returns The logExit attribute */ export declare function logExit(message: string): LogExitAttribute; /** * The logExit attribute is used to log a message when exiting the instrumented method or function. * * The logExit attribute supports the following syntax: * * - `logExit()`: Log the default message when entering with the default log level * - `logExit("Custom message")`: Log a custom message when entering with the default log level * - `logExit((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logExit(Level.TRACE)`: Log the default message when entering with a custom log level * - `logExit(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logExit(Level.TRACE, (args) => args[0])`: Log a custom message mapped from args when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logExit } from "@bcheidemann/tracing"; * * class Example { * @instrument(logExit((args) => args[0])) * test(arg0: string) { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logExit } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logExit((args) => args[0])], * function test(arg0: string) { * // ... * } * ); * ``` * * @param message Callback to map function arguments to the message to log when exiting the function * @returns The logExit attribute */ export declare function logExit(message: (args: TArgs) => string): LogExitAttribute; /** * The logExit attribute is used to log a message when exiting the instrumented method or function. * * The logExit attribute supports the following syntax: * * - `logExit()`: Log the default message when entering with the default log level * - `logExit("Custom message")`: Log a custom message when entering with the default log level * - `logExit((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logExit(Level.TRACE)`: Log the default message when entering with a custom log level * - `logExit(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logExit(Level.TRACE, (args) => args[0])`: Log a custom message mapped from args when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logExit, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(logExit(Level.TRACE)) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logExit, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logExit(Level.TRACE)], * function test() { * // ... * } * ); * ``` * * @param level The log level to use when logging the message * @returns The logExit attribute */ export declare function logExit(level: Level): LogExitAttribute; /** * The logExit attribute is used to log a message when exiting the instrumented method or function. * * The logExit attribute supports the following syntax: * * - `logExit()`: Log the default message when entering with the default log level * - `logExit("Custom message")`: Log a custom message when entering with the default log level * - `logExit((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logExit(Level.TRACE)`: Log the default message when entering with a custom log level * - `logExit(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logExit(Level.TRACE, (args) => args[0])`: Log a custom message mapped from args when entering with a custom log level * * The default log level is `Level.INFO`, unless the `log` attribute is provided with a different log level. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logExit, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(logExit(Level.TRACE, "my message")) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logExit, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logExit(Level.TRACE, "my message")], * function test() { * // ... * } * ); * ``` * * @param level The log level to use when logging the message * @param message The message to log when exiting * @returns The logExit attribute */ export declare function logExit(level: Level, message: string | ((args: TArgs) => string)): LogExitAttribute; /** * The logReturnValue attribute is used to log a message when exiting the instrumented method or function. It has no effect * when used without the `log` or `logExit` attribute. * * The logReturnValue attribute supports the following syntax: * - `logReturnValue()`: Add the returnValue field to the exit message * - `logReturnValue((returnValue, args) => returnValue)`: Add the returnValue field to the exit message with a custom value * * @example Instrument a method and log the return value when exiting * ```ts * import { instrument, logReturnValue } from "@bcheidemann/tracing"; * * class Example { * @instrument(logReturnValue()) * test() { * return "test"; * } * } * ``` * * @example Instrument a method and log the mappped return value when exiting * ```ts * import { instrument, logReturnValue } from "@bcheidemann/tracing"; * * class Example { * @instrument(logReturnValue((returnValue, args) => returnValue.toUpperCase()) * test() { * return "test"; * } * } * ``` * * @example Instrument a function and log the return value when exiting * ```ts * import { instrumentCallback, logReturnValue } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logReturnValue()], * function test() { * return "test"; * } * ); * ``` * * @example Instrument a function and log the mapped return value when exiting * ```ts * import { instrumentCallback, logReturnValue } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logReturnValue((returnValue, args) => returnValue.toUpperCase()], * function test() { * return "test"; * } * ); * ``` * * @param map The function to map the return value to a custom value * @returns The logReturnValue attribute */ export declare function logReturnValue(map?: LogReturnValueAttribute["map"]): LogReturnValueAttribute; /** * The logError attribute is used to log a message when the instrumented method or function throws an error. * * The logError attribute supports the following syntax: * * - `logError()`: Log the default message when entering with the default log level * - `logError("Custom message")`: Log a custom message when entering with the default log level * - `logError((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logError(Level.TRACE)`: Log the default message when entering with a custom log level * - `logError(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logError(Level.TRACE, (args) => args[0])`: Log a custom message mapped from return value and args when entering with a custom log level * * The default log level is `Level.ERROR`. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logError } from "@bcheidemann/tracing"; * * class Example { * @instrument(logError()) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logError } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logError()], * function test() { * // ... * } * ); * ``` * * @returns The logError attribute */ export declare function logError(): LogErrorAttribute; /** * The logError attribute is used to log a message when the instrumented method or function throws an error. * * The logError attribute supports the following syntax: * * - `logError()`: Log the default message when entering with the default log level * - `logError("Custom message")`: Log a custom message when entering with the default log level * - `logError((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logError(Level.TRACE)`: Log the default message when entering with a custom log level * - `logError(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logError(Level.TRACE, (args) => args[0])`: Log a custom message mapped from return value and args when entering with a custom log level * * The default log level is `Level.ERROR`. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logError } from "@bcheidemann/tracing"; * * class Example { * @instrument(logError("my message")) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logError } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logError("my message")], * function test() { * // ... * } * ); * ``` * * @param message The message to log on error * @returns The logError attribute */ export declare function logError(message: string): LogErrorAttribute; /** * The logError attribute is used to log a message when the instrumented method or function throws an error. * * The logError attribute supports the following syntax: * * - `logError()`: Log the default message when entering with the default log level * - `logError("Custom message")`: Log a custom message when entering with the default log level * - `logError((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logError(Level.TRACE)`: Log the default message when entering with a custom log level * - `logError(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logError(Level.TRACE, (args) => args[0])`: Log a custom message mapped from return value and args when entering with a custom log level * * The default log level is `Level.ERROR`. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logError } from "@bcheidemann/tracing"; * * class Example { * @instrument(logError((args) => args[0])) * test(arg0: string) { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logError } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logError((args) => args[0])], * function test(arg0: string) { * // ... * } * ); * ``` * * @param message Callback to map function arguments to the message to log on error * @returns The logError attribute */ export declare function logError(message: (args: TArgs) => string): LogErrorAttribute; /** * The logError attribute is used to log a message when the instrumented method or function throws an error. * * The logError attribute supports the following syntax: * * - `logError()`: Log the default message when entering with the default log level * - `logError("Custom message")`: Log a custom message when entering with the default log level * - `logError((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logError(Level.TRACE)`: Log the default message when entering with a custom log level * - `logError(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logError(Level.TRACE, (args) => args[0])`: Log a custom message mapped from return value and args when entering with a custom log level * * The default log level is `Level.ERROR`. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logError, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(logError(Level.CRITICAL)) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logError, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logError(Level.CRITICAL)], * function test() { * // ... * } * ); * ``` * * @param level The log level to use when logging the message * @returns The logError attribute */ export declare function logError(level: Level): LogErrorAttribute; /** * The logError attribute is used to log a message when the instrumented method or function throws an error. * * The logError attribute supports the following syntax: * * - `logError()`: Log the default message when entering with the default log level * - `logError("Custom message")`: Log a custom message when entering with the default log level * - `logError((args) => args[0])`: Log a custom message mapped from args when entering with the default log level * - `logError(Level.TRACE)`: Log the default message when entering with a custom log level * - `logError(Level.TRACE, "Custom message")`: Log a custom message when entering with a custom log level * - `logError(Level.TRACE, (args) => args[0])`: Log a custom message mapped from return value and args when entering with a custom log level * * The default log level is `Level.ERROR`. * * @example Instrument a method and log a message when entering * ```ts * import { instrument, logErrorm, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(logError(Level.CRITICAL, "my message")) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering * ```ts * import { instrumentCallback, logError, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [logError(logError(Level.CRITICAL, "my message"))], * function test() { * // ... * } * ); * ``` * * @param level The log level to use when logging the message * @param message The message to log on error * @returns The logError attribute */ export declare function logError(level: Level, message: string | ((args: TArgs) => string)): LogErrorAttribute; /** * The log attribute is used to log a message when entering, exiting, or when an error occurs in the instrumented method or function. * * @example Instrument a method and log a message when entering, exiting, or when an error occurs * ```ts * import { instrument, log } from "@bcheidemann/tracing"; * * class Example { * @instrument(log()) * test() { * // ... * } * } * ``` * * @example Instrument a method and log a message when entering, exiting, or when an error occurs (with level) * ```ts * import { instrument, log, Level } from "@bcheidemann/tracing"; * * class Example { * @instrument(log(Level.TRACE)) * test() { * // ... * } * } * ``` * * @example Instrument a function and log a message when entering, exiting, or when an error occurs * ```ts * import { instrumentCallback, log } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [log()], * function test() { * // ... * } * ); * * @example Instrument a function and log a message when entering, exiting, or when an error occurs (with level) * ```ts * import { instrumentCallback, log, Level } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [log(Level.TRACE)], * function test() { * // ... * } * ); * ``` */ export declare function log(level?: Level): LogAttribute; /** * The redact attribute is used to redact all or part of a parameter. It acts similarly to the skip attribute, but the * parameter (or field) is replaced with the string "[REDACTED]" in the logs. * * @example Instrument a method and redact a sensitive field * ```ts * import { instrument, redact } from "@bcheidemann/tracing"; * * class Example { * @instrument(redact("credentials", credentials => credentials.password)) * login(credentials) { * // ... * } * } * ``` * * @example Instrument a method and redact multiple sensitive fields * ```ts * import { instrument, redact } from "@bcheidemann/tracing"; * * class Example { * @instrument(redact( * "credentials", * credentials => [credentials.email, credentials.password], * )) * login(credentials) { * // ... * } * } * ``` * * @example Instrument a method and redact a parameter * ```ts * import { instrument, redact } from "@bcheidemann/tracing"; * * class Example { * @instrument(redact("credentials")) * login(credentials) { * // ... * } * } * ``` * * @param param The parameter name or index to skip. * @param redact Used to specify one or more fields to redact. If omitted, the whole parameter will be redacted. */ export declare function redact(param: string | number, redact?: (param: RedactProxy) => RedactProxy | RedactProxy[]): RedactAttribute; declare const REDACT_PROXY_PATH_SYMBOL: unique symbol; /** * The subscriber data attribute is used to attach subscriber specific data to * a span. * * @example Instrument a method and redact a sensitive field * ```ts * import { instrument, redact } from "@bcheidemann/tracing"; * import type { SpanKind } from "@opentelemetry/api"; * * class Controller { * @instrument(subscriberData({ otel: { kind: SpanKind.SERVER } })) * index() { * // ... * } * } * ``` * * @param subscriberData The subscriber specific data to set on the span. */ export declare function subscriberData(subscriberData: TSubscriberData): SubscriberDataAttribute; interface InstrumentDecorator { (target: TMethod, context: ClassMethodDecoratorContext, TMethod>): TMethod; (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; } /** * The instrument decorator is used to instrument a class method. This will create a span when the method * is entered. By default, the span message will be the name of the method, and the arguments will be included * in the fields. This behaviour can be customised using attributes. * * @example Instrument a method * ```ts * import { instrument } from "@bcheidemann/tracing"; * * class Example { * @instrument() * test() { * // ... * } * } * ``` * * @example Instrument a method with a custom message * ```ts * import { instrument, message } from "@bcheidemann/tracing"; * * class Example { * @instrument(message("Custom message")) * test() { * // ... * } * } * ``` * * @param attributes The attributes to use for the instrumented method * @returns The instrument decorator */ export declare function instrument(...attributes: Attributes, ReturnType>[]): InstrumentDecorator; /** * The instrumentCallback function is used to instrument a function. This will create a span when the function * is entered. By default, the span message will be the name of the function, and the arguments will be included * in the fields. This behaviour can be customised using attributes. * * @example Instrument a function * ```ts * import { instrumentCallback } from "@bcheidemann/tracing"; * * const test = instrumentCallback(function test() { * // ... * }); * ``` * * @example Instrument a function with a custom message * ```ts * import { instrumentCallback, message } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [message("Custom message")], * function test() { * // ... * } * ); * ``` * * @param fn The function to instrument * @returns The instrumented function */ export declare function instrumentCallback(fn: TCallback): TCallback; /** * The instrumentCallback function is used to instrument a function. This will create a span when the function * is entered. By default, the span message will be the name of the function, and the arguments will be included * in the fields. This behaviour can be customised using attributes. * * @example Instrument a function * ```ts * import { instrumentCallback } from "@bcheidemann/tracing"; * * const test = instrumentCallback(function test() { * // ... * }); * ``` * * @example Instrument a function with a custom message * ```ts * import { instrumentCallback, message } from "@bcheidemann/tracing"; * * const test = instrumentCallback( * [message("Custom message")], * function test() { * // ... * } * ); * ``` * * @param attributes The attributes to apply to the instrumented function * @param fn The function to instrument * @returns The instrumented function */ export declare function instrumentCallback(attributes: Attributes, ReturnType>[], fn: TCallback): TCallback; export {}; //# sourceMappingURL=instrument.d.ts.map