Skip to content

Commit

Permalink
Update telemetry API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Dec 19, 2024
1 parent 7c22e42 commit db2a828
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 23 deletions.
17 changes: 13 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}

const manifest = context.extension.packageJSON;
reporter = new TelemetryReporter(context.extension.id, manifest.version, manifest.appInsightsKey);
reporter = new TelemetryReporter(manifest.appInsightsKey);
context.subscriptions.push(reporter);

// always register commands needed to control terraform-ls
Expand Down Expand Up @@ -102,7 +102,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
initializationFailedHandler: (error: ResponseError<InitializeError> | Error) => {
initializationError = error;

reporter.sendTelemetryException(error);
reporter.sendTelemetryErrorEvent('initializationError', {
message: error.message,
stack: error.stack,
code: error instanceof ResponseError ? error.code.toString() : undefined,
});

let msg = 'Failure to start terraform-ls. Please check your configuration settings and reload this window';

Expand Down Expand Up @@ -235,12 +239,17 @@ export async function deactivate(): Promise<void> {
} catch (error) {
if (error instanceof Error) {
outputChannel.appendLine(error.message);
reporter.sendTelemetryException(error);
reporter.sendTelemetryErrorEvent('deactivate', {
message: error.message,
stack: error.stack,
});
vscode.window.showErrorMessage(error.message);
lsStatus.setLanguageServerState(error.message, false, vscode.LanguageStatusSeverity.Error);
} else if (typeof error === 'string') {
outputChannel.appendLine(error);
reporter.sendTelemetryException(new Error(error));
reporter.sendTelemetryErrorEvent('deactivate', {
message: error,
});
vscode.window.showErrorMessage(error);
lsStatus.setLanguageServerState(error, false, vscode.LanguageStatusSeverity.Error);
}
Expand Down
6 changes: 5 additions & 1 deletion src/features/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export class TelemetryFeature implements StaticFeature {
return;
}

this.reporter.sendRawTelemetryEvent(event.name, event.properties);
const thing: Record<string, string> = {};
for (const [key, value] of Object.entries(event.properties)) {
thing[key] = String(value);
}
this.reporter.sendRawTelemetryEvent(event.name, thing);
}),
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/providers/tfc/applyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export class ApplyTreeDataProvider implements vscode.TreeDataProvider<vscode.Tre
if (error instanceof Error) {
message += error.message;
vscode.window.showErrorMessage(message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('applyLogError', {
message: message,
stack: error.stack,
});
return;
}

Expand Down
19 changes: 15 additions & 4 deletions src/providers/tfc/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ class TerraformCloudSessionHandler {
if ((error.response.status as number) === 401) {
throw new InvalidToken();
}
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('storeSession', {
message: error.message,
stack: error.stack,
});
throw new Error(`Failed to login: ${apiErrorsToString(error.response.data.errors)}`);
} else if (error instanceof Error) {
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('storeSession', {
message: error.message,
stack: error.stack,
});
}

throw error;
Expand Down Expand Up @@ -243,11 +249,16 @@ export class TerraformCloudAuthenticationProvider implements vscode.Authenticati
return this.createSession(_scopes);
} else if (error instanceof Error) {
vscode.window.showErrorMessage(error.message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('invalidHCPToken', {
message: error.message,
stack: error.stack,
});
this.logger.error(error.message);
} else if (typeof error === 'string') {
vscode.window.showErrorMessage(error);
this.reporter.sendTelemetryException(new Error(error));
this.reporter.sendTelemetryErrorEvent('invalidHCPToken', {
message: error,
});
this.logger.error(error);
}

Expand Down
10 changes: 8 additions & 2 deletions src/providers/tfc/organizationPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ export class OrganizationAPIResource implements APIResource {
return picks;
} else if (isErrorFromAlias(apiClient.api, 'listOrganizations', error)) {
message += apiErrorsToString(error.response.data.errors);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('orgranizationFetchError', {
message: message,
stack: error.stack,
});
} else if (error instanceof Error) {
message += error.message;
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('orgranizationFetchError', {
message: message,
stack: error.stack,
});
} else if (typeof error === 'string') {
message += error;
}
Expand Down
5 changes: 4 additions & 1 deletion src/providers/tfc/planProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ export class PlanTreeDataProvider implements vscode.TreeDataProvider<vscode.Tree
if (error instanceof Error) {
message += error.message;
vscode.window.showErrorMessage(message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('planLogError', {
message: message,
stack: error.stack,
});
return;
}

Expand Down
10 changes: 8 additions & 2 deletions src/providers/tfc/runProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,21 @@ export class RunTreeDataProvider implements vscode.TreeDataProvider<TFCRunTreeIt
if (isErrorFromAlias(apiClient.api, 'listRuns', error)) {
message += apiErrorsToString(error.response.data.errors);
vscode.window.showErrorMessage(message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('runProviderError', {
message: message,
stack: error.stack,
});
return [];
}
}

if (error instanceof Error) {
message += error.message;
vscode.window.showErrorMessage(message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('runProviderError', {
message: message,
stack: error.stack,
});
return [];
}

Expand Down
5 changes: 4 additions & 1 deletion src/providers/tfc/uiHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export async function handleZodiosError(
outputChannel: vscode.OutputChannel,
reporter: TelemetryReporter,
) {
reporter.sendTelemetryException(error);
reporter.sendTelemetryErrorEvent('zodiosError', {
message: error.message,
stack: error.stack,
});
outputChannel.append(JSON.stringify({ cause: error.cause }, undefined, 2));
const chosenItem = await vscode.window.showErrorMessage(
`${msgPrefix} Response validation failed. Please report this as a bug.`,
Expand Down
10 changes: 8 additions & 2 deletions src/providers/tfc/workspaceFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ export class ProjectsAPIResource implements APIResource {
return picks;
} else if (isErrorFromAlias(apiClient.api, 'listProjects', error)) {
message += apiErrorsToString(error.response.data.errors);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('projectWorkspaceFetchError', {
message: message,
stack: error.stack,
});
} else if (error instanceof Error) {
message += error.message;
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('projectWorkspaceFetchError', {
message: message,
stack: error.stack,
});
} else if (typeof error === 'string') {
message += error;
}
Expand Down
10 changes: 8 additions & 2 deletions src/providers/tfc/workspaceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,21 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<vscode
) {
message += apiErrorsToString(error.response.data.errors);
vscode.window.showErrorMessage(message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('workspaceProviderError', {
message: message,
stack: error.stack,
});
return [];
}
}

if (error instanceof Error) {
message += error.message;
vscode.window.showErrorMessage(message);
this.reporter.sendTelemetryException(error);
this.reporter.sendTelemetryErrorEvent('workspaceProviderError', {
message: message,
stack: error.stack,
});
return [];
}

Expand Down
9 changes: 7 additions & 2 deletions src/utils/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ export async function handleLanguageClientStartError(
return;
} else if (error instanceof Error) {
message = error.message;
reporter.sendTelemetryException(error);
reporter.sendTelemetryErrorEvent('extensionStartError', {
message: message,
stack: error.stack,
});
} else if (typeof error === 'string') {
message = error;
reporter.sendTelemetryException(new Error(error));
reporter.sendTelemetryErrorEvent('extensionStartError', {
message: error,
});
}

if (message === 'INVALID_URI_WSL') {
Expand Down
2 changes: 1 addition & 1 deletion src/web/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let reporter: TelemetryReporter;

export function activate(context: vscode.ExtensionContext) {
const manifest = context.extension.packageJSON;
reporter = new TelemetryReporter(context.extension.id, manifest.version, manifest.appInsightsKey);
reporter = new TelemetryReporter(manifest.appInsightsKey);
context.subscriptions.push(reporter);
context.subscriptions.push(outputChannel);

Expand Down

0 comments on commit db2a828

Please sign in to comment.