Update connection event properties (#14608)

This commit is contained in:
Charles Gagnon
2021-03-09 08:39:14 -08:00
committed by GitHub
parent e2a5859155
commit b5e66a715f
3 changed files with 38 additions and 36 deletions

View File

@@ -3,7 +3,8 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IAdsTelemetryService, ITelemetryInfo, ITelemetryEvent, ITelemetryConnectionInfo, ITelemetryEventMeasures, ITelemetryEventProperties } from 'sql/platform/telemetry/common/telemetry';
import * as azdata from 'azdata';
import { IAdsTelemetryService, ITelemetryInfo, ITelemetryEvent, ITelemetryEventMeasures, ITelemetryEventProperties } from 'sql/platform/telemetry/common/telemetry';
import { ILogService } from 'vs/platform/log/common/log';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { assign } from 'vs/base/common/objects';
@@ -43,13 +44,23 @@ class TelemetryEventImpl implements ITelemetryEvent {
return this;
}
public withConnectionInfo(connectionInfo: ITelemetryConnectionInfo): ITelemetryEvent {
public withConnectionInfo(connectionInfo?: azdata.IConnectionProfile): ITelemetryEvent {
assign(this._properties,
{
authenticationType: connectionInfo.authenticationType,
providerName: connectionInfo.providerName,
serverType: connectionInfo.serverType,
engineType: connectionInfo.engineType
authenticationType: connectionInfo?.authenticationType,
providerName: connectionInfo?.providerName
});
return this;
}
public withServerInfo(serverInfo?: azdata.ServerInfo): ITelemetryEvent {
assign(this._properties,
{
connectionType: serverInfo?.isCloud !== undefined ? (serverInfo.isCloud ? 'Azure' : 'Standalone') : '',
serverVersion: serverInfo?.serverVersion ?? '',
serverEdition: serverInfo?.serverEdition ?? '',
serverEngineEdition: serverInfo?.engineEditionId ?? '',
isBigDataCluster: serverInfo?.options?.isBigDataCluster ?? false,
});
return this;
}
@@ -64,7 +75,9 @@ class NullTelemetryEventImpl implements ITelemetryEvent {
public withAdditionalMeasurements(additionalMeasurements: ITelemetryEventMeasures): ITelemetryEvent { return this; }
public withConnectionInfo(connectionInfo: ITelemetryConnectionInfo): ITelemetryEvent { return this; }
public withConnectionInfo(connectionInfo: azdata.IConnectionProfile): ITelemetryEvent { return this; }
public withServerInfo(serverInfo: azdata.ServerInfo): ITelemetryEvent { return this; }
}
export class AdsTelemetryService implements IAdsTelemetryService {

View File

@@ -3,6 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IAdsTelemetryService = createDecorator<IAdsTelemetryService>('adsTelemetryService');
@@ -21,16 +22,6 @@ export interface ITelemetryEventMeasures {
[key: string]: number;
}
/**
* Connection info properties to add into an event.
*/
export interface ITelemetryConnectionInfo {
authenticationType?: string;
providerName?: string;
serverType?: string;
engineType?: string;
}
export interface ITelemetryEvent {
/**
* Sends the event
@@ -51,9 +42,15 @@ export interface ITelemetryEvent {
/**
* Adds additional connection-related information to this event.
* @param connectionInfo The connection info to add. Only the fields in TelemetryConnectionInfo are included, all others are ignored.
* @param connectionInfo The connection info to add.
*/
withConnectionInfo(connectionInfo: ITelemetryConnectionInfo): ITelemetryEvent;
withConnectionInfo(connectionInfo?: azdata.IConnectionProfile): ITelemetryEvent;
/**
* Adds additional server-related information to this event.
* @param serverInfo The server info to add.
*/
withServerInfo(serverInfo?: azdata.ServerInfo): ITelemetryEvent;
}
export interface ITelemetryInfo {

View File

@@ -955,14 +955,9 @@ export class ConnectionManagementService extends Disposable implements IConnecti
connection.connectHandler(true);
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Shell, TelemetryKeys.DatabaseConnected)
.withAdditionalProperties({
connectionType: connection.serverInfo ? (connection.serverInfo.isCloud ? 'Azure' : 'Standalone') : '',
provider: connection.connectionProfile.providerName,
serverVersion: connection.serverInfo ? connection.serverInfo.serverVersion : '',
serverEdition: connection.serverInfo ? connection.serverInfo.serverEdition : '',
serverEngineEdition: connection.serverInfo ? connection.serverInfo.engineEditionId : '',
isBigDataCluster: connection.serverInfo?.options?.isBigDataCluster ?? false,
}).withAdditionalMeasurements({
.withConnectionInfo(connection.connectionProfile)
.withServerInfo(connection.serverInfo)
.withAdditionalMeasurements({
extensionConnectionTimeMs: connection.extensionTimer.elapsed() - connection.serviceTimer.elapsed(),
serviceConnectionTimeMs: connection.serviceTimer.elapsed()
})
@@ -974,9 +969,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
} else {
connection.connectHandler(false, info.errorMessage, info.errorNumber, info.messages);
this._telemetryService.createErrorEvent(TelemetryKeys.TelemetryView.Shell, TelemetryKeys.DatabaseConnectionError, info.errorNumber.toString())
.withAdditionalProperties({
provider: connection.connectionProfile.providerName,
})
.withConnectionInfo(connection.connectionProfile)
.withAdditionalMeasurements({
extensionConnectionTimeMs: connection.extensionTimer.elapsed() - connection.serviceTimer.elapsed(),
serviceConnectionTimeMs: connection.serviceTimer.elapsed()
@@ -1131,9 +1124,6 @@ export class ConnectionManagementService extends Disposable implements IConnecti
if (this._connectionStatusManager.isDefaultTypeUri(fileUri)) {
this._connectionGlobalStatus.setStatusToDisconnected(fileUri);
}
// TODO: send telemetry events
// Telemetry.sendTelemetryEvent('DatabaseDisconnected');
}
return result;
@@ -1145,19 +1135,21 @@ export class ConnectionManagementService extends Disposable implements IConnecti
public disconnect(input: string | interfaces.IConnectionProfile): Promise<void> {
let uri: string;
let profile: interfaces.IConnectionProfile;
let info: ConnectionManagementInfo | undefined;
if (typeof input === 'object') {
uri = Utils.generateUri(input);
profile = input;
info = this.getConnectionInfo(uri);
} else if (typeof input === 'string') {
profile = this.getConnectionProfile(input);
info = this.getConnectionInfo(input);
uri = input;
}
return this.doDisconnect(uri, profile).then(result => {
if (result) {
this._telemetryService.createActionEvent(TelemetryKeys.TelemetryView.Shell, TelemetryKeys.DatabaseDisconnected)
.withAdditionalProperties({
provider: profile.providerName
})
.withConnectionInfo(profile)
.withServerInfo(info?.serverInfo)
.send();
this._connectionStatusManager.removeConnection(uri);
} else {