npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

applicationinsights-telemetryfilter

v1.0.5

Published

Provides an Application Insights extension which filters out configured telemetry before sending

Downloads

7

Readme

Application Insights Telemetry 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-telemetryfilter

Basic usage

This Application Insights extension allows for filtering HTTP headers and URLs from the 'name' and 'data' properties flowing into telemetry. Setup is easy:

import { TelemetryFilterPlugin } from './applicationinsights-telemetryfilter';

or using require:

const telemetryFilterPlugin = require('applicationinsights-telemetryfilter');

then:

const filteringPlugin = new telemetryFilterPlugin.TelemetryFilterPlugin();
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,
            },
            filteredName: [ /^(.*?) .*$/gi, '$1 **NAME URL REMOVED**' ],
            filteredData: [ /^(.*?) .*$/gi, '$1 **DATA URL REMOVED**' ]
        }
    }
 });

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

Configuration options

The plugin scans the HTTP headers, as well as the 'name' and 'data' properties send to the telemetry server. It scans the headers using case-insensitive matching.

It can do three things for those three items:

  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. The same goes for URLs in the 'name' and 'data' properties of the telemetry.

Testing

The filter has tests, simply run

npm test