-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add instrumentation support to the typescript code #12991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2c3dcd4
add instrumentation support to the typescript code
fearthecowboy 8db9949
fix linter
fearthecowboy ad614bf
missed file
fearthecowboy 1b3c84e
update to a newer image?
fearthecowboy 73abb77
Merge branch 'main' into dev/garretts/instrumentation
fearthecowboy 47f172e
merged from main
fearthecowboy 8c6e727
merged
fearthecowboy ad53e59
Merge branch 'dev/garretts/instrumentation' of https://github.com/mic…
fearthecowboy 53dd899
work around webpack
fearthecowboy c5d8af4
webpack! Arg!
fearthecowboy 35172cb
Merge branch 'main' of https://github.com/microsoft/vscode-cpptools i…
fearthecowboy fbb07e6
cleanup
fearthecowboy d272d97
cleanups
fearthecowboy 9a22dc2
remove spaces
fearthecowboy b147b2b
must use eval to work around webpack
fearthecowboy 86c26c1
Merge branch 'main' of https://github.com/microsoft/vscode-cpptools i…
fearthecowboy 2b87424
need vscode in here
fearthecowboy 9270034
Merge branch 'main' of https://github.com/microsoft/vscode-cpptools i…
fearthecowboy 30044a4
Merge branch 'main' of https://github.com/microsoft/vscode-cpptools i…
fearthecowboy b016317
fix line endings?
fearthecowboy 4c206b2
fix line endings?
fearthecowboy d71e4fb
Add comment
fearthecowboy 9d09405
Merge branch 'main' of https://github.com/microsoft/vscode-cpptools i…
fearthecowboy 0a2c368
Merge branch 'dev/garretts/instrumentation' of https://github.com/mic…
fearthecowboy fe6a369
Added instrumentation to copilothoverprovider
fearthecowboy 249f93e
Merge branch 'main' into dev/garretts/instrumentation
fearthecowboy 0823147
inject instrumentation code via perfecto instead
fearthecowboy 20749be
Merge branch 'dev/garretts/instrumentation' of https://github.com/mic…
fearthecowboy d2adad4
Merge branch 'main' into dev/garretts/instrumentation
fearthecowboy b0a4968
Ensure that everything is instrumented where we can.
fearthecowboy a4d3760
extra comma
fearthecowboy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
* See 'LICENSE' in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
'use strict'; | ||
|
||
/* eslint @typescript-eslint/no-var-requires: "off" */ | ||
|
||
export interface PerfMessage<TInput = Record<string, any> | undefined> { | ||
/** this is the 'name' of the event */ | ||
name: string; | ||
|
||
/** this indicates the context or origin of the message */ | ||
context: Record<string, string | Set<string>>; | ||
|
||
/** if the message contains complex data, it should be in here */ | ||
data?: TInput; | ||
|
||
/** if the message is just a text message, this is the contents of the message */ | ||
text?: string; | ||
|
||
/** the message can have a numeric value that indicates the 'level' or 'severity' etc */ | ||
level?: number; | ||
} | ||
|
||
const services = { | ||
instrument: <T extends Record<string, any>>(instance: T, _options?: { ignore?: string[]; name?: string }): T => instance, | ||
message: (_message: PerfMessage) => { }, | ||
init: (_vscode: any) => { }, | ||
launchSettings: undefined as Record<string, any> | undefined | ||
}; | ||
|
||
/** Adds instrumentation to all the members of an object when instrumentation is enabled */ | ||
export function instrument<T extends Record<string, any>>(instance: T, options?: { ignore?: string[]; name?: string }): T { | ||
return services.instrument(instance, options); | ||
} | ||
|
||
/** sends a perf message to the monitor */ | ||
export function sendInstrumentation(message: PerfMessage): void { | ||
services.message(message); | ||
} | ||
|
||
/** verifies that the instrumentation is loaded into the global namespace */ | ||
export function isInstrumentationEnabled(): boolean { | ||
return !!(global as any).instrumentation; | ||
fearthecowboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// if the instrumentation code is not globally loaded *yet*, then load it now. | ||
if (!isInstrumentationEnabled()) { | ||
// pull the launch settings from the environment if the variable has been set. | ||
if (services.launchSettings === undefined) { | ||
services.launchSettings = process.env.PERFECTO_LAUNCH_SETTINGS ? JSON.parse(process.env.PERFECTO_LAUNCH_SETTINGS) as Record<string, any> : { tests: [], collector: undefined }; | ||
} | ||
|
||
// this loads the bootstrap module (global-instrumentation-support) which adds some global functions. | ||
if (services.launchSettings?.bootstrapModule) { | ||
// work around for webpack to load the bootstrap module. | ||
/* eslint no-eval: "off" */ | ||
eval(`require`)(services.launchSettings.bootstrapModule); | ||
} | ||
} | ||
|
||
// If the instrumentation object was *actually* loaded then we can set the services from the global object. | ||
// Having this separate ensures that this module is wired up to the global object. | ||
// It's not included in the previous block because if something else loads the instrumentation code first | ||
fearthecowboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// this is still needed so that *this* module is properly connected to the global object. | ||
if (isInstrumentationEnabled()) { | ||
fearthecowboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// instrumentation services provided by the tool | ||
services.instrument = (global as any).instrumentation.instrument; | ||
services.message = (global as any).instrumentation.message; | ||
services.init = (global as any).instrumentation.init; | ||
|
||
services.init(require('vscode')); | ||
} | ||
|
||
(globalThis as any)["_vscode_"] = require('vscode'); | ||
fearthecowboy marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.