unnbound-logger-sdk
Version:
A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.
21 lines (20 loc) • 713 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withTrace = withTrace;
/**
* Utility function to wrap a function with trace context
*/
const uuid_1 = require("uuid");
const trace_context_1 = require("./trace-context");
/**
* Higher-order function that wraps a function with trace context
* @param fn - Function to wrap with trace context
* @param traceId - Optional trace ID to use (will generate new one if not provided)
* @returns Wrapped function that maintains trace context
*/
function withTrace(fn, traceId) {
const id = traceId || (0, uuid_1.v4)();
return ((...args) => {
return trace_context_1.traceContext.run(id, () => fn(...args));
});
}