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
Clean up CallstackOrException telemetry in typescript-language-features #96108
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type * as Proto from '../protocol'; | ||
import { escapeRegExp } from '../utils/regexp'; | ||
import { TypeScriptVersion } from '../utils/versionProvider'; | ||
|
||
|
||
|
@@ -14,16 +13,17 @@ export class TypeScriptServerError extends Error { | |
version: TypeScriptVersion, | ||
response: Proto.Response | ||
): TypeScriptServerError { | ||
const parsedResult = TypeScriptServerError.parseErrorText(version, response); | ||
return new TypeScriptServerError(serverId, version, response, parsedResult?.message, parsedResult?.stack); | ||
const parsedResult = TypeScriptServerError.parseErrorText(response); | ||
return new TypeScriptServerError(serverId, version, response, parsedResult?.message, parsedResult?.stack, parsedResult?.sanitizedStack); | ||
} | ||
|
||
private constructor( | ||
serverId: string, | ||
public readonly version: TypeScriptVersion, | ||
private readonly response: Proto.Response, | ||
public readonly serverMessage: string | undefined, | ||
public readonly serverStack: string | undefined | ||
public readonly serverStack: string | undefined, | ||
private readonly sanitizedStack: string | undefined | ||
) { | ||
super(`<${serverId}> TypeScript Server Error (${version.displayName})\n${serverMessage}\n${serverStack}`); | ||
} | ||
|
@@ -33,47 +33,38 @@ export class TypeScriptServerError extends Error { | |
public get serverCommand() { return this.response.command; } | ||
|
||
public get telemetry() { | ||
// The "sanitizedstack" has been purged of error messages, paths, and file names (other than tsserver) | ||
// and, thus, can be classified as SystemMetaData, rather than CallstackOrException. | ||
/* __GDPR__FRAGMENT__ | ||
"TypeScriptRequestErrorProperties" : { | ||
"command" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, | ||
"message" : { "classification": "CallstackOrException", "purpose": "PerformanceAndHealth" }, | ||
"stack" : { "classification": "CallstackOrException", "purpose": "PerformanceAndHealth" }, | ||
"errortext" : { "classification": "CallstackOrException", "purpose": "PerformanceAndHealth" } | ||
"sanitizedstack" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, | ||
} | ||
*/ | ||
return { | ||
command: this.serverCommand, | ||
message: this.serverMessage || '', | ||
stack: this.serverStack || '', | ||
errortext: this.serverErrorText || '', | ||
sanitizedstack: this.sanitizedStack || '', | ||
} as const; | ||
} | ||
|
||
/** | ||
* Given a `errorText` from a tsserver request indicating failure in handling a request, | ||
* prepares a payload for telemetry-logging. | ||
*/ | ||
private static parseErrorText(version: TypeScriptVersion, response: Proto.Response) { | ||
private static parseErrorText(response: Proto.Response) { | ||
const errorText = response.message; | ||
if (errorText) { | ||
const errorPrefix = 'Error processing request. '; | ||
if (errorText.startsWith(errorPrefix)) { | ||
let prefixFreeErrorText = errorText.substr(errorPrefix.length); | ||
|
||
// Prior to https://github.com/microsoft/TypeScript/pull/32785, this error | ||
// returned and excessively long and detailed list of paths. Since server-side | ||
// filtering doesn't have sufficient granularity to drop these specific | ||
// messages, we sanitize them here. | ||
if (prefixFreeErrorText.indexOf('Could not find sourceFile') >= 0) { | ||
prefixFreeErrorText = prefixFreeErrorText.replace(/ in \[[^\]]*\]/g, ''); | ||
} | ||
|
||
const prefixFreeErrorText = errorText.substr(errorPrefix.length); | ||
const newlineIndex = prefixFreeErrorText.indexOf('\n'); | ||
if (newlineIndex >= 0) { | ||
// Newline expected between message and stack. | ||
const stack = prefixFreeErrorText.substring(newlineIndex + 1); | ||
return { | ||
message: prefixFreeErrorText.substring(0, newlineIndex), | ||
stack: TypeScriptServerError.normalizeMessageStack(version, prefixFreeErrorText.substring(newlineIndex + 1)) | ||
stack, | ||
sanitizedStack: TypeScriptServerError.sanitizeStack(stack) | ||
}; | ||
} | ||
} | ||
|
@@ -82,12 +73,23 @@ export class TypeScriptServerError extends Error { | |
} | ||
|
||
/** | ||
* Try to replace full TS Server paths with 'tsserver.js' so that we don't have to post process the data as much | ||
* Drop everything but ".js" and line/column numbers (though retain "tsserver" if that's the filename). | ||
*/ | ||
private static normalizeMessageStack(version: TypeScriptVersion, message: string | undefined) { | ||
private static sanitizeStack(message: string | undefined) { | ||
if (!message) { | ||
return ''; | ||
} | ||
return message.replace(new RegExp(`${escapeRegExp(version.path)}[/\\\\]tsserver.js:`, 'gi'), 'tsserver.js:'); | ||
const regex = /(tsserver)?(\.(?:ts|tsx|js|jsx)(?::\d+(?::\d+))?)\)?$/igm; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This moves us from an exclusion list to an inclusion list, so it should be impossible for customer data to slip through. |
||
let serverStack = ''; | ||
while (true) { | ||
const match = regex.exec(message); | ||
if (!match) { | ||
break; | ||
} | ||
// [1] is 'tsserver' or undefined | ||
// [2] is '.js:{line_number}:{column_number}' | ||
serverStack += `${match[1] || 'suppressed'}${match[2]}\n`; | ||
} | ||
return serverStack; | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe dropping these causes them to be on the server side?