Path: blob/main/src/vs/platform/externalServices/common/marketplace.ts
3296 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 { IHeaders } from '../../../base/parts/request/common/request.js';6import { IConfigurationService } from '../../configuration/common/configuration.js';7import { IEnvironmentService } from '../../environment/common/environment.js';8import { getServiceMachineId } from './serviceMachineId.js';9import { IFileService } from '../../files/common/files.js';10import { IProductService } from '../../product/common/productService.js';11import { IStorageService } from '../../storage/common/storage.js';12import { ITelemetryService, TelemetryLevel } from '../../telemetry/common/telemetry.js';13import { getTelemetryLevel, supportsTelemetry } from '../../telemetry/common/telemetryUtils.js';1415export async function resolveMarketplaceHeaders(version: string,16productService: IProductService,17environmentService: IEnvironmentService,18configurationService: IConfigurationService,19fileService: IFileService,20storageService: IStorageService | undefined,21telemetryService: ITelemetryService): Promise<IHeaders> {2223const headers: IHeaders = {24'X-Market-Client-Id': `VSCode ${version}`,25'User-Agent': `VSCode ${version} (${productService.nameShort})`26};2728if (supportsTelemetry(productService, environmentService) && getTelemetryLevel(configurationService) === TelemetryLevel.USAGE) {29const serviceMachineId = await getServiceMachineId(environmentService, fileService, storageService);30headers['X-Market-User-Id'] = serviceMachineId;31// Send machineId as VSCode-SessionId so we can correlate telemetry events across different services32// machineId can be undefined sometimes (eg: when launching from CLI), so send serviceMachineId instead otherwise33// Marketplace will reject the request if there is no VSCode-SessionId header34headers['VSCode-SessionId'] = telemetryService.machineId || serviceMachineId;35}3637return headers;38}394041