@@ -10,15 +10,23 @@ export const initTimers = function () {
1010 return [ ]
1111}
1212
13+ type MeasureDurationOptions = {
14+ metricName ?: string
15+ parentTag ?: string
16+ category ?: string
17+ tags ?: string [ ]
18+ }
19+
1320// Wrap an async function to measure how long it takes.
1421// The function must:
1522// - take a plain object as first argument. This must contain a `timers`.
1623// - return a plain object. This may or may not contain a modified `timers`.
1724// The `durationNs` will be returned by the function. A new `timers` with the
1825// additional duration timer will be returned as well.
19- const kMeasureDuration = function ( func , stageTag , { parentTag = undefined , category = undefined } = { } ) {
26+ const kMeasureDuration = function ( func , stageTag , options : MeasureDurationOptions = { } ) {
2027 return async function measuredFunc ( { timers, ...opts } , ...args ) {
2128 const timerNs = startTimer ( )
29+ const { parentTag, category } = options
2230 const { timers : timersA = timers , ...returnObject } = await func ( { timers, ...opts } , ...args )
2331 const { tags = { } } = returnObject
2432 const durationNs = endTimer ( timerNs )
@@ -41,7 +49,12 @@ export const measureDuration = keepFuncProps(kMeasureDuration)
4149export const createTimer = function (
4250 stageTag ,
4351 durationNs ,
44- { metricName = DEFAULT_METRIC_NAME , parentTag = TOP_PARENT_TAG , category = undefined , tags = undefined } = { } ,
52+ {
53+ metricName = DEFAULT_METRIC_NAME ,
54+ parentTag = TOP_PARENT_TAG ,
55+ category = undefined ,
56+ tags = undefined ,
57+ } : MeasureDurationOptions = { } ,
4558) {
4659 return { metricName, stageTag, parentTag, durationNs, category, tags }
4760}
0 commit comments