Skip to content

Commit

Permalink
Sanitize unknownapiversion telemetry (#1435)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Weatherford <[email protected]>
  • Loading branch information
StephenWeatherford and Stephen Weatherford authored Jan 14, 2022
1 parent 55220a1 commit 65aaa4a
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/languageclient/startArmLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,24 @@ async function startLanguageClient(serverDllPath: string, dotnetExePath: string)

client.onTelemetry((telemetryData: { eventName: string; properties: { [key: string]: string | undefined } }) => {
const eventName = telemetryData.eventName.replace(/^\/|\/$/g, ""); // Remove slashes at beginning or end
callWithTelemetryAndErrorHandlingSync(`langserver/${eventName}`, telemetryActionContext => {
telemetryActionContext.errorHandling.suppressDisplay = true;
const fullEventName = `langserver/${eventName}`;

for (let prop of Object.getOwnPropertyNames(telemetryData.properties)) {
const value = telemetryData.properties[prop];
prop = prop.replace(/^\./g, ""); // Remove starting period
telemetryActionContext.telemetry.properties[prop] = String(value);
}
if (sanitizeTelemetryData(fullEventName, telemetryData.properties)
) {
callWithTelemetryAndErrorHandlingSync(fullEventName, telemetryActionContext => {
telemetryActionContext.errorHandling.suppressDisplay = true;

if (telemetryActionContext.telemetry.properties.error) {
telemetryActionContext.telemetry.properties.result = 'Failed';
}
});
for (let prop of Object.getOwnPropertyNames(telemetryData.properties)) {
const value = telemetryData.properties[prop];
prop = prop.replace(/^\./g, ""); // Remove starting period
telemetryActionContext.telemetry.properties[prop] = String(value);
}

if (telemetryActionContext.telemetry.properties.error) {
telemetryActionContext.telemetry.properties.result = 'Failed';
}
});
}
});

try {
Expand Down Expand Up @@ -289,6 +294,26 @@ async function startLanguageClient(serverDllPath: string, dotnetExePath: string)
});
}

function sanitizeTelemetryData(fullEventName: string, properties: { [key: string]: string | undefined }): boolean {
switch (fullEventName) {
case 'langserver/VS/WebTools/Languages/JSON/UnrecognizedResourceApiVersion':
if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}(-(alpha|beta|preview)+)?$/i.test(properties['vS.WebTools.Languages.JSON.apiVersion'] ?? '')) {
{
return false;
}
}

properties['vS.WebTools.Languages.JSON.apiVersion'] = properties['vS.WebTools.Languages.JSON.apiVersion']?.toLowerCase();
properties['vS.WebTools.Languages.JSON.type'] = properties['vS.WebTools.Languages.JSON.type']
?.replace('/', '@')
.toLowerCase();
return true;

default:
return true;
}
}

async function getDotNetPath(): Promise<string | undefined> {
return await callWithTelemetryAndErrorHandling("getDotNetPath", async (actionContext: IActionContext) => {
actionContext.errorHandling.rethrow = true;
Expand Down

0 comments on commit 65aaa4a

Please sign in to comment.