Path: blob/main/extensions/copilot/src/extension/log/vscode-node/extensionStateCommand.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';6import { IAuthenticationService } from '../../../platform/authentication/common/authentication';7import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';8import { ILogService } from '../../../platform/log/common/logService';9import { ITelemetryService } from '../../../platform/telemetry/common/telemetry';10import { Disposable } from '../../../util/vs/base/common/lifecycle';11import { IExtensionContribution } from '../../common/contributions';12import { IToolsService } from '../../tools/common/toolsService';1314export class ExtensionStateCommandContribution extends Disposable implements IExtensionContribution {15id = 'extensionStateCommand';1617constructor(18@ILogService private readonly _logService: ILogService,19@IAuthenticationService private readonly _authenticationService: IAuthenticationService,20@IEndpointProvider private readonly _endpointProvider: IEndpointProvider,21@IToolsService private readonly _toolsService: IToolsService,22@ITelemetryService private readonly _telemetryService: ITelemetryService,23) {24super();2526this._register(vscode.commands.registerCommand('github.copilot.debug.extensionState', async () => {27await this._logExtensionState();28}));29}3031private async _logExtensionState(): Promise<void> {32const lines: string[] = [33'[ExtensionState] ===============================================================',34'[ExtensionState] INCLUDE THIS INFORMATION IF YOU ARE OPENING AN ISSUE',35'[ExtensionState] ===============================================================',36];3738// Auth state39const hasAnySession = !!this._authenticationService.anyGitHubSession;40const hasPermissiveSession = !!this._authenticationService.permissiveGitHubSession;41const hasCopilotToken = !!this._authenticationService.copilotToken;42lines.push(` Auth: anyGitHubSession=${hasAnySession}, repoGitHubSession=${hasPermissiveSession}, copilotToken=${hasCopilotToken}`);4344// Username45const session = this._authenticationService.anyGitHubSession;46if (session) {47lines.push(` Username: ${session.account.label}`);48} else {49lines.push(' Username: (not signed in) - check the GitHub Authentication output channel for more details');50}5152// Proxy setup53const proxySupport = vscode.workspace.getConfiguration('http').get<string>('proxySupport', 'override');54const proxyUrl = vscode.workspace.getConfiguration('http').get<string>('proxy', '');55const proxyConfigured = proxyUrl ? 'true' : 'false';56lines.push(` Proxy: http.proxySupport=${proxySupport}, http.proxy=${proxyUrl ? '(configured)' : '(not configured)'}`);5758let languageModelsLoaded = 'false';59let languageModelCount = 0;60let copilotProviderRegistered = 'false';61let copilotModelCount = 0;62let copilotEmbeddingsRegistered = 'false';63let toolCount = 0;6465if (session) {66// Language models67try {68const endpoints = await this._endpointProvider.getAllChatEndpoints();69languageModelCount = endpoints.length;70languageModelsLoaded = String(endpoints.length > 0);71lines.push(` Language models loaded: ${endpoints.length > 0} (count: ${endpoints.length})`);72} catch (e) {73lines.push(` Language models loaded: false (error: ${e})`);74}7576// Copilot chat provider registration77try {78const copilotModels = await vscode.lm.selectChatModels({ vendor: 'copilot' });79copilotModelCount = copilotModels.length;80copilotProviderRegistered = String(copilotModels.length > 0);81lines.push(` Copilot chat provider registered: ${copilotModels.length > 0} (models: ${copilotModels.length})`);82} catch (e) {83lines.push(` Copilot chat provider registered: false (error: ${e})`);84}8586// Copilot embeddings model registration87const copilotEmbeddings = vscode.lm.embeddingModels.filter(m => m.startsWith('copilot.'));88copilotEmbeddingsRegistered = String(copilotEmbeddings.length > 0);89lines.push(` Copilot embeddings model registered: ${copilotEmbeddings.length > 0} (models: [${copilotEmbeddings.join(', ')}])`);9091// Tools92toolCount = this._toolsService.tools.length;93lines.push(` Tools loaded: ${toolCount > 0} (count: ${toolCount})`);94}9596lines.push('[ExtensionState] ===============================================================');9798this._logService.info(lines.join('\n'));99100/* __GDPR__101"extensionState" : {102"owner": "TylerLeonhardt",103"comment": "Extension state diagnostic information",104"hasAnySession": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether a GitHub session exists" },105"hasPermissiveSession": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether a permissive GitHub session exists" },106"hasCopilotToken": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether a Copilot token exists" },107"proxySupport": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The http.proxySupport setting value" },108"proxyConfigured": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether an http proxy is configured" },109"languageModelsLoaded": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether language models are loaded" },110"copilotProviderRegistered": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether the Copilot chat provider is registered" },111"copilotEmbeddingsRegistered": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether Copilot embeddings models are registered" },112"languageModelCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Number of language models loaded", "isMeasurement": true },113"copilotModelCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Number of Copilot chat models", "isMeasurement": true },114"toolCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Number of tools loaded", "isMeasurement": true }115}116*/117this._telemetryService.sendMSFTTelemetryEvent(118'extensionState',119{120hasAnySession: String(hasAnySession),121hasPermissiveSession: String(hasPermissiveSession),122hasCopilotToken: String(hasCopilotToken),123proxySupport,124proxyConfigured,125languageModelsLoaded,126copilotProviderRegistered,127copilotEmbeddingsRegistered,128},129{130languageModelCount,131copilotModelCount,132toolCount,133}134);135}136}137138139