-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve APM spans (no more <anonymous>) (#1267)
* refactor: rename wrapper based on original function, only when original.name exists * feat: utility to name all methods of an object * feat: ensure all route handlers are named * feat: drop the bound prefix in span names * chore: remove unused eslint rule disabling --------- Co-authored-by: Alexander Lee <[email protected]>
- Loading branch information
1 parent
a453b9f
commit ccde289
Showing
12 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
/** | ||
* A function to set the name of anonymous methods on an object, all the way into the prototype chain | ||
* This is useful to be reported in APM traces and spans | ||
* This is an unconventional thing to do, so we have to disable a couple of eslint rules | ||
*/ | ||
export const nameAnonymousMethods = <SelfType extends { [key: string]: any }>( | ||
self: SelfType | ||
): SelfType => { | ||
/* eslint-disable no-restricted-syntax */ | ||
/* eslint-disable no-continue */ | ||
for (const methodName in self) { | ||
if (methodName === "constructor") continue | ||
|
||
const method = self[methodName] | ||
if (typeof method !== "function") continue | ||
if (method.name) continue | ||
|
||
Object.defineProperty(method, "name", { | ||
value: methodName, | ||
writable: false, | ||
}) | ||
} | ||
return self | ||
} |