Note: The first style of method declaration does NOT create methods on the class' prototype. The methods are created on the instance themselves at construction (and so just FYI the call to autoBind(this) are actually useless for classes which only use that style of declaration)
TODO: We should ensure that all methods we use as express route handlers are named to have nice usable traces
Solution
Provide a utility nameAnonymousMethods() to ensure all methods of an instance and its class are named (invoked at construction)
Update all router classes to ensure all methods are named
Updating the Router classes was done via the script below, which was then cleaned up on commit by eslint/prettier:
grep 'autoBind(this)' $(git grep Router | grep class | grep Router | cut -d: -f1) | cut -d: -f1 | while read f; do
echo 'import { nameAnonymousMethods } from "@root/utils/apm-utils"' > temp;
sed -E -e 's/autoBind\(this\)/nameAnonymousMethods(this);autoBind(this)/' "${f}" >> temp;
mv temp "${f}";
done
Verified on staging:
Tests
[ ] Load the CMS and perform some actions, all happy paths should work
[ ] Find a span for a Review compare, and verify the span name is compareDiff (NOT<anonymous>)
Problem
We have a lot of spans in APM traces which are
<anonymous>
. While not a deal breaker to get value out of APM, it is annoying.The anonymous functions are due to the way some methods are declared in classes, which is done to be able to specify types.
e.g. in
ReviewsRouter
, the assignment syntax creates anonymous methodswhile in
collectionPages
, this style of named method works:Note: The first style of method declaration does NOT create methods on the class' prototype. The methods are created on the instance themselves at construction (and so just FYI the call to
autoBind(this)
are actually useless for classes which only use that style of declaration)TODO: We should ensure that all methods we use as express route handlers are named to have nice usable traces
Solution
nameAnonymousMethods()
to ensure all methods of an instance and its class are named (invoked at construction)Updating the Router classes was done via the script below, which was then cleaned up on commit by eslint/prettier:
Verified on staging:
Tests
compareDiff
(NOT<anonymous>
)