What you will learn

  • Installing the @infrastack/otel NPM package
  • Setting up your environment
  • Instrumenting your application

Prerequisites

  • An infrastack.ai account to get your API key
  • A Nest.js application

Getting started

1

Install the NPM package

2

Prepare your environment

Export your API key as an environment variable.

export INFRASTACK_API_KEY=sk-1*************************f5af
3

Create instrumentation.ts

Create an instrumentation.ts file under the src folder.

instrumentation.ts
import { startOtel } from '@infrastack/otel';
startOtel({
  serviceName: 'nestjs-otel-example',
});

If you don’t provide a service name, we will create a random name for you.
4

Import the instrumentation module in your main.ts file

main.ts
import './instrumentation';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(8081);
  console.log('Server is running on port 8081');
}
bootstrap();
5

Run your application

Run your Nest.js application with the default Nest.js command.

npm run start
After creating some traffic, you can check your data from the infrastack.ai dashboard.

Next steps