NextJS根据ENV激活DataDogrum
我们目前有多种环境,我们只想启动DataDogrum以进行生产。
在_app.tsx中,我尝试了这样的事情:
import { datadogRum } from '@datadog/browser-rum';
if (process.env.NODE_ENV=== 'production') {
datadogRum.init({...});
datadogRum.startSessionReplayRecording();
}
但是这是不起作用的,因为这里没有env变量...
您对此有任何工作吗?
We currently have multiple environments and we would like to init datadogRum only for production.
In the _app.tsx I tried something like this :
import { datadogRum } from '@datadog/browser-rum';
if (process.env.NODE_ENV=== 'production') {
datadogRum.init({...});
datadogRum.startSessionReplayRecording();
}
But this is not working because env variables are not available here ...
Do you have any work around for this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我成功使用@BWest评论。
我使用nextjs
getInitialProps
是为了传输我的env变量。然后,我将我的datadog init代码放在
useffect(()=> {...},[])
hook中仅执行代码一次。I succeed using @bwest comment.
I used nextJs
getInitialProps
in order to transmit my env variable.And I put my datadog init code in a
useEffect(() => {...} , [])
hook to only execute the code once.使用NextJS环境变量可用于前端代码。
它们将使用某些WebPack插件(例如EnvironmentPlugin或DefinePlugin)在您的代码中进行插值。
从此
With nextjs environment variables can be available to front-end code.
They will be interpolated inside your code using some webpack plugin (something like EnvironmentPlugin or DefinePlugin).
From this Nextjs documentation: