[Beta] [BUG] SharedWorker does not Instrument fetch correctly #1996

- Also add a Shared Worker example
This commit is contained in:
Nev Wylie 2023-02-22 18:51:26 -08:00
Родитель 073c0aaf26
Коммит 73cebfe8bd
19 изменённых файлов: 1153 добавлений и 119 удалений

Просмотреть файл

@ -15,11 +15,11 @@
ms.topic="article"
ms.date="08/24/2015"/>
[![Build Status](https://dev.azure.com/mseng/AppInsights/_apis/build/status/AppInsights%20-%20DevTools/1DS%20JavaScript%20SDK%20web%20SKU%20vNext?branchName=master)](https://dev.azure.com/mseng/AppInsights/_build/latest?definitionId=8184&branchName=master)
[![Build Status](https://travis-ci.org/microsoft/ApplicationInsights-JS.svg?branch=master)](https://travis-ci.org/microsoft/ApplicationInsights-JS)
![GitHub Workflow Status (main)](https://img.shields.io/github/actions/workflow/status/microsoft/ApplicationInsights-JS/ci.yml?branch=master)
[![npm version](https://badge.fury.io/js/%40microsoft%2Fapplicationinsights-web.svg)](https://badge.fury.io/js/%40microsoft%2Fapplicationinsights-web)
[![minified size size](https://img.badgesize.io/https://js.monitor.azure.com/scripts/b/ai.2.min.js.svg?label=minified%20size)](https://img.badgesize.io/https://js.monitor.azure.com/scripts/b/ai.2.min.js.svg?label=minified%20size)
[![gzip size](https://img.badgesize.io/https://js.monitor.azure.com/scripts/b/ai.2.min.js.svg?compression=gzip&softmax=30000&max=35000)](https://img.badgesize.io/https://js.monitor.azure.com/scripts/b/ai.2.min.js.svg?compression=gzip&softmax=30000&max=35000)
[![Build Status](https://dev.azure.com/mseng/AppInsights/_apis/build/status/AppInsights%20-%20DevTools/1DS%20JavaScript%20SDK%20web%20SKU%20vNext?branchName=master)](https://dev.azure.com/mseng/AppInsights/_build/latest?definitionId=8184&branchName=master)
[![minified size size](https://img.badgesize.io/https://js.monitor.azure.com/scripts/b/ai.2.min.js.svg?label=minified%20size)](https://js.monitor.azure.com/scripts/b/ai.2.min.js)
[![gzip size](https://img.badgesize.io/https://js.monitor.azure.com/scripts/b/ai.2.min.js.svg?compression=gzip&softmax=30000&max=35000)](https://js.monitor.azure.com/scripts/b/ai.2.min.js)
## Beta (v3.x) Release Breaking changes

260
common/config/rush/npm-shrinkwrap.json сгенерированный
Просмотреть файл

@ -26,6 +26,7 @@
"@rush-temp/applicationinsights-core-js": "file:./projects/applicationinsights-core-js.tgz",
"@rush-temp/applicationinsights-debugplugin-js": "file:./projects/applicationinsights-debugplugin-js.tgz",
"@rush-temp/applicationinsights-dependencies-js": "file:./projects/applicationinsights-dependencies-js.tgz",
"@rush-temp/applicationinsights-example-shared-worker": "file:./projects/applicationinsights-example-shared-worker.tgz",
"@rush-temp/applicationinsights-js-release-tools": "file:./projects/applicationinsights-js-release-tools.tgz",
"@rush-temp/applicationinsights-perfmarkmeasure-js": "file:./projects/applicationinsights-perfmarkmeasure-js.tgz",
"@rush-temp/applicationinsights-properties-js": "file:./projects/applicationinsights-properties-js.tgz",
@ -333,9 +334,9 @@
}
},
"node_modules/@nevware21/ts-async": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@nevware21/ts-async/-/ts-async-0.1.1.tgz",
"integrity": "sha512-NvR4toK+8qGIFvRTB3ZodLhwzSvtoNUcb+bfbY1+vBy1IkbKg9fcZ/5cWQrgL9bwfrQ8kroNbbRPV6mjczB+jw==",
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@nevware21/ts-async/-/ts-async-0.1.2.tgz",
"integrity": "sha512-NCXzmG+HnkvyduMypWjMn1nZcQLMp3b2nZdt3RJuKZgRrcwCI2ZWcNt3XAfTEMiT+FbZx6htTs/JgWu3m0yZAw==",
"dependencies": {
"@nevware21/ts-utils": ">= 0.7 < 2.x"
},
@ -344,9 +345,9 @@
}
},
"node_modules/@nevware21/ts-utils": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.7.2.tgz",
"integrity": "sha512-eqkL8vHgeuGkjouEHGD3Hi156IBqflFFT8k1UzWg5xEdjQ0tFEQfOjhAeja0fFC6hrL2lHlIHt16stDtag+QCg==",
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.8.0.tgz",
"integrity": "sha512-MKDEZakdmPT0flCbgYSkXzVrmwqOGTBCmK7AkxvxuOedsekHKPyqUYX2WTKu9SjfnlsNX1DqjTNWcLy8h8g0Xg==",
"peerDependencies": {
"typescript": ">=1"
}
@ -693,6 +694,32 @@
"typescript": "^4.9.3"
}
},
"node_modules/@rush-temp/applicationinsights-example-shared-worker": {
"version": "0.0.0",
"resolved": "file:projects/applicationinsights-example-shared-worker.tgz",
"integrity": "sha512-aIL4qvg/bjQOniMml+en/LfOa1mNHRaJXtyNFkMu1MqFSsPgH1L6Sg/fWJhkh/+TEPyDt6+QboKMqBeDs4mihQ==",
"dependencies": {
"@microsoft/dynamicproto-js": "^1.1.7",
"@nevware21/grunt-eslint-ts": "^0.2.2",
"@nevware21/grunt-ts-plugin": "^0.4.3",
"@nevware21/ts-utils": ">= 0.7 < 2.x",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.3.3",
"globby": "^11.0.0",
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-qunit": "^6.2.1",
"magic-string": "^0.25.7",
"pako": "^2.0.3",
"qunit": "^2.11.2",
"rollup": "^2.32.0",
"rollup-plugin-cleanup": "^3.2.1",
"sinon": "^7.3.1",
"tslib": "^2.0.0",
"typescript": "^4.9.3"
}
},
"node_modules/@rush-temp/applicationinsights-js-release-tools": {
"version": "0.0.0",
"resolved": "file:projects/applicationinsights-js-release-tools.tgz",
@ -1188,14 +1215,14 @@
}
},
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.52.0.tgz",
"integrity": "sha512-lHazYdvYVsBokwCdKOppvYJKaJ4S41CgKBcPvyd0xjZNbvQdhn/pnJlGtQksQ/NhInzdaeaSarlBjDXHuclEbg==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.53.0.tgz",
"integrity": "sha512-alFpFWNucPLdUOySmXCJpzr6HKC3bu7XooShWM+3w/EL6J2HIoB2PFxpLnq4JauWVk6DiVeNKzQlFEaE+X9sGw==",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "5.52.0",
"@typescript-eslint/type-utils": "5.52.0",
"@typescript-eslint/utils": "5.52.0",
"@typescript-eslint/scope-manager": "5.53.0",
"@typescript-eslint/type-utils": "5.53.0",
"@typescript-eslint/utils": "5.53.0",
"debug": "^4.3.4",
"grapheme-splitter": "^1.0.4",
"ignore": "^5.2.0",
@ -1222,14 +1249,14 @@
}
},
"node_modules/@typescript-eslint/parser": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.52.0.tgz",
"integrity": "sha512-e2KiLQOZRo4Y0D/b+3y08i3jsekoSkOYStROYmPUnGMEoA0h+k2qOH5H6tcjIc68WDvGwH+PaOrP1XRzLJ6QlA==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.53.0.tgz",
"integrity": "sha512-MKBw9i0DLYlmdOb3Oq/526+al20AJZpANdT6Ct9ffxcV8nKCHz63t/S0IhlTFNsBIHJv+GY5SFJ0XfqVeydQrQ==",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "5.52.0",
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/typescript-estree": "5.52.0",
"@typescript-eslint/scope-manager": "5.53.0",
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/typescript-estree": "5.53.0",
"debug": "^4.3.4"
},
"engines": {
@ -1249,13 +1276,13 @@
}
},
"node_modules/@typescript-eslint/scope-manager": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.52.0.tgz",
"integrity": "sha512-AR7sxxfBKiNV0FWBSARxM8DmNxrwgnYMPwmpkC1Pl1n+eT8/I2NAUPuwDy/FmDcC6F8pBfmOcaxcxRHspgOBMw==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.53.0.tgz",
"integrity": "sha512-Opy3dqNsp/9kBBeCPhkCNR7fmdSQqA+47r21hr9a14Bx0xnkElEQmhoHga+VoaoQ6uDHjDKmQPIYcUcKJifS7w==",
"peer": true,
"dependencies": {
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/visitor-keys": "5.52.0"
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/visitor-keys": "5.53.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -1266,13 +1293,13 @@
}
},
"node_modules/@typescript-eslint/type-utils": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.52.0.tgz",
"integrity": "sha512-tEKuUHfDOv852QGlpPtB3lHOoig5pyFQN/cUiZtpw99D93nEBjexRLre5sQZlkMoHry/lZr8qDAt2oAHLKA6Jw==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.53.0.tgz",
"integrity": "sha512-HO2hh0fmtqNLzTAme/KnND5uFNwbsdYhCZghK2SoxGp3Ifn2emv+hi0PBUjzzSh0dstUIFqOj3bp0AwQlK4OWw==",
"peer": true,
"dependencies": {
"@typescript-eslint/typescript-estree": "5.52.0",
"@typescript-eslint/utils": "5.52.0",
"@typescript-eslint/typescript-estree": "5.53.0",
"@typescript-eslint/utils": "5.53.0",
"debug": "^4.3.4",
"tsutils": "^3.21.0"
},
@ -1293,9 +1320,9 @@
}
},
"node_modules/@typescript-eslint/types": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.52.0.tgz",
"integrity": "sha512-oV7XU4CHYfBhk78fS7tkum+/Dpgsfi91IIDy7fjCyq2k6KB63M6gMC0YIvy+iABzmXThCRI6xpCEyVObBdWSDQ==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.53.0.tgz",
"integrity": "sha512-5kcDL9ZUIP756K6+QOAfPkigJmCPHcLN7Zjdz76lQWWDdzfOhZDTj1irs6gPBKiXx5/6O3L0+AvupAut3z7D2A==",
"peer": true,
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
@ -1306,13 +1333,13 @@
}
},
"node_modules/@typescript-eslint/typescript-estree": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.52.0.tgz",
"integrity": "sha512-WeWnjanyEwt6+fVrSR0MYgEpUAuROxuAH516WPjUblIrClzYJj0kBbjdnbQXLpgAN8qbEuGywiQsXUVDiAoEuQ==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.53.0.tgz",
"integrity": "sha512-eKmipH7QyScpHSkhbptBBYh9v8FxtngLquq292YTEQ1pxVs39yFBlLC1xeIZcPPz1RWGqb7YgERJRGkjw8ZV7w==",
"peer": true,
"dependencies": {
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/visitor-keys": "5.52.0",
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/visitor-keys": "5.53.0",
"debug": "^4.3.4",
"globby": "^11.1.0",
"is-glob": "^4.0.3",
@ -1333,16 +1360,16 @@
}
},
"node_modules/@typescript-eslint/utils": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.52.0.tgz",
"integrity": "sha512-As3lChhrbwWQLNk2HC8Ree96hldKIqk98EYvypd3It8Q1f8d5zWyIoaZEp2va5667M4ZyE7X8UUR+azXrFl+NA==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.53.0.tgz",
"integrity": "sha512-VUOOtPv27UNWLxFwQK/8+7kvxVC+hPHNsJjzlJyotlaHjLSIgOCKj9I0DBUjwOOA64qjBwx5afAPjksqOxMO0g==",
"peer": true,
"dependencies": {
"@types/json-schema": "^7.0.9",
"@types/semver": "^7.3.12",
"@typescript-eslint/scope-manager": "5.52.0",
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/typescript-estree": "5.52.0",
"@typescript-eslint/scope-manager": "5.53.0",
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/typescript-estree": "5.53.0",
"eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0",
"semver": "^7.3.7"
@ -1359,12 +1386,12 @@
}
},
"node_modules/@typescript-eslint/visitor-keys": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.52.0.tgz",
"integrity": "sha512-qMwpw6SU5VHCPr99y274xhbm+PRViK/NATY6qzt+Et7+mThGuFSl/ompj2/hrBlRP/kq+BFdgagnOSgw9TB0eA==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.53.0.tgz",
"integrity": "sha512-JqNLnX3leaHFZEN0gCh81sIvgrp/2GOACZNgO4+Tkf64u51kTpAyWFOY8XHx8XuXr3N2C9zgPPHtcpMg6z1g0w==",
"peer": true,
"dependencies": {
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/types": "5.53.0",
"eslint-visitor-keys": "^3.3.0"
},
"engines": {
@ -1753,9 +1780,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001454",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001454.tgz",
"integrity": "sha512-4E63M5TBbgDoA9dQoFRdjL6iAmzTrz3rwYWoKDlvnvyvBxjCZ0rrUoX3THhEMie0/RYuTCeMbeTYLGAWgnLwEg==",
"version": "1.0.30001457",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001457.tgz",
"integrity": "sha512-SDIV6bgE1aVbK6XyxdURbUE89zY7+k1BBBaOwYwkNCglXlel/E7mELiHC64HQ+W0xSKlqWhV9Wh7iHxUjMs4fA==",
"funding": [
{
"type": "opencollective",
@ -2111,9 +2138,9 @@
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
},
"node_modules/electron-to-chromium": {
"version": "1.4.301",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.301.tgz",
"integrity": "sha512-bz00ASIIDjcgszZKuEA1JEFhbDjqUNbQ/PEhNEl1wbixzYpeTp2H2QWjsQvAL2T1wJBdOwCF5hE896BoMwYKrA=="
"version": "1.4.306",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.306.tgz",
"integrity": "sha512-1zGmLFfpcs2v7ELt/1HgLZF6Gm2CCHaAdNKxd9Ge4INSU/HDYWjs7fcWU6eVMmhkpwmh+52ZrGCUU+Ji9OJihA=="
},
"node_modules/encodeurl": {
"version": "1.0.2",
@ -5660,17 +5687,17 @@
"requires": {}
},
"@nevware21/ts-async": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@nevware21/ts-async/-/ts-async-0.1.1.tgz",
"integrity": "sha512-NvR4toK+8qGIFvRTB3ZodLhwzSvtoNUcb+bfbY1+vBy1IkbKg9fcZ/5cWQrgL9bwfrQ8kroNbbRPV6mjczB+jw==",
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@nevware21/ts-async/-/ts-async-0.1.2.tgz",
"integrity": "sha512-NCXzmG+HnkvyduMypWjMn1nZcQLMp3b2nZdt3RJuKZgRrcwCI2ZWcNt3XAfTEMiT+FbZx6htTs/JgWu3m0yZAw==",
"requires": {
"@nevware21/ts-utils": ">= 0.7 < 2.x"
}
},
"@nevware21/ts-utils": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.7.2.tgz",
"integrity": "sha512-eqkL8vHgeuGkjouEHGD3Hi156IBqflFFT8k1UzWg5xEdjQ0tFEQfOjhAeja0fFC6hrL2lHlIHt16stDtag+QCg==",
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/@nevware21/ts-utils/-/ts-utils-0.8.0.tgz",
"integrity": "sha512-MKDEZakdmPT0flCbgYSkXzVrmwqOGTBCmK7AkxvxuOedsekHKPyqUYX2WTKu9SjfnlsNX1DqjTNWcLy8h8g0Xg==",
"requires": {}
},
"@nodelib/fs.scandir": {
@ -5978,6 +6005,31 @@
"typescript": "^4.9.3"
}
},
"@rush-temp/applicationinsights-example-shared-worker": {
"version": "file:projects\\applicationinsights-example-shared-worker.tgz",
"integrity": "sha512-aIL4qvg/bjQOniMml+en/LfOa1mNHRaJXtyNFkMu1MqFSsPgH1L6Sg/fWJhkh/+TEPyDt6+QboKMqBeDs4mihQ==",
"requires": {
"@microsoft/dynamicproto-js": "^1.1.7",
"@nevware21/grunt-eslint-ts": "^0.2.2",
"@nevware21/grunt-ts-plugin": "^0.4.3",
"@nevware21/ts-utils": ">= 0.7 < 2.x",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.3.3",
"globby": "^11.0.0",
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-qunit": "^6.2.1",
"magic-string": "^0.25.7",
"pako": "^2.0.3",
"qunit": "^2.11.2",
"rollup": "^2.32.0",
"rollup-plugin-cleanup": "^3.2.1",
"sinon": "^7.3.1",
"tslib": "^2.0.0",
"typescript": "^4.9.3"
}
},
"@rush-temp/applicationinsights-js-release-tools": {
"version": "file:projects\\applicationinsights-js-release-tools.tgz",
"integrity": "sha512-6sVB5NMzKj/P9v9UvZlA/IjQSkGeupaDliSt2IZqy+SlR59Hv335Ekz/5f54xMHu+QiARXJATbjX7lDfCMG8qw==",
@ -6445,14 +6497,14 @@
}
},
"@typescript-eslint/eslint-plugin": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.52.0.tgz",
"integrity": "sha512-lHazYdvYVsBokwCdKOppvYJKaJ4S41CgKBcPvyd0xjZNbvQdhn/pnJlGtQksQ/NhInzdaeaSarlBjDXHuclEbg==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.53.0.tgz",
"integrity": "sha512-alFpFWNucPLdUOySmXCJpzr6HKC3bu7XooShWM+3w/EL6J2HIoB2PFxpLnq4JauWVk6DiVeNKzQlFEaE+X9sGw==",
"peer": true,
"requires": {
"@typescript-eslint/scope-manager": "5.52.0",
"@typescript-eslint/type-utils": "5.52.0",
"@typescript-eslint/utils": "5.52.0",
"@typescript-eslint/scope-manager": "5.53.0",
"@typescript-eslint/type-utils": "5.53.0",
"@typescript-eslint/utils": "5.53.0",
"debug": "^4.3.4",
"grapheme-splitter": "^1.0.4",
"ignore": "^5.2.0",
@ -6463,53 +6515,53 @@
}
},
"@typescript-eslint/parser": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.52.0.tgz",
"integrity": "sha512-e2KiLQOZRo4Y0D/b+3y08i3jsekoSkOYStROYmPUnGMEoA0h+k2qOH5H6tcjIc68WDvGwH+PaOrP1XRzLJ6QlA==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.53.0.tgz",
"integrity": "sha512-MKBw9i0DLYlmdOb3Oq/526+al20AJZpANdT6Ct9ffxcV8nKCHz63t/S0IhlTFNsBIHJv+GY5SFJ0XfqVeydQrQ==",
"peer": true,
"requires": {
"@typescript-eslint/scope-manager": "5.52.0",
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/typescript-estree": "5.52.0",
"@typescript-eslint/scope-manager": "5.53.0",
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/typescript-estree": "5.53.0",
"debug": "^4.3.4"
}
},
"@typescript-eslint/scope-manager": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.52.0.tgz",
"integrity": "sha512-AR7sxxfBKiNV0FWBSARxM8DmNxrwgnYMPwmpkC1Pl1n+eT8/I2NAUPuwDy/FmDcC6F8pBfmOcaxcxRHspgOBMw==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.53.0.tgz",
"integrity": "sha512-Opy3dqNsp/9kBBeCPhkCNR7fmdSQqA+47r21hr9a14Bx0xnkElEQmhoHga+VoaoQ6uDHjDKmQPIYcUcKJifS7w==",
"peer": true,
"requires": {
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/visitor-keys": "5.52.0"
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/visitor-keys": "5.53.0"
}
},
"@typescript-eslint/type-utils": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.52.0.tgz",
"integrity": "sha512-tEKuUHfDOv852QGlpPtB3lHOoig5pyFQN/cUiZtpw99D93nEBjexRLre5sQZlkMoHry/lZr8qDAt2oAHLKA6Jw==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.53.0.tgz",
"integrity": "sha512-HO2hh0fmtqNLzTAme/KnND5uFNwbsdYhCZghK2SoxGp3Ifn2emv+hi0PBUjzzSh0dstUIFqOj3bp0AwQlK4OWw==",
"peer": true,
"requires": {
"@typescript-eslint/typescript-estree": "5.52.0",
"@typescript-eslint/utils": "5.52.0",
"@typescript-eslint/typescript-estree": "5.53.0",
"@typescript-eslint/utils": "5.53.0",
"debug": "^4.3.4",
"tsutils": "^3.21.0"
}
},
"@typescript-eslint/types": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.52.0.tgz",
"integrity": "sha512-oV7XU4CHYfBhk78fS7tkum+/Dpgsfi91IIDy7fjCyq2k6KB63M6gMC0YIvy+iABzmXThCRI6xpCEyVObBdWSDQ==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.53.0.tgz",
"integrity": "sha512-5kcDL9ZUIP756K6+QOAfPkigJmCPHcLN7Zjdz76lQWWDdzfOhZDTj1irs6gPBKiXx5/6O3L0+AvupAut3z7D2A==",
"peer": true
},
"@typescript-eslint/typescript-estree": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.52.0.tgz",
"integrity": "sha512-WeWnjanyEwt6+fVrSR0MYgEpUAuROxuAH516WPjUblIrClzYJj0kBbjdnbQXLpgAN8qbEuGywiQsXUVDiAoEuQ==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.53.0.tgz",
"integrity": "sha512-eKmipH7QyScpHSkhbptBBYh9v8FxtngLquq292YTEQ1pxVs39yFBlLC1xeIZcPPz1RWGqb7YgERJRGkjw8ZV7w==",
"peer": true,
"requires": {
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/visitor-keys": "5.52.0",
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/visitor-keys": "5.53.0",
"debug": "^4.3.4",
"globby": "^11.1.0",
"is-glob": "^4.0.3",
@ -6518,28 +6570,28 @@
}
},
"@typescript-eslint/utils": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.52.0.tgz",
"integrity": "sha512-As3lChhrbwWQLNk2HC8Ree96hldKIqk98EYvypd3It8Q1f8d5zWyIoaZEp2va5667M4ZyE7X8UUR+azXrFl+NA==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.53.0.tgz",
"integrity": "sha512-VUOOtPv27UNWLxFwQK/8+7kvxVC+hPHNsJjzlJyotlaHjLSIgOCKj9I0DBUjwOOA64qjBwx5afAPjksqOxMO0g==",
"peer": true,
"requires": {
"@types/json-schema": "^7.0.9",
"@types/semver": "^7.3.12",
"@typescript-eslint/scope-manager": "5.52.0",
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/typescript-estree": "5.52.0",
"@typescript-eslint/scope-manager": "5.53.0",
"@typescript-eslint/types": "5.53.0",
"@typescript-eslint/typescript-estree": "5.53.0",
"eslint-scope": "^5.1.1",
"eslint-utils": "^3.0.0",
"semver": "^7.3.7"
}
},
"@typescript-eslint/visitor-keys": {
"version": "5.52.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.52.0.tgz",
"integrity": "sha512-qMwpw6SU5VHCPr99y274xhbm+PRViK/NATY6qzt+Et7+mThGuFSl/ompj2/hrBlRP/kq+BFdgagnOSgw9TB0eA==",
"version": "5.53.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.53.0.tgz",
"integrity": "sha512-JqNLnX3leaHFZEN0gCh81sIvgrp/2GOACZNgO4+Tkf64u51kTpAyWFOY8XHx8XuXr3N2C9zgPPHtcpMg6z1g0w==",
"peer": true,
"requires": {
"@typescript-eslint/types": "5.52.0",
"@typescript-eslint/types": "5.53.0",
"eslint-visitor-keys": "^3.3.0"
}
},
@ -6807,9 +6859,9 @@
"peer": true
},
"caniuse-lite": {
"version": "1.0.30001454",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001454.tgz",
"integrity": "sha512-4E63M5TBbgDoA9dQoFRdjL6iAmzTrz3rwYWoKDlvnvyvBxjCZ0rrUoX3THhEMie0/RYuTCeMbeTYLGAWgnLwEg=="
"version": "1.0.30001457",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001457.tgz",
"integrity": "sha512-SDIV6bgE1aVbK6XyxdURbUE89zY7+k1BBBaOwYwkNCglXlel/E7mELiHC64HQ+W0xSKlqWhV9Wh7iHxUjMs4fA=="
},
"chalk": {
"version": "4.1.2",
@ -7069,9 +7121,9 @@
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
},
"electron-to-chromium": {
"version": "1.4.301",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.301.tgz",
"integrity": "sha512-bz00ASIIDjcgszZKuEA1JEFhbDjqUNbQ/PEhNEl1wbixzYpeTp2H2QWjsQvAL2T1wJBdOwCF5hE896BoMwYKrA=="
"version": "1.4.306",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.306.tgz",
"integrity": "sha512-1zGmLFfpcs2v7ELt/1HgLZF6Gm2CCHaAdNKxd9Ge4INSU/HDYWjs7fcWU6eVMmhkpwmh+52ZrGCUU+Ji9OJihA=="
},
"encodeurl": {
"version": "1.0.2",

31
examples/README.md Normal file
Просмотреть файл

@ -0,0 +1,31 @@
# Microsoft Application Insights JavaScript SDK Examples
A collection of examples using the ApplicationInsights SDK, these examples are compiled as part of every build (unless otherwise stated),
but may not be executed as part of any automated test pass -- this may change/vary.
## Examples
[Shared Worker](./shared-worker/README.md)
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
and actually do, grant us the rights to use your contribution. For details, visit
https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsofts Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-partys policies.
## License
[MIT](LICENSE)

Просмотреть файл

@ -0,0 +1,49 @@
# Microsoft Application Insights JavaScript SDK Example - Shared Worker
![GitHub Workflow Status (main)](https://img.shields.io/github/actions/workflow/status/microsoft/ApplicationInsights-JS/ci.yml?branch=master)
Example to instrument a Shared-Worker
## Simple Instrumented Shared Worker Example
This is a simple example that uses 2 Shared Workers as defined by
- [worker.ts](./src/worker.ts)
- [worker2.ts](./src/worker2.ts)
You WILL NEED to have compiled the repository before running this example as it loads the compiled scripts, and you will also NEED to start the
local web server via `npm run serve` from the root of repository.
You can load the Shared Worker example via the [SharedWorker.html](SharedWorker.html).
This implements a VERY simple Shared Worker example that passes messages between the
current page and the workers using the type in the [IExampleMessage](./src/interfaces/IExampleMessage.ts),
And the support functions for the Web page are located in [example-shared-worker.ts](./src/example-shared-worker.ts)
## Contributing
This project welcomes contributions and suggestions. Most contributions require you to
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
and actually do, grant us the rights to use your contribution. For details, visit
https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## Data Collection
As this SDK is designed to enable applications to perform data collection which is sent to the Microsoft collection endpoints the following is required to identify our privacy statement.
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsofts privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsofts Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-partys policies.
## License
[MIT](LICENSE)

Просмотреть файл

@ -0,0 +1,124 @@
<html>
<head>
<script src="./browser/example-shared-worker.gbl.js"></script>
</head>
<body>
<h1>Simple Instrumented Shared Worker Example</h1>
<p>Please make sure that you have compiled the repository before running this example as it loads the compiled scripts.</p>
<p>This script also needs to be run from the hosted `localhost` instance which can be started by running<br/> &gt; <code>npm run serve</code><br/>
from the root folder of the repository.
</p>
<p>
And then re-laoding this page from <a href="http://localhost:9001/examples/shared-worker/SharedWorker.html">http://localhost:9001/examples/shared-worker/SharedWorker.html</a>
</p>
<p>
Work is sent to the worker(s) and any responses are returned and displayed on the main console, if you want to inspect
the console of the workers you can access and debug the worker code via these links. You will need to manually open as accessing
local resources is generally prohibited.
<ul>
<li>Chrome: <code>chrome://inspect/#workers</code></li>
<li>MS Edge: <code>edge://inspect/#workers</code></li>
</ul>
</p>
<hr />
<h2>Worker 1 - Instrumented</h2>
<p>You must use the <code>Initialize SDK</code> button at least once to initialize Application Insights within the worker.
The <code>Unload SDK</code> will cause the SDK instance in the worker to unload and this will disable the reporting of fetch calls.<br/>
Once the SDK in initialized it will report back when events are sent from the Workers SDK instance.
</p>
<div>
<div style="display:inline-block; width:50%; vertical-align: top;">
<div>
<div style="display:inline-block; width:10%">
<label for="connectionString">Connection String</label>
</div>
<input id="connectionString" style="width:50%" value="YourConnectionString" />
</div>
<div style="margin-top:10px">
<div style="display:inline-block; width:10%">
</div>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.loadSdk('connectionString')">Initialize SDK</button>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.unloadSdk()">Unload SDK</button>
</div>
<hr style="margin-top:10px"/>
<div>
<div style="display:inline-block; width:10%">
<label for="fetchUrl">Fetch URL</label>
</div>
<input id="fetchUrl" style="width:50%" value="https://js.monitor.azure.com/scripts/b/ai.2.integrity.json" />
</div>
<div style="margin-top:10px">
<div style="display:inline-block; width:10%">
</div>
<div style="display:inline-block">
<div>
This will cause the worker (if the SDK is initialized) to send a RemoteDependency event.
</div>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.fetchUrl('fetchUrl')">Fetch the URL</button> (Contents will be sent to the main page console via a post)
</div>
</div>
<div style="margin-top:10px">
<div style="display:inline-block; width:10%">
</div>
<div style="display:inline-block">
<div style="margin-bottom:2px">
This will cause the worker (if the SDK is initialized) to send a new PageView event.
</div>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.trackPageView()">Track Page View</button>
</div>
</div>
<div style="margin-top:10px">
<div style="display:inline-block; width:10%">
</div>
<div style="display:inline-block">
<div style="margin-bottom:2px">
Send an invalid request to the worker
</div>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.sendInvalidRequest()">Send Invalid Request</button>
</div>
</div>
</div>
<div style="display:inline-table; width:45%; margin-left: 10px">
<p>This is the information returned by the worker, when the SDK is initialized you will see an "Events Sent"
message when the SDK has sent the events to Azure Monitor, if the connection string is valid you will
see the generated events in the Azure Monitor Portal.
</p>
<textarea id="_logContainer-log" style="width:100%; min-height: 200px;"></textarea>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.clearLog('log')">Clear Log</button>
</div>
</div>
<hr/>
<h2>Worker 2 - Not Instrumented</h2>
<div>
<div style="display:inline-block; width:50%; vertical-align: top;">
<div>
<div style="display:inline-block; width:10%">
<label for="fetch2Url">Fetch URL</label>
</div>
<input id="fetch2Url" style="width:50%" value="https://js.monitor.azure.com/scripts/b/ai.2.integrity.json" />
</div>
<div style="margin-top:10px">
<div style="display:inline-block; width:10%">
</div>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.fetch2Url('fetch2Url')">Fetch the URL</button> (Contents will be sent to the main page console via a post)
</div>
<div style="margin-top:10px">
<div style="display:inline-block; width:10%">
</div>
<div style="display:inline-block">
<div style="margin-bottom:2px">
Send an invalid request to the worker
</div>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.sendInvalidRequest2()">Send Invalid Request</button>
</div>
</div>
</div>
<div style="display:inline-block; width:45%; margin-left: 10px">
<p>This is the information returned by the worker 2.
</p>
<textarea id="_logContainer-log2" style="width:100%; min-height: 200px;"></textarea>
<button onclick="javascript:Microsoft.ApplicationInsights.Example.clearLog('log2')">Clear Log</button>
</div>
</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,71 @@
{
"name": "@microsoft/applicationinsights-example-shared-worker",
"author": "Microsoft Application Insights Team",
"version": "2.8.10",
"description": "Microsoft Application Insights Shared Worker Example",
"homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
"keywords": [
"azure",
"cloud",
"script errors",
"microsoft",
"application insights",
"browser performance monitoring",
"web analytics",
"example"
],
"main": "dist/applicationinsights-example-shared-worker.js",
"module": "dist-esm/applicationinsights-example-shared-worker.js",
"types": "types/applicationinsights-example-shared-worker.d.ts",
"scripts": {
"clean": "grunt clean",
"build": "npm run build:esm && npm run build:browser",
"build:esm": "grunt example-shared-worker",
"build:browser": "rollup -c rollup.config.js",
"rebuild": "npm run build",
"test": "",
"mintest": "",
"perftest": "",
"lint": "tslint -p tsconfig.json",
"ai-min": "grunt example-shared-worker-min",
"ai-restore": "grunt example-shared-worker-restore"
},
"repository": {
"type": "git",
"url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/shared/AppInsightsCore"
},
"license": "MIT",
"sideEffects": false,
"devDependencies": {
"@microsoft/ai-test-framework": "0.0.1",
"@microsoft/applicationinsights-rollup-plugin-uglify3-js": "1.0.0",
"@microsoft/applicationinsights-rollup-es5": "1.0.0",
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-qunit": "^6.2.1",
"@nevware21/grunt-ts-plugin": "^0.4.3",
"@nevware21/grunt-eslint-ts": "^0.2.2",
"globby": "^11.0.0",
"magic-string": "^0.25.7",
"pako": "^2.0.3",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.3.3",
"rollup-plugin-cleanup": "^3.2.1",
"rollup": "^2.32.0",
"typescript": "^4.9.3",
"tslib": "^2.0.0",
"qunit": "^2.11.2",
"sinon": "^7.3.1"
},
"peerDependencies": {
"tslib": "*"
},
"dependencies": {
"@microsoft/applicationinsights-shims": "2.0.2",
"@microsoft/dynamicproto-js": "^1.1.7",
"@microsoft/applicationinsights-web": "2.8.10",
"@microsoft/applicationinsights-web-snippet": "1.0.1",
"@nevware21/ts-utils": ">= 0.7 < 2.x"
}
}

Просмотреть файл

@ -0,0 +1,102 @@
import nodeResolve from "@rollup/plugin-node-resolve";
import { uglify } from "@microsoft/applicationinsights-rollup-plugin-uglify3-js";
import replace from "@rollup/plugin-replace";
import cleanup from "rollup-plugin-cleanup";
import dynamicRemove from "@microsoft/dynamicproto-js/tools/rollup/node/removedynamic";
import { es5Poly, es5Check, importCheck } from "@microsoft/applicationinsights-rollup-es5";
import { updateDistEsmFiles } from "../../tools/updateDistEsm/updateDistEsm";
const version = require("./package.json").version;
const workerName = "example-shared-worker";
const workerModule = "worker";
const worker2Module = "worker2";
const banner = [
"/*!",
` * Application Insights JavaScript SDK Example - Shared Worker, ${version}`,
" * Copyright (c) Microsoft and contributors. All rights reserved.",
" */"
].join("\n");
const replaceValues = {
"// Copyright (c) Microsoft Corporation. All rights reserved.": "",
"// Licensed under the MIT License.": ""
};
function doCleanup() {
return cleanup({
comments: [
'some',
/^.\s*@DynamicProtoStub/i,
/^\*\*\s*@class\s*$/
]
})
}
const browserRollupConfigFactory = (name, isProduction, format = "umd", extension = "") => {
const browserRollupConfig = {
input: `dist-esm/${name}.js`,
output: {
file: `browser/${name}${extension ? "." +extension : ""}.js`,
banner: banner,
format: format,
name: "Microsoft.ApplicationInsights.Example",
extend: true,
freeze: false,
sourcemap: true
},
treeshake: {
propertyReadSideEffects: false,
moduleSideEffects: false,
tryCatchDeoptimization: false,
correctVarValueBeforeDeclaration: false
},
plugins: [
dynamicRemove(),
replace({
preventAssignment: true,
delimiters: ["", ""],
values: replaceValues
}),
// This just makes sure we are importing the example dependencies correctly
importCheck({ exclude: [ "applicationinsights-example-shared-worker" ] }),
nodeResolve({
module: true,
browser: true,
preferBuiltins: false
}),
doCleanup(),
es5Poly(),
es5Check()
]
};
if (isProduction) {
browserRollupConfig.output.file = `browser/${name}${extension ? "." +extension : ""}.min.js`;
browserRollupConfig.plugins.push(
uglify({
ie8: false,
ie: true,
compress: {
ie: true,
passes:3,
unsafe: true,
},
output: {
ie: true,
preamble: banner,
webkit:true
}
})
);
}
return browserRollupConfig;
};
updateDistEsmFiles(replaceValues, banner);
export default [
browserRollupConfigFactory(workerName, false, "iife", "gbl"),
browserRollupConfigFactory(workerModule, false, "esm"),
browserRollupConfigFactory(worker2Module, false, "esm")
];

Просмотреть файл

@ -0,0 +1,208 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { getDocument } from "@nevware21/ts-utils";
import { ExampleMessageType, IExampleRequest } from "./interfaces/IExampleMessage";
let _logContainers = {
log: "",
log2: ""
};
let _worker: SharedWorker;
let _worker2: SharedWorker;
//-------------------------------------------------------------------------------------
// Main Page Helper functions
//-------------------------------------------------------------------------------------
/**
* Log details to the named HTML Text Area
* @param message
* @param dest
*/
function logMessage(message: string, dest: keyof typeof _logContainers) {
var dateTime = new Date().toLocaleString();
var target = "_logContainer-" + dest || "log";
var elm = document.getElementById(target);
_logContainers[target] = dateTime + ": " + message + "\n" + (_logContainers[target] ||"");
if (_logContainers[target].length > 4096) {
_logContainers[target] = _logContainers[target].substring(0, 4090) + "...\n";
}
if (elm) {
elm.innerHTML = _logContainers[target];
}
console.log(message);
}
/**
* Clear the log and the named HTML Text Area
* @param dest
*/
export function clearLog(dest: keyof typeof _logContainers) {
var target = "_logContainer-" + dest || "log";
var elm = document.getElementById(target);
_logContainers[target] = "";
if (elm) {
elm.innerHTML = _logContainers[target];
}
}
//-------------------------------------------------------------------------------------
// Worker 1 functions for main page
//-------------------------------------------------------------------------------------
/**
* Cause Worker 1 to be loaded and started or return the previous loaded / started reference
* @returns
*/
export function loadSharedWorker() {
if (!_worker) {
_worker = new SharedWorker("./browser/worker.js");
_worker.port.onmessage = (evt) => {
let resp = evt.data;
if (resp) {
logMessage(JSON.stringify(resp), "log");
}
}
}
return _worker;
}
/**
* Send a message to Worker 1, this will initialize the worker if has not already been started
* @param message
*/
export function sendWorkerMessage(message: IExampleRequest) {
let worker = loadSharedWorker();
worker.port.postMessage(message);
}
/**
* Ask Worker 1 to initialize the SDK
* @param connectionStringId
*/
export function loadSdk(connectionStringId: string) {
let doc = getDocument();
let elm = doc.getElementById(connectionStringId) as HTMLInputElement;
let connectionString: string;
if (elm) {
connectionString = elm.value;
}
sendWorkerMessage({
type: ExampleMessageType.Load,
connectionString: connectionString
});
}
/**
* Ask Worker 1 to unload the SDK
*/
export function unloadSdk() {
sendWorkerMessage({
type: ExampleMessageType.Unload
});
}
/**
* Ask Worker 1 to fetch the provided URL (this will cause the worker fetch to trigger a Dependency Request)
* @param urlId
*/
export function fetchUrl(urlId: string) {
let doc = getDocument();
let elm = doc.getElementById(urlId) as HTMLInputElement;
let theUrl: string;
if (elm) {
theUrl = elm.value;
}
sendWorkerMessage({
type: ExampleMessageType.Fetch,
url: theUrl
});
}
/**
* Ask Worker 1 to perform a track Page view
*/
export function trackPageView() {
sendWorkerMessage({
type: ExampleMessageType.TrackPageView
});
}
/**
* Send an invalid request to Worker 1
*/
export function sendInvalidRequest() {
sendWorkerMessage({
type: 9999
});
}
//-------------------------------------------------------------------------------------
// Worker 2 functions for main page
//-------------------------------------------------------------------------------------
/**
* Cause Worker 2 to be loaded and started or return the previous loaded / started reference
* @returns
*/
export function loadSharedWorker2() {
if (!_worker2) {
_worker2 = new SharedWorker("./browser/worker2.js");
_worker2.port.onmessage = (evt) => {
let resp = evt.data;
if (resp) {
logMessage(JSON.stringify(resp), "log2");
}
}
}
return _worker2;
}
/**
* Send a message to Worker 2, this will initialize the worker if has not already been started
* @param message
*/
export function sendWorker2Message(message: IExampleRequest) {
let worker = loadSharedWorker2();
worker.port.postMessage(message);
}
/**
* Ask Worker 2 to fetch the provided URL (this will cause the worker fetch to trigger a Dependency Request)
* @param urlId
*/
export function fetch2Url(urlId: string) {
let doc = getDocument();
let elm = doc.getElementById(urlId) as HTMLInputElement;
let theUrl: string;
if (elm) {
theUrl = elm.value;
}
sendWorker2Message({
type: ExampleMessageType.Fetch,
url: theUrl
});
}
/**
* Send an invalid request to Worker 2
*/
export function sendInvalidRequest2() {
sendWorker2Message({
type: 9999
});
}

Просмотреть файл

@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/**
* Enum to identify the examples support messages
*/
export const enum ExampleMessageType {
Invalid = 0,
Load = 1,
Unload = 2,
Fetch = 3,
TrackPageView = 4
}
/**
* The format of a request to the example workers
*/
export interface IExampleRequest {
type: ExampleMessageType;
connectionString?: string;
url?: string;
}
/**
* The format of the response returned from the workers
*/
export interface IExampleResponse {
success: boolean;
message?: string;
resp?: string;
}

Просмотреть файл

@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { ApplicationInsights, IConfiguration } from "@microsoft/applicationinsights-web"
// Cache the previously initialized instance to avoid creating multiple instances
let _appInsights: ApplicationInsights;
/**
* Initialize (or return the previously initialized) SDK instance for the worker
* @param config
* @returns
*/
export function initApplicationInsights(config: IConfiguration) {
if (!_appInsights) {
// Make sure we have a configuration object
config = config || {};
if (!config.instrumentationKey || !config.connectionString) {
config.connectionString = "InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE";
}
_appInsights = new ApplicationInsights({
config: config
});
_appInsights.loadAppInsights();
_appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
return _appInsights;
}
return _appInsights;
}
/**
* Unload the SDK if it has been initialized
* @returns
*/
export function unloadApplicationInsights() {
if (_appInsights) {
_appInsights.unload();
_appInsights = null;
return true;
}
return false;
}
/**
* Request a page view request if the SDK has been initialized
* @returns
*/
export function trackPageView() {
if (_appInsights) {
_appInsights.trackPageView();
return true;
}
return false;
}

Просмотреть файл

@ -0,0 +1,173 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { initApplicationInsights, trackPageView, unloadApplicationInsights } from "./worker-npm-init";
import { ExampleMessageType, IExampleRequest, IExampleResponse } from "./interfaces/IExampleMessage";
import { IConfiguration, INotificationListener } from "@microsoft/applicationinsights-web";
import { dumpObj, objAssign } from "@nevware21/ts-utils";
/**
* Default base configuration, add your defaults here.
* Or simply specify your entire configuration and don't have the main page pass
* the connection string.
*/
const defaultApplicationInsightsConfig: IConfiguration = {
};
/**
* Simple lookup table which matches the request type to the function that will process the request
*/
const EventHandlers: { [key: number]: (request: IExampleRequest, port: MessagePort) => IExampleResponse } = {
[ExampleMessageType.Invalid]: workerInvalid,
[ExampleMessageType.Load]: workerLoadSdk,
[ExampleMessageType.Unload]: workerUnloadSdk,
[ExampleMessageType.Fetch]: workerFetch,
[ExampleMessageType.TrackPageView]: workerTrackPageView
};
/**
* The main shared worker entry point
*/
addEventListener("connect", (evt: MessageEvent) => {
const port = evt.ports[0];
// Add the message listener
port.addEventListener("message", (evt: MessageEvent<IExampleRequest>) => {
const request = evt.data;
if (!request || !request.type) {
// doesn't look correct
port.postMessage(workerInvalid(request));
return;
}
console.log(`Worker: Received message [${request.type}] from main script`);
let handler: (request: IExampleRequest, port: MessagePort) => IExampleResponse = EventHandlers[request.type];
if (!handler) {
handler = workerInvalid;
}
try {
let response = handler(request, port);
if (response) {
port.postMessage(response);
}
} catch (e) {
port.postMessage({
success: false,
message: dumpObj(e)
});
}
});
port.start();
});
/**
* Handle "Invalid" (Unknown) request
* @param request
* @returns
*/
function workerInvalid(request: IExampleRequest) {
return {
success: false,
message: `Unsupported command - ${request ? request.type : "Invalid Request"}`
}
}
/**
* Internal hook to listen to the events send notification from the Application Insights Sender
* @param port
* @returns
*/
function notificationListener(port: MessagePort): INotificationListener {
return {
eventsSendRequest: function () {
port.postMessage({
success: true,
message: `Events Sent: ${dumpObj(arguments)}`
});
}
};
}
/**
* Initialize the SDK using the passed connection string from the request (if supplied)
* @param request
* @param port
* @returns
*/
function workerLoadSdk(request: IExampleRequest, port: MessagePort) {
let theConfig = objAssign({}, defaultApplicationInsightsConfig);
theConfig.connectionString = request.connectionString;
let appInsights = initApplicationInsights(theConfig);
if (appInsights && appInsights.core.isInitialized()) {
appInsights.core.getNotifyMgr().addNotificationListener(notificationListener(port));
return {
success: true,
message: `SDK Loaded and Initialized with - ${appInsights.config.connectionString}`
};
}
return {
success: true,
message: "SDK Failed to initialize"
};
}
/**
* Unload the SDK instance
* @param request
* @returns
*/
function workerUnloadSdk(request: IExampleRequest) {
if (unloadApplicationInsights()) {
return {
success: true,
message: "SDK Unloading"
};
}
return {
success: true,
message: "SDK Already unloaded"
};
}
/**
* Perform a "fetch" request for the provided URL
* @param request
* @param port
* @returns
*/
function workerFetch(request: IExampleRequest, port: MessagePort) {
function fetchFailed(reason: any) {
port.postMessage({ success: false, message: dumpObj(reason) });
}
fetch(request.url).then((value) => {
value.text().then((theResponse) => {
port.postMessage({ success: true, resp: theResponse });
}, fetchFailed);
}, fetchFailed);
// Will return message asynchronously
return {
success: true,
message: "Fetch request received"
};
}
/**
* Attempt to send a PageView event (if the SDK is initialized)
* @param request
* @param port
* @returns
*/
function workerTrackPageView(request: IExampleRequest, port: MessagePort) {
return {
success: trackPageView(),
message: "TrackPageView requested"
};
}

Просмотреть файл

@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { ExampleMessageType, IExampleRequest, IExampleResponse } from "./interfaces/IExampleMessage";
import { dumpObj } from "@nevware21/ts-utils";
const EventHandlers: { [key: number]: (request: IExampleRequest, port: MessagePort) => IExampleResponse } = {
[ExampleMessageType.Invalid]: workerInvalid,
[ExampleMessageType.Fetch]: workerFetch
};
/**
* The main shared worker entry point
*/
addEventListener("connect", (evt: MessageEvent) => {
const port = evt.ports[0];
// Add the message listener
port.addEventListener("message", (evt: MessageEvent<IExampleRequest>) => {
const request = evt.data;
if (!request || !request.type) {
// doesn't look correct
console.log("Worker2: Invalid message received -- ignoring!");
return;
}
console.log(`Worker2: Received message [${request.type}] from main script`);
let handler: (request: IExampleRequest, port: MessagePort) => IExampleResponse = EventHandlers[request.type];
if (!handler) {
handler = workerInvalid;
}
try {
let response = handler(request, port);
if (response) {
port.postMessage(response);
}
} catch (e) {
port.postMessage({
success: false,
message: dumpObj(e)
});
}
});
port.start();
});
/**
* Handle "Invalid" (Unknown) request
* @param request
* @returns
*/
function workerInvalid(request: IExampleRequest) {
return {
success: false,
message: `Unsupported commend - ${request.type}`
}
}
/**
* Perform a "fetch" request for the provided URL
* @param request
* @param port
* @returns
*/
function workerFetch(request: IExampleRequest, port: MessagePort) {
function fetchFailed(reason: any) {
port.postMessage({ success: false, message: dumpObj(reason) });
}
fetch(request.url).then((value) => {
value.text().then((theResponse) => {
port.postMessage({ success: true, resp: theResponse });
}, fetchFailed);
}, fetchFailed);
// Will return message asynchronously
return {
success: true,
message: "Worker2: Fetch request received"
};
}

Просмотреть файл

@ -0,0 +1,26 @@
{
"compilerOptions": {
"sourceMap": true,
"inlineSources": true,
"noImplicitAny": true,
"module": "es6",
"moduleResolution": "node",
"target": "es5",
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"noEmitHelpers": true,
"skipLibCheck": false,
"alwaysStrict": true,
"skipDefaultLibCheck": true,
"declaration": true,
"declarationDir": "./types",
"outDir": "./dist-esm",
"rootDir": "./src",
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true
},
"include": [
"src/**/*"
],
"exclude": ["node_modules/"]
}

Просмотреть файл

@ -15,7 +15,7 @@ import {
dumpObj, eLoggingSeverity, eventOn, generateW3CId, getExceptionName, getGlobal, getIEVersion, getLocation, getPerformance, isFunction,
isNullOrUndefined, isString, isXhrSupported, mergeEvtNamespace, onConfigChange, strPrototype, strTrim
} from "@microsoft/applicationinsights-core-js";
import { objFreeze, scheduleTimeout, strIndexOf } from "@nevware21/ts-utils";
import { isWebWorker, objFreeze, scheduleTimeout, strIndexOf } from "@nevware21/ts-utils";
import { DependencyInitializerFunction, IDependencyInitializerDetails, IDependencyInitializerHandler } from "./DependencyInitializer";
import {
DependencyListenerFunction, IDependencyHandler, IDependencyListenerContainer, IDependencyListenerDetails, IDependencyListenerHandler
@ -618,7 +618,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
// Create an error callback to report any hook errors
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
"Failed to monitor Window.fetch" + ERROR_POSTFIX)
}));
}, true, isWebWorker()));
_fetchInitialized = true;
} else if (isPolyfill && !_polyfillInitialized) {

Просмотреть файл

@ -438,6 +438,13 @@ module.exports = function (grunt) {
path: "./extensions/applicationinsights-properties-js",
unitTestName: "prop.tests.js"
},
// Examples
"example-shared-worker": {
autoMinify: false,
path: "./examples/shared-worker",
testHttp: false
},
// Tools
"rollupuglify": {
@ -756,6 +763,9 @@ module.exports = function (grunt) {
grunt.registerTask("clickanalyticstests", tsTestActions("clickanalytics"));
grunt.registerTask("clickanalytics-mintests", tsTestActions("clickanalytics", true));
grunt.registerTask("example-shared-worker", tsBuildActions("example-shared-worker"));
grunt.registerTask("example-shared-worker-test", tsTestActions("example-shared-worker"));
grunt.registerTask("tst-framework", tsBuildActions("tst-framework"));
grunt.registerTask("serve", ["connect:server:keepalive"]);
} catch (e) {

Просмотреть файл

@ -103,6 +103,11 @@
"packageName": "applicationinsights-web-config",
"projectFolder": "tools/config",
"shouldPublish": false
},
{
"packageName": "@microsoft/applicationinsights-example-shared-worker",
"projectFolder": "examples/shared-worker",
"shouldPublish": false
}
]
}

Просмотреть файл

@ -2,7 +2,8 @@
# Microsoft Application Insights JavaScript SDK - Core
[![Build Status](https://travis-ci.org/microsoft/applicationinsights-core-js.svg?branch=master)](https://travis-ci.org/microsoft/applicationinsights-core-js) [![Build status](https://dev.azure.com/mseng/AppInsights/_apis/build/status/AppInsights%20-%20DevTools/1DS%20JavaScript%20SDK%20-%20Core)](https://dev.azure.com/mseng/AppInsights/_build/latest?definitionId=7605)
![GitHub Workflow Status (main)](https://img.shields.io/github/actions/workflow/status/microsoft/ApplicationInsights-JS/ci.yml?branch=master)
[![npm version](https://badge.fury.io/js/%40microsoft%2Fapplicationinsights-core-js.svg)](https://badge.fury.io/js/%40microsoft%2Fapplicationinsights-core-js)
Core SDK layer for next version of application insights javascript SDK.

Просмотреть файл

@ -131,13 +131,13 @@ function _createFunctionHook(aiHook:IInstrumentHooks) {
/** @ignore */
function _getOwner(target:any, name:string, checkPrototype: boolean): any {
function _getOwner(target:any, name:string, checkPrototype: boolean, checkParentProto: boolean): any {
let owner = null;
if (target) {
if (objHasOwnProperty(target, name)) {
owner = target;
} else if (checkPrototype) {
owner = _getOwner(_getObjProto(target), name, false);
owner = _getOwner(_getObjProto(target), name, checkParentProto, false);
}
}
@ -219,10 +219,11 @@ function _createInstrumentHook(owner: any, funcName: string, fn: any, callbacks:
* @param funcName - The function name
* @param callbacks - The callbacks to configure and call whenever the function is called
* @param checkPrototype - If the function doesn't exist on the target should it attempt to hook the prototype function
* @param checkParentProto - If the function doesn't exist on the target or it's prototype should it attempt to hook the parent's prototype
*/
export function InstrumentFunc(target:any, funcName:string, callbacks: IInstrumentHooksCallbacks, checkPrototype:boolean = true): IInstrumentHook {
export function InstrumentFunc(target:any, funcName:string, callbacks: IInstrumentHooksCallbacks, checkPrototype: boolean = true, checkParentProto?: boolean): IInstrumentHook {
if (target && funcName && callbacks) {
let owner = _getOwner(target, funcName, checkPrototype);
let owner = _getOwner(target, funcName, checkPrototype, checkParentProto);
if (owner) {
let fn = owner[funcName]
if (typeof fn === strShimFunction) {
@ -240,11 +241,12 @@ export function InstrumentFunc(target:any, funcName:string, callbacks: IInstrume
* @param funcNames - The function names to intercept and call
* @param callbacks - The callbacks to configure and call whenever the function is called
* @param checkPrototype - If the function doesn't exist on the target should it attempt to hook the prototype function
* @param checkParentProto - If the function doesn't exist on the target or it's prototype should it attempt to hook the parent's prototype
*/
export function InstrumentFuncs(target:any, funcNames:string[], callbacks: IInstrumentHooksCallbacks, checkPrototype:boolean = true): IInstrumentHook[] {
export function InstrumentFuncs(target:any, funcNames:string[], callbacks: IInstrumentHooksCallbacks, checkPrototype:boolean = true, checkParentProto?: boolean): IInstrumentHook[] {
let hooks: IInstrumentHook[] = null;
_arrLoop(funcNames, (funcName) => {
let hook = InstrumentFunc(target, funcName, callbacks, checkPrototype);
let hook = InstrumentFunc(target, funcName, callbacks, checkPrototype, checkParentProto);
if (hook) {
if (!hooks) {
hooks = [];
@ -264,10 +266,11 @@ export function InstrumentFuncs(target:any, funcNames:string[], callbacks: IInst
* @param evtName - The name of the event
* @param callbacks - The callbacks to configure and call whenever the function is called
* @param checkPrototype - If the function doesn't exist on the target should it attempt to hook the prototype function
* @param checkParentProto - If the function doesn't exist on the target or it's prototype should it attempt to hook the parent's prototype
*/
export function InstrumentEvent(target: any, evtName: string, callbacks: IInstrumentHooksCallbacks, checkPrototype?: boolean): IInstrumentHook {
export function InstrumentEvent(target: any, evtName: string, callbacks: IInstrumentHooksCallbacks, checkPrototype?: boolean, checkParentProto?: boolean): IInstrumentHook {
if (target && evtName && callbacks) {
let owner = _getOwner(target, evtName, checkPrototype) || target;
let owner = _getOwner(target, evtName, checkPrototype, checkParentProto) || target;
if (owner) {
return _createInstrumentHook(owner, evtName, owner[evtName], callbacks);
}

Просмотреть файл

@ -365,6 +365,10 @@ function shouldProcess(name) {
return updateDefPkgs;
}
if (name.indexOf("examples/") !== -1) {
return updateDefPkgs;
}
if (name.indexOf("extensions/") !== -1) {
return updateDefPkgs;
}