Automatic Tracing Decorator #1383
Unanswered
NickSeagull
asked this question in
Refactors and standards
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction
By using a decorator in all of our service classes (#1381 ) we can benefit from automatic augmentation of the capabilities of these.
The most important one, perhaps, is to the Automatic Tracing capability, which would enable instrumentation and monitoring of Booster applications, and even the CLI, in case we want to track anonymous data of the usage of Booster.
Although this sounds complicated, it really isn't. The key is to use a JavaScript Proxy Object that wraps all the methods of the decorated class, and then act on the arguments, method name, and output.
Naive implementation
The following code is long, but mainly because I've added error handler code and checks to ensure nothing is missing.
For instance, if we wanted to implement a decorator like this, that logs all method calls, and also the errors, it would be like:
Issues with this approach
The issue with this implementation is that:
The solution
Remove the constraints
HasLogger
andHasCatchMethod
, and instead use OpenTelemetry.OpenTelemetry has a singleton tracer instance that you can get from any part of the code, and has a lot of configuration options and plugins that don't require us to implement everything ourselves.
Also, on top of that, it has a span feature that allows delimiting the start and the end of a process, which is extremely useful for this to delimit the start and the end of method calls.
Related discussions
Beta Was this translation helpful? Give feedback.
All reactions