【问题标题】:Adding Request Headers to Azure Application Insights Events in Node向 Node 中的 Azure Application Insights 事件添加请求标头
【发布时间】:2019-04-10 18:17:47
【问题描述】:

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

我应该如何最好地在这些事件中包含标题?

https://github.com/Microsoft/ApplicationInsights-node.js

【问题讨论】:

    标签: node.js azure azure-application-insights hapijs


    【解决方案1】:

    您可以添加自定义遥测处理器来执行此操作 https://github.com/Microsoft/ApplicationInsights-node.js/blob/44330896f58d4e6c2b6c4fec821430f7e1067138/README.md#preprocess-data-with-telemetry-processors

    这是一个例子:

    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);
    

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 2021-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多