Created
May 5, 2023 16:24
-
-
Save sibelius/55dda37a9b386fc3dbb6e3af837907fb to your computer and use it in GitHub Desktop.
monkeyPatchAggregateApm
This file contains 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
export const monkeyPatchAggregateApm = (M: Model<any>) => { | |
const aggregate = M.aggregate; | |
M.aggregate = async (pipeline: Array<any>) => { | |
const spanName = `${M.collection.collectionName}.aggregate`; | |
const span = apm.startSpan(spanName); | |
if (span) { | |
span.setLabel('pipeline', JSON.stringify(pipeline)); | |
} | |
const result = await aggregate(pipeline).allowDiskUse(true); | |
if (span) { | |
span.end(); | |
} | |
return result; | |
}; | |
return M; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment