Nest.js
Send distributed traces to Last9 from an Nest.js app using OpenTelemetry
Nest.js is a progressive Node.js framework for building efficient, reliable, scalable server-side applications. This comprehensive guide will help you instrument your Nest.js application with OpenTelemetry, seamlessly sending the traces to Last9.
You can also check out the example application on GitHub↗.
Pre-requisites
- You have a Nest.js application.
- You have signed up for Last9, created a cluster, and obtained the following OTLP credentials from the Integrations page:
endpoint
auth_header
Install OpenTelemetry packages
To perform the instrumentation, install the following OpenTelemetry packages.
To know more about them, you can check: https://opentelemetry.io/docs/languages/js/libraries/
Setup auto-instrumentation using OpenTelemetry
Add the necessary environment variables that can be obtained from the Integrations page.
Next, create a file named instrumentation.ts
and add the following code:
This above code performs the following steps:
- Set up Trace Provider with the application’s name as Service Name.
- Set up OTLP Exporter with Last9 OTLP endpoint.
- Set up auto instrumentation.
Next, the script should be “required” in the main.ts
file to start the instrumentation.
Visualize the traces in Last9
Once the application runs with the above code, it pushes traces to Last9. You can see the result in action by looking at the APM dashboard in Last9.
Troubleshooting
Please get in touch with us on Discord or Email if you have any questions.