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
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!
For Nestjs monorepo, I faced the exact issue. I placed the newrelic.js [not newrelic.ts] file in the root directory [to the most directory of the project] and the issue was resolved. Try this and comment here about the result!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.