Last active
May 28, 2025 03:54
-
-
Save stormslowly/ccaac467cde60337eda534886f25ae7e to your computer and use it in GitHub Desktop.
javascript promise trace helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { JavaScriptTracer } from "./trace"; | |
import { randomUUID } from "crypto"; | |
function withTracer<A extends any[], P>( | |
eventName: string, | |
fn: (...args: A) => Promise<P> | |
) { | |
return (...args: A) => { | |
let g = randomUUID(); | |
JavaScriptTracer.startAsync({ | |
name: eventName, | |
args: { | |
id2: args[0] as unknown as string | |
}, | |
id2: { | |
global: g | |
} | |
}); | |
return fn(...args).finally(() => { | |
JavaScriptTracer.endAsync({ | |
name: eventName, | |
args: { | |
id2: args[0] as unknown as string | |
}, | |
id2: { | |
global: g | |
} | |
}); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment