Newrelic configuration not being read from the newrelic.ts on Nrwl Nx NestJs

Viewed 31

I have an issue where my newrelic configuration is not being read by my NestJs app. Just an extra info, my NestJs app is part of a Nrwl Nx monorepo.

newrelic.ts is in the same folder as the main.ts

Newrelic ts in same folder as main ts

Error thrown was:

Error: New Relic requires that you name this application!
Set app_name in your newrelic.js file or set environment variable
NEW_RELIC_APP_NAME. Not starting!

I did install "newrelic": "9.0.3",

I also tried to initiate newrelic before the rest of application gets bootstrapped by calling the require on the top of main.ts

// @ts-ignore
const newrelic = require('newrelic');

import { INestApplication, Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';
import { NewrelicInterceptor } from './app/interceptors/newrelic.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors({
    origin: process.env.CORS_ORIGIN?.split(','),
    credentials: true,
  });
  setupNewRelicInterceptor(app);
  const port = process.env.PORT || 8080;
  await app.listen(port);
  Logger.log(` Application is running on: http://localhost:${port}`);
}

function setupNewRelicInterceptor(app: INestApplication) {
  app.useGlobalInterceptors(new NewrelicInterceptor());
  Logger.log(`New Relic Interceptor Added`);
}

bootstrap();

If I pass the configuration as environment variables, it works, but that is not what I intended to do at the moment.

Really appreciate the help if anyone can point out where the issue is. Cheers!

0 Answers
Related