Open ghost opened 10 months ago
You need to "force" nextjs to read the env variables from your file (i.e. .env.local
)
use 'strict'
import { loadEnvConfig } from '@next/env'
loadEnvConfig(process.cwd())
/**
* New Relic agent configuration.
*
* See lib/config/default.js in the agent distribution for a more complete
* description of configuration variables and their potential values.
*/
exports.config = {
/**
* Array of application names.
*/
app_name: ["GSF App 2 NextJS Web App"],
/**
/**
* Your New Relic license key.
*/
license_key: process.env.NEW_RELIC_LICENSE_KEY,
// ...
}
When I try use:
'use strict'
import { loadEnvConfig } from '@next/env'
loadEnvConfig(process.cwd())
exports.config = {
app_name: process.env.NEW_RELIC_APP_NAME,
license_key: process.env.NEW_RELIC_LICENSE_KEY,
distributed_tracing: {
enabled: true,
},
...
returns this error message:
(/home/node/node_modules/@newrelic/next/index.js:13:18)
2024-01-03T07:01:59.238-03:00 New Relic for Node.js was unable to bootstrap itself due to an error:
2024-01-03T07:01:59.243-03:00 Error: New Relic requires that you name this application!
2024-01-03T07:01:59.243-03:00 Set app_name in your newrelic.js or newrelic.cjs file or set environment variable
2024-01-03T07:01:59.243-03:00 NEW_RELIC_APP_NAME. Not starting!
2024-01-03T07:01:59.243-03:00 at createAgent (/home/node/node_modules/newrelic/index.js:160:11)
2024-01-03T07:01:59.243-03:00 at initialize (/home/node/node_modules/newrelic/index.js:105:15)
2024-01-03T07:01:59.243-03:00 at Object.<anonymous> (/home/node/node_modules/newrelic/index.js:39:3)
2024-01-03T07:01:59.243-03:00 at Module._compile (node:internal/modules/cjs/loader:1256:14)
2024-01-03T07:01:59.243-03:00 at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
2024-01-03T07:01:59.243-03:00 at Module.load (node:internal/modules/cjs/loader:1119:32)
2024-01-03T07:01:59.243-03:00 at Module._load (node:internal/modules/cjs/loader:960:12)
2024-01-03T07:01:59.243-03:00 at Module.require (node:internal/modules/cjs/loader:1143:19)
2024-01-03T07:01:59.243-03:00 at require (node:internal/modules/cjs/helpers:119:18)
2024-01-03T07:01:59.243-03:00 at Object.<anonymous> (/home/node/node_modules/@newrelic/next/index.js:13:18)
My .env.development
file looks like this:
NEW_RELIC_APP_NAME='my-next-application'
NEW_RELIC_LICENSE_KEY='my_key'
If your setup is like mine and you use dotenv
, then the following did the trick for me:
// newrelic.js
require('./src/configs/env');
Description
I'm trying to pull in my license_key into the
newrelic.js
file, but it won't read any of my environment variables. I get an error stating that:New Relic for Node.js halted startup due to an error:
Error: Not starting without license key!
my environment variables are stored in a file called
.env.local
Here's an example of my
newrelic.js
file:What I've tried to do
process.env.NEW_RELIC_LICENSE_KEY
require("dotenv").config();
, this then breaks the appnewrelic.js
file. But obviously, for security reasons, I don't want to do this.System Information