Koa
Send distributed traces to Last9 from a Koa app using OpenTelemetry
Koa is a web framework for Node.js. This comprehensive guide will help you instrument your Koa application with OpenTelemetry, seamlessly sending the traces to Last9.
You can also check out the example application on GitHub↗.
Pre-requisites
- You have a Koa 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 for all the supported libraries.
Next, this script must be imported at the application’s entry point, even before importing koa
package. For instance, if you have server.ts
as your entry file, then import it at the top of the file as follows:
Visualize the traces in Last9
Once the application runs with the above code, it will start pushing 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.