I have an application in NodeJS and ExpressJS with redirects from one function to another. I would like to trace the sequence of redirects so I know how requests bounce from one function to another until the response is sent.
I tried adding an error in the function handling the last request, but this shows the stacktrace going into ExpressJS and processing events, not from one of my functions to another of my functions.
I could not find a middleware or a setting in the morgan
logger that prints the name of each function, or its line in the source code, when it gets called.
How can I trace all of my functions that respond to a request?
Note: this is different from How to get filename and line number of where a function is called in Node? because of redirects.
What you're looking for is Tracing. There is an industry standard called OpenTelemetry, which has a rich ecosystem of tools to generate and analyze. For your software to emit traces in OpenTelemetry format, you can set up an Instrumentation for JavaScript