Tracing a NestJS Application
Recap.Dev provides two levels of tracing: basic tracing and function-level tracing.
Basic tracing collects request, response and error information, logs, and provides a timeline of external resource access (databases, HTTP endpoints, external services) of your unit (basically, endpoint or handler).
Function-level tracing also adds timings of the individual function calls to the timeline.
#
Setting up a Basic Tracing#
1. Install the Recap.Dev Client Libraryor
#
2. Enable the NestJS TracingCall the initNestJsTracing
function before creating your NestJS app.
You may also pass these options to the initNestJsTracing
function:
- captureLogs - Enables or disables capture of logs from global console object. Defaults to true.
- disableAutomaticUnitNames - Disables default
environment-injectable.methodName
unit names. Defaults to false. - ignoreUnnamedUnits - Ignore traces without a unit name. Useful if you want to ignore requests to static assets or only trace particular modules. Defaults to true.
- assignUnitName - Defines a unit name for a trace.
The default strategy creates a unit name using a first injectable method appearing in the chain and an environment.
An example of the unit name generated is
local-CatFactsResolver.catFacts
#
3. Wrap NestJS Modules to Trace ThemWrap a NestJS module with wrapNestJsModule
function exported from the @recap.dev/client
to trace it with Recap.Dev.
RECAP_DEV_SYNC_ENDPOINT
environment variable to point at your Recap.Dev server's sync endpoint, for example:#
4. Set the Check the complete source code of an example NestJS project traced with Recap.Dev here.
#
Setting up a Function-level TracingClick here to learn how to set up the function-level tracing for your application.