Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created May 5, 2023 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibelius/55dda37a9b386fc3dbb6e3af837907fb to your computer and use it in GitHub Desktop.
Save sibelius/55dda37a9b386fc3dbb6e3af837907fb to your computer and use it in GitHub Desktop.
monkeyPatchAggregateApm
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