-
Notifications
You must be signed in to change notification settings - Fork 256
Description
Description/Screenshot
Discovered from microsoft/vscode-containers#367 originally. Related issues:
TypeError: Cannot redefine property: namewhen using esbuild withkeepNames: true, preventing telemetry from being sent vscode-extension-telemetry#237- Webpack
vscode/extension-telemetryto avoid that clients need to know exclusion rules vscode-extension-telemetry#150 - This repo: [BUG] AppInsights breaks Angular SSR in Cloudflare Worker #2523
- This repo: [BUG] AppInsights breaks Angular v20.3.* local development #2643
Quoting my original issue here, but please look there for the most up-to-date:
Boring analysis: the reason it was happening was because we're using
keepNamesin esbuild, to make it not mangle class/function names (which we need if we want useful call stacks). Esbuild writes code into the bundle that, at load time (which is run time), tries to set thenameproperty on the minified classes/functions to the original name.Some of the AppInsights packages are freezing some of their stuff, which makes it impossible to set the
nameproperty. The error that was thrown (and then caught and eaten) would resemble:TypeError: Cannot redefine property: name at defineProperty (<anonymous>) at __name (d:\\vscode-containers\\dist\\extension.bundle.js:8:33) at node_modules/@microsoft/1ds-core-js/dist-es5/AppInsightsCore.js (d:\\vscode-containers\\dist\\extension.bundle.js:16157:5) at __init (d:\\vscode-containers\\dist\\extension.bundle.js:10:56) at node_modules/@microsoft/1ds-core-js/dist-es5/Index.js (d:\\vscode-containers\\dist\\extension.bundle.js:16819:5) at __init (d:\\vscode-containers\\dist\\extension.bundle.js:10:56) at d:\\vscode-containers\\dist\\extension.bundle.js:20303:57 at async getAICore (d:\\vscode-containers\\dist\\extension.bundle.js:20303:21) at async oneDataSystemClientFactory (d:\\vscode-containers\\dist\\extension.bundle.js:20343:29)The end result was that loading the AppInsights packages failed silently, and the AppInsights reporter never got built--so when we logged telemetry events, they were just screamed into the void.
I considered three options. The first was to build the extension as ESM, but unfortunately this just didn't work at all.
The second was to turn off
keepNames...but that would negatively impact both telemetry and the issue reporter by giving us mangled names that we would have to translate after-the-fact if we wanted to investigate.The third was Opus' idea (nice job AI!). Basically, we build the
@vscode/extension-telemetrypackage into its own bundle, withkeepNamesoff, and then build everything else (extension and other dependencies) into the main bundle, with an alias to rewrite imports to@vscode/extension-telemetryto point to the other bundle.
Steps to Reproduce
- Clone and
npm installfrom https://github.com/microsoft/vscode-containers/tree/v2.4.0 - In launch.json, change
DEBUGTELEMETRYenv var to 0 - F5 and do anything in the Container Tools extension
- OS/Browser: Any OS
- SDK Version [e.g. 22]: (Below)
- How you initialized the SDK:
@vscode/extension-telemetry@0.9.9
@microsoft/1ds-core-js@4.3.10
@microsoft/1ds-post-js@4.3.10
@microsoft/applicationinsights-web-basic@3.3.10
Expected behavior
Works with ESBuild without issues