NestJS OpenTelemetry Instrumentation
Introduction to SigNoz for Nestjs​
SigNoz can help you monitor your Nestjs applications for application related metrics like latency, request per second, error rates, etc. It can also monitor infrastructure metrics like CPU utilization and memory usage.
You can set alerts on metrics of your choice to stay on top of any issues arising in your deployed application.
Getting started for Nestjs with SigNoz​
SigNoz uses OpenTelemetry for enabling your application code to generate telemetry data. OpenTelemetry provides a vendor-neutral specification to instrument your application so that you can export data to any backend of your choice, such as SigNoz.
Let us see how to instrument your application with OpenTelemetry, so that you can visualize the data with SigNoz.
Instrumenting a sample Nestjs application with OpenTelemetry​
Install below dependencies
"@opentelemetry/api": "^1.0.4",
"@opentelemetry/resources": "^1.0.4",
"@opentelemetry/auto-instrumentations-node": "^0.27.1",
"@opentelemetry/exporter-otlp-grpc": "^0.26.0",
"@opentelemetry/sdk-node": "^0.27.0",Create a
tracer.ts
fileThe
IP of SIgNoz
will be localhost if you are running SigNoz on local. If you are not running SigNoz on local machine, then please use the IP of the machine where SigNoz is installed.
'use strict'
const opentelemetry = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-grpc');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
// configure the SDK to export telemetry data to the console
// enable all auto-instrumentations from the meta package
const exporterOptions = {
url: 'http://<IP of SigNoz>:4317',
}
const traceExporter = new OTLPTraceExporter(exporterOptions);
const sdk = new opentelemetry.NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'sampleNestJsApp-local'
}),
traceExporter,
instrumentations: [getNodeAutoInstrumentations()]
});
sdk.start()
.then(() => console.log('Tracing initialized'))
.catch((error) => console.log('Error initializing tracing', error));
// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
.finally(() => process.exit(0));
});
module.exports = sdkImport the tracer module where your app starts
On
main.ts
file or file where your app starts import tracer using below command:const tracer = require('./tracer')
Start the tracer
await tracer.start();
You can now run your Nestjs application. The data captured with OpenTelemetry from your application should start showing on the SigNoz dashboard.
Testing with sample Nestjs application​
If you want to test out how SigNoz works with a sample Nestjs application, check out a sample Nestjs application at this GitHub repo.
Frequently Asked Questions​
How to find what to use in
IP of SigNoz
if I have installed SigNoz in Kubernetes cluster?Based on where you have installed your application and where you have installed SigNoz, you need to find the right value for this. Please use this grid to find the value you should use for
IP of SigNoz
I am sending data from my application to SigNoz, but I don't see any events or graphs in the SigNoz dashboard. What should I do?
This could be because of one of the following reasons:
Your application is generating telemetry data, but not able to connect with SigNoz installation
Please use this troubleshooting guide to find if your application is able to access SigNoz installation and send data to it.
Your application is not actually generating telemetry data
Please check if the application is generating telemetry data first. You can use
Console Exporter
to just print your telemetry data in console first. Join our Slack Community if you need help on how to export your telemetry data in consoleYour SigNoz installation is not running or behind a firewall
Please double check if the pods in SigNoz installation are running fine.
docker ps
orkubectl get pods -n platform
are your friends for this.