Node.js 将请求头添加到节点中的Azure Application Insights事件

Node.js 将请求头添加到节点中的Azure Application Insights事件,node.js,azure,azure-application-insights,hapijs,Node.js,Azure,Azure Application Insights,Hapijs,Azure Application Insights节点模块默认收集HTTP请求,但是,这些事件似乎不包括请求的头 如何在这些事件中最好地包含标题 您可以添加一个自定义遥测处理器来执行此操作 下面是一个例子: const logHTTPheaders = (envelope, context) => { const httpRequest = context['http.ServerRequest']; if (httpRequest && appInsights

Azure Application Insights节点模块默认收集HTTP请求,但是,这些事件似乎不包括请求的头

如何在这些事件中最好地包含标题


您可以添加一个自定义遥测处理器来执行此操作

下面是一个例子:

const logHTTPheaders = (envelope, context) => {
  const httpRequest = context['http.ServerRequest'];
  if (httpRequest && appInsights.Contracts.domainSupportsProperties(envelope.data.baseData)) {
    _.forOwn(httpRequest.headers, (headerValue, headerName) => {
      _.set(envelope, `data.baseData.properties.[header-${headerName}]`, headerValue);
    });
  }
  return true;
};

// Telemetry processor to record HTTP request header
appInsights.defaultClient.addTelemetryProcessor(logHTTPheaders);