Skip to content
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

chore: Sending experience telemetry property #2538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/resolver/AppResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { API, tryGetExperience } from '../AzureDBExperiences';
import { type DocDBAccountTreeItem } from '../docdb/tree/DocDBAccountTreeItem';
import { ext } from '../extensionVariables';
import { type MongoAccountTreeItem } from '../mongo/tree/MongoAccountTreeItem';
import { type PostgresAbstractServer } from '../postgres/abstract/models';
import { PostgresServerType, type PostgresAbstractServer } from '../postgres/abstract/models';
import { type PostgresServerTreeItem } from '../postgres/tree/PostgresServerTreeItem';
import { SubscriptionTreeItem } from '../tree/SubscriptionTreeItem';
import { createCosmosDBClient, createPostgreSQLClient, createPostgreSQLFlexibleClient } from '../utils/azureClients';
Expand Down Expand Up @@ -74,6 +74,10 @@ export class DatabaseResolver implements AppResourceResolver {
: await createPostgreSQLFlexibleClient({ ...context, ...subContext });

postgresServer = await postgresClient.servers.get(resourceGroupName, name);
postgresServer.serverType ??=
resource.type.toLowerCase() === resourceTypes[1]
? PostgresServerType.Single
: PostgresServerType.Flexible;
dbChild = await SubscriptionTreeItem.initPostgresChild(postgresServer, nonNullValue(subNode));

return new ResolvedPostgresServerResource(dbChild as PostgresServerTreeItem, resource);
Expand Down
64 changes: 40 additions & 24 deletions src/tree/AttachedAccountsTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import {
appendExtensionUserAgent,
AzExtParentTreeItem,
callWithTelemetryAndErrorHandling,
GenericTreeItem,
type AzExtTreeItem,
type IActionContext,
Expand Down Expand Up @@ -335,31 +336,46 @@ export class AttachedAccountsTreeItem extends AzExtParentTreeItem {
const accounts: (string | IPersistedAccount)[] = JSON.parse(value);
await Promise.all(
accounts.map(async (account) => {
let id: string;
let label: string;
let api: API;
let isEmulator: boolean | undefined;
if (typeof account === 'string') {
// Default to Mongo if the value is a string for the sake of backwards compatibility
// (Mongo was originally the only account type that could be attached)
id = account;
api = API.MongoDB;
label = `${account} (${getExperienceFromApi(api).shortName})`;
isEmulator = false;
} else {
id = (<IPersistedAccount>account).id;
api = (<IPersistedAccount>account).defaultExperience;
isEmulator = (<IPersistedAccount>account).isEmulator;
label = isEmulator
? `${getExperienceFromApi(api).shortName} Emulator`
: `${id} (${getExperienceFromApi(api).shortName})`;
}
// TODO: keytar: migration plan?
const connectionString: string = nonNullValue(
await ext.secretStorage.get(getSecretStorageKey(this._serviceName, id)),
'connectionString',
await callWithTelemetryAndErrorHandling(
'cosmosDB.initCosmosDBChild', // The same name as for CosmosDB because API has Postgres in it
async (context: IActionContext) => {
let id: string;
let label: string;
let api: API;
let isEmulator: boolean | undefined;
if (typeof account === 'string') {
// Default to Mongo if the value is a string for the sake of backwards compatibility
// (Mongo was originally the only account type that could be attached)
id = account;
api = API.MongoDB;
label = `${account} (${getExperienceFromApi(api).shortName})`;
isEmulator = false;
} else {
id = (<IPersistedAccount>account).id;
api = (<IPersistedAccount>account).defaultExperience;
isEmulator = (<IPersistedAccount>account).isEmulator;
label = isEmulator
? `${getExperienceFromApi(api).shortName} Emulator`
: `${id} (${getExperienceFromApi(api).shortName})`;
}
// TODO: keytar: migration plan?
const connectionString: string = nonNullValue(
await ext.secretStorage.get(getSecretStorageKey(this._serviceName, id)),
'connectionString',
);

context.valuesToMask.push(id);
context.valuesToMask.push(label);
context.valuesToMask.push(connectionString);
context.telemetry.properties.experience = api;
context.telemetry.properties.isAttached = 'true';
context.telemetry.properties.isEmulator = String(isEmulator);

persistedAccounts.push(
await this.createTreeItem(connectionString, api, label, id, isEmulator),
);
},
);
persistedAccounts.push(await this.createTreeItem(connectionString, api, label, id, isEmulator));
}),
);
}
Expand Down
23 changes: 19 additions & 4 deletions src/tree/SubscriptionTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,25 @@ export class SubscriptionTreeItem extends SubscriptionTreeItemBase {
server: PostgresAbstractServer,
parent: AzExtParentTreeItem,
): Promise<AzExtTreeItem> {
const connectionString: string = createPostgresConnectionString(
nonNullProp(server, 'fullyQualifiedDomainName'),
const newNode = await callWithTelemetryAndErrorHandling(
'cosmosDB.initCosmosDBChild', // The same name as for CosmosDB because API has Postgres in it
(context: IActionContext) => {
// leave error handling to the caller (command or tree node)
context.errorHandling.suppressDisplay = true;
context.telemetry.properties.experience =
server.serverType === PostgresServerType.Single ? API.PostgresSingle : API.PostgresFlexible;

const connectionString: string = createPostgresConnectionString(
nonNullProp(server, 'fullyQualifiedDomainName'),
);
const parsedCS: ParsedPostgresConnectionString = parsePostgresConnectionString(connectionString);
return new PostgresServerTreeItem(parent, parsedCS, server);
},
);
const parsedCS: ParsedPostgresConnectionString = parsePostgresConnectionString(connectionString);
return new PostgresServerTreeItem(parent, parsedCS, server);
if (!(newNode instanceof AzExtTreeItem)) {
// note: this should never happen, callWithTelemetryAndErrorHandling will rethrow all errors
throw new Error(localize('invalidCosmosDBAccount', 'Invalid Cosmos DB account.'));
}
return newNode;
}
}
Loading