1.0.6 • Published 4 years ago

applicationinsights-httpheaderfilter-js v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Application Insights HTTP Header Filtering Extension

Getting Started

Add The filter to your app.

Note: Typings are included with this package, so you do not need to install a separate typings package.

npm i --save applicationinsights-httpheaderfilter-js

Basic usage

This Application Insights extension allows for filtering HTTP headers flowing into telemetry. Setup is easy:

import {HttpHeaderFilterPlugin} from 'applicationinsights-httpheaderfilter-js';

or using require:

const httpheaderFilter = require('applicationinsights-httpheaderfilter-js');

then:

const filteringPlugin = new httpheaderFilter.HttpHeaderFilterPlugin();
const appInsights = new ApplicationInsights({ config: {
    /* ... */
    extensions = [filteringPlugin];
    extensionConfig = {
        [filteringPlugin.identifier]: {
            filteredHeaders: {
            Authorization: [ /^(.*?) .*$/gi, '$1 **TOKEN REMOVED**' ],
            'Content-Type': [ 'something replacing content-type' ],
            'Request-Id': null,
            }
        }
    }
 });

appInsights.loadAppInsights();
/* ... */

Configuration options

The plugin scans the HTTP headers send to the telemetry server. It scans the headers using case-insensitive matching.

It can do three things:

  1. Replace the value of the matching regular expression with another regular expression.

    Authorization: [ /^(.*?) .*$/gi, '$1 **TOKEN REMOVED**' ]

    This expression matches anything for the Authorization header and captures what is in front of the first space character (typically, the type of authorization, i.e. Bearer, Basic, see explanation)

    Notice the two elements in the array for the Authorization property. The first is used as the match and capture for the original value, the second is the replacement value.

  2. Replace the value of the matching regular expression with a hardcoded value.

    'Content-Type': [ 'application/json' ]

    This way, the HTTP header Content-Type is replaced, just as an example.

  3. Remove the value.

    'Request-Id': null

    The HTTP header will be removed by the filter, and won't show in Application Insights telemetry.

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago