Skip to content

[BUG] ignoreHeaders as part of config does not build with typescript #2336

Closed
@aviita

Description

Description/Screenshot
Reading Application Insights Javascript SDK configuration documentation I understood that ignoreHeaders can be given as part of config to limit headers being included to dependency telemetry in case of enableResponseHeaderTracking being enabled.

The documentation explicitly state:

These configuration fields are optional and default to false unless otherwise stated.

For instructions on how to add SDK configuration, see Add SDK configuration.

And in the add sdk configuration documentation:

The optional SDK configuration is passed to the Application Insights JavaScript SDK during initialization.

To add SDK configuration, add each configuration option directly under connectionString.

Steps to Reproduce
With node v18.18.1 and npm 9.8.1

  1. Checkout repo: https://github.com/aviita/react-typescript-app-application-insights-ignore-headers-bug.git
  2. Run npm run build or see eslint output for telemetry.ts.

So the repro is in the app in github. Using

Firstly I also tried updating my app insights web and react js packages with:

npm i @microsoft/applicationinsights-react-js@latest @microsoft/applicationinsights-web@latest

How I try to init:

import {
  ApplicationInsights,
  ITelemetryItem,
} from "@microsoft/applicationinsights-web";
import { ReactPlugin } from "@microsoft/applicationinsights-react-js";
import { createBrowserHistory } from "history";

const history = createBrowserHistory();

const reactPlugin = new ReactPlugin();

const appInsights = new ApplicationInsights({
  config: {
    connectionString: process.env.VITE_APP_AI_INSTRUMENTATION_CONNECTION_STRING,
    disableFetchTracking: false,
    //enableRequestHeaderTracking: true, // Enable to get request headers in dependency logs
    enableResponseHeaderTracking: true, // Enable to get response headers in dependency logs
    ignoreHeaders: [
      "Authorization",
      "X-API-Key",
      "WWW-Authenticate",
      "date",
      "x-ms-blob-type",
      "x-ms-lease-status",
      "x-ms-request-id",
      "x-ms-version",
      "content-type",
      "X-Powered-By",
      "X-Firefox-Spdy",
      "Set-Cookie",
      "Request-Context",
      "Content-Encoding",
      "Access-Control-Allow-Origin",
      "Content-Encoding",
      "Vary",
    ], // Ignore these headers in dependency logs
    disableAjaxTracking: false,
    enableCorsCorrelation: true,
    extensions: [reactPlugin /* debugPluginInstance */],
    extensionConfig: {
      [reactPlugin.identifier]: {
        history,
      },
      /*
        [DebugPlugin.identifier]: {
          trackers: toTrack
        }
        */
    },
  },
});

appInsights.loadAppInsights();
export { reactPlugin, appInsights };

Expected behavior

  • ignoreHeaders can be passed as a parameter to config
  • ignoreHeaders is documented clearly.

Actual behvior:
Currently I get build error on npm run build:

Object literal may only specify known properties, and 'ignoreHeaders' does not exist in type 'IConfiguration & IConfig'.ts(2353)

Additional context
I would like to be able to include some specific headers to my dependency telemetry from our react app. I am specifically interested in X-Cache, cache-control and Content-Length headers to se relevant data to determine if our caching configuration needs improvement or if we should do improvements to our backend performance (Azure Storage Account tier selection in this case).

It would also be nice to have rather an include headers clause than exclude headers in our case, but anyways I can work with this if I figure out how to get it working.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions