var newrelic = require('newrelic');
var app = require('express')();
// in express, this lets you call newrelic from within a template
app.locals.newrelic = newrelic;
app.get('/user/:id', function (req, res) {
res.render('user');
});
app.listen(process.env.PORT);
layout.jade
doctype html
html
head
!= newrelic.getBrowserTimingHeader()
title= title
link(rel='stylesheet', href='stylesheets/style.css')
body
block content
1 回答
New Relic for Node要求应用程序使用HTML模板库来注入标头 .
他们在这里有完整的文档:https://docs.newrelic.com/docs/agents/nodejs-agent/supported-features/page-load-timing-nodejs
要看的重要部分是示例 . 这些来自使用Express和Jade的示例文档:
app.js
layout.jade
newrelic
模块设置用于模板的应用程序本地的块是重要的位:app.locals.newrelic = newrelic;
.'s simply no way to run something in a static file the way Express' s static 模块默认工作 . 它几乎直接流式传输静态文件的文本内容 .