Skip to content

Commit

Permalink
Chore: Migrate to shared telemetry utilities
Browse files Browse the repository at this point in the history
Allows removing the significantly-sized client bundle from
Application Insights in favor of a minimal shared utility.
  • Loading branch information
antross authored and molant committed Nov 12, 2019
1 parent 618e13a commit c2f74dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 223 deletions.
4 changes: 2 additions & 2 deletions packages/extension-browser/package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"timeout": "1m" "timeout": "1m"
}, },
"browserslist": "last 2 chrome versions, last 2 firefox versions", "browserslist": "last 2 chrome versions, last 2 firefox versions",
"bundleSize": 675000, "bundleSize": 660000,
"description": "webhint browser extension", "description": "webhint browser extension",
"devDependencies": { "devDependencies": {
"@hint/hint-axe": "^4.2.0", "@hint/hint-axe": "^4.2.0",
Expand Down Expand Up @@ -46,8 +46,8 @@
"@hint/utils-dom": "^1.0.0", "@hint/utils-dom": "^1.0.0",
"@hint/utils-fs": "^1.0.0", "@hint/utils-fs": "^1.0.0",
"@hint/utils-i18n": "^1.0.0", "@hint/utils-i18n": "^1.0.0",
"@hint/utils-telemetry": "^1.0.0",
"@hint/utils-types": "^1.0.0", "@hint/utils-types": "^1.0.0",
"@microsoft/applicationinsights-web-basic": "^2.2.0",
"@types/chrome": "^0.0.91", "@types/chrome": "^0.0.91",
"@types/har-format": "^1.2.4", "@types/har-format": "^1.2.4",
"@types/is-ci": "^2.0.0", "@types/is-ci": "^2.0.0",
Expand Down
69 changes: 0 additions & 69 deletions packages/extension-browser/src/devtools/utils/activity.ts

This file was deleted.

44 changes: 16 additions & 28 deletions packages/extension-browser/src/devtools/utils/analytics.ts
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web-basic';

import { Config, ErrorData, Results } from '../../shared/types'; import { Config, ErrorData, Results } from '../../shared/types';


import { getUpdatedActivity } from './activity'; import { getUpdatedActivity, initTelemetry, updateTelemetry, trackEvent } from '@hint/utils-telemetry';
import { determineHintStatus } from './hints'; import { determineHintStatus } from './hints';
import * as storage from './storage'; import * as storage from './storage';


Expand All @@ -13,25 +11,21 @@ const alreadyOptInKey = 'webhint-already-opt-in';


const instrumentationKey = '8ef2b55b-2ce9-4c33-a09a-2c3ef605c97d'; const instrumentationKey = '8ef2b55b-2ce9-4c33-a09a-2c3ef605c97d';


let appInsights: ApplicationInsights | null = null; /** Check if telemetry is enabled */
export const enabled = (s = storage) => {
return !!s.getItem(storageKey);
};


const trackEvent = (name: string, properties: { [key: string]: string } = {}, measurements?: { [key: string]: number }) => { initTelemetry({
if (!appInsights) { defaultProperties: { 'extension-version': manifest.version },
return; enabled: enabled(),
} instrumentationKey,
post: async (url, data) => {
const response = await fetch(url, { body: data, method: 'POST' });


properties['extension-version'] = manifest.version; return response.status;

}
appInsights.track({ });
baseData: {
measurements,
name,
properties
},
baseType: 'EventData',
name: `Microsoft.ApplicationInsights.${instrumentationKey}.Event`
});
};


/** /**
* Return true if the user has not respond yet * Return true if the user has not respond yet
Expand All @@ -47,19 +41,13 @@ export const setup = (s = storage) => {


if (!telemetry) { if (!telemetry) {
console.log('telemetry disabled'); console.log('telemetry disabled');
appInsights = null; updateTelemetry(false);


return; return;
} }


console.log('telemetry enabled'); console.log('telemetry enabled');

updateTelemetry(true);
appInsights = new ApplicationInsights({ instrumentationKey });
};

/** Check if telemetry is enabled */
export const enabled = (s = storage) => {
return !!s.getItem(storageKey);
}; };


/** Enables telemetry */ /** Enables telemetry */
Expand Down
90 changes: 0 additions & 90 deletions packages/extension-browser/tests/devtools/utils/activity.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/extension-browser/tsconfig.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
{ "path": "../utils-dom" }, { "path": "../utils-dom" },
{ "path": "../utils-fs" }, { "path": "../utils-fs" },
{ "path": "../utils-i18n" }, { "path": "../utils-i18n" },
{ "path": "../utils-telemetry" },
{ "path": "../utils-types" } { "path": "../utils-types" }
] ]
} }
35 changes: 1 addition & 34 deletions yarn.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -365,39 +365,6 @@
dependencies: dependencies:
arrify "^1.0.1" arrify "^1.0.1"


"@microsoft/applicationinsights-channel-js@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-channel-js/-/applicationinsights-channel-js-2.2.0.tgz#3a424729c0176288e79db8e1b3478ce3e7fa8a9d"
integrity sha512-o67F1YVSXGyjZhMDrZQRzWJK0mH4Qm6YphG12ZVbdgQZeoouI4uoIDHxOOuIi4GLNdX8w59k8Wy2tnxFQbPY8A==
dependencies:
"@microsoft/applicationinsights-common" "2.2.0"
"@microsoft/applicationinsights-core-js" "2.2.0"
tslib "^1.9.3"

"@microsoft/applicationinsights-common@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-common/-/applicationinsights-common-2.2.0.tgz#12e81cca220450d16129fea4f16e3212efbfd32e"
integrity sha512-4zFUD4y8ekJ8tZSK2k5Ij6pvWYGFIcH8RoHKlkm7D+mO7vGkvR9dF7hJEJ/eliCtETbEJeNw/wi8TCxvc6oHkA==
dependencies:
"@microsoft/applicationinsights-core-js" "2.2.0"
tslib "^1.9.3"

"@microsoft/applicationinsights-core-js@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-core-js/-/applicationinsights-core-js-2.2.0.tgz#80b3352367834447499c0324ccddd1264d1770b4"
integrity sha512-+96gffh7TfYho8J0Oaxr9SUtUr0SwWMPArCMngnqqY5gcgNu9LaiVt/e/gsz8kKEuLb3m2+d22mmHb2fwpxMbQ==
dependencies:
tslib "^1.9.3"

"@microsoft/applicationinsights-web-basic@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@microsoft/applicationinsights-web-basic/-/applicationinsights-web-basic-2.2.0.tgz#85388f593239f264839b0e8fd5cd3dd47b7eb913"
integrity sha512-16IjDsmbnpWxQFOMrEliKWqWqXYEdMOjsqHEn96F3JSuJgsSN3f+ufURTfaiEbCwkgvSAjlaSIICYg2SqJGXPg==
dependencies:
"@microsoft/applicationinsights-channel-js" "2.2.0"
"@microsoft/applicationinsights-common" "2.2.0"
"@microsoft/applicationinsights-core-js" "2.2.0"

"@mrmlnc/readdir-enhanced@^2.2.1": "@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1" version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
Expand Down Expand Up @@ -11623,7 +11590,7 @@ ts-loader@^6.1.2:
micromatch "^4.0.0" micromatch "^4.0.0"
semver "^6.0.0" semver "^6.0.0"


tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: tslib@^1.8.1, tslib@^1.9.0:
version "1.10.0" version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
Expand Down

0 comments on commit c2f74dc

Please sign in to comment.