Skip to content

Commit

Permalink
Merge pull request #153271 from prashantvc/issue2961
Browse files Browse the repository at this point in the history
Added the `VSCode-SessionId` for extension queries Issue2961
  • Loading branch information
sandy081 authored Jun 28, 2022
2 parents 5feeb83 + 44a89e5 commit a69f95f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,14 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
const config = productService.extensionsGallery;
this.extensionsGalleryUrl = config && config.serviceUrl;
this.extensionsControlUrl = config && config.controlUrl;
this.commonHeadersPromise = resolveMarketplaceHeaders(productService.version, productService, this.environmentService, this.configurationService, this.fileService, storageService);
this.commonHeadersPromise = resolveMarketplaceHeaders(
productService.version,
productService,
this.environmentService,
this.configurationService,
this.fileService,
storageService,
this.telemetryService);
}

private api(path = ''): string {
Expand Down Expand Up @@ -928,7 +935,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
'Content-Type': 'application/json',
'Accept': 'application/json;api-version=3.0-preview.1',
'Accept-Encoding': 'gzip',
'Content-Length': String(data.length)
'Content-Length': String(data.length),
};

const startTime = new Date().getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { resolveMarketplaceHeaders } from 'vs/platform/externalServices/common/m
import { InMemoryStorageService, IStorageService } from 'vs/platform/storage/common/storage';
import { TelemetryConfiguration, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
import { TargetPlatform } from 'vs/platform/extensions/common/extensions';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';

class EnvironmentServiceMock extends mock<IEnvironmentService>() {
override readonly serviceMachineIdResource: URI;
Expand Down Expand Up @@ -52,9 +53,9 @@ suite('Extension Gallery Service', () => {
teardown(() => disposables.clear());

test('marketplace machine id', async () => {
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService);
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, NullTelemetryService);
assert.ok(isUUID(headers['X-Market-User-Id']));
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService);
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, NullTelemetryService);
assert.strictEqual(headers['X-Market-User-Id'], headers2['X-Market-User-Id']);
});

Expand Down
13 changes: 11 additions & 2 deletions src/vs/platform/externalServices/common/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ import { getServiceMachineId } from 'vs/platform/externalServices/common/service
import { IFileService } from 'vs/platform/files/common/files';
import { IProductService } from 'vs/platform/product/common/productService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';

export async function resolveMarketplaceHeaders(version: string, productService: IProductService, environmentService: IEnvironmentService, configurationService: IConfigurationService, fileService: IFileService, storageService: IStorageService | undefined): Promise<IHeaders> {
export async function resolveMarketplaceHeaders(version: string,
productService: IProductService,
environmentService: IEnvironmentService,
configurationService: IConfigurationService,
fileService: IFileService,
storageService: IStorageService | undefined,
telemetryService: ITelemetryService): Promise<IHeaders> {
const headers: IHeaders = {
'X-Market-Client-Id': `VSCode ${version}`,
'User-Agent': `VSCode ${version} (${productService.nameShort})`
};
const uuid = await getServiceMachineId(environmentService, fileService, storageService);
const { sessionId } = await telemetryService.getTelemetryInfo();

if (supportsTelemetry(productService, environmentService) && getTelemetryLevel(configurationService) === TelemetryLevel.USAGE) {
headers['X-Market-User-Id'] = uuid;
headers['VSCode-SessionId'] = sessionId;
}
return headers;
}
9 changes: 8 additions & 1 deletion src/vs/platform/windows/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,14 @@ export class CodeWindow extends Disposable implements ICodeWindow {
private marketplaceHeadersPromise: Promise<object> | undefined;
private getMarketplaceHeaders(): Promise<object> {
if (!this.marketplaceHeadersPromise) {
this.marketplaceHeadersPromise = resolveMarketplaceHeaders(this.productService.version, this.productService, this.environmentMainService, this.configurationService, this.fileService, this.applicationStorageMainService);
this.marketplaceHeadersPromise = resolveMarketplaceHeaders(
this.productService.version,
this.productService,
this.environmentMainService,
this.configurationService,
this.fileService,
this.applicationStorageMainService,
this.telemetryService);
}

return this.marketplaceHeadersPromise;
Expand Down

0 comments on commit a69f95f

Please sign in to comment.