Skip to content

Commit a69f95f

Browse files
authored
Merge pull request microsoft#153271 from prashantvc/issue2961
Added the `VSCode-SessionId` for extension queries Issue2961
2 parents 5feeb83 + 44a89e5 commit a69f95f

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/vs/platform/extensionManagement/common/extensionGalleryService.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,14 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
584584
const config = productService.extensionsGallery;
585585
this.extensionsGalleryUrl = config && config.serviceUrl;
586586
this.extensionsControlUrl = config && config.controlUrl;
587-
this.commonHeadersPromise = resolveMarketplaceHeaders(productService.version, productService, this.environmentService, this.configurationService, this.fileService, storageService);
587+
this.commonHeadersPromise = resolveMarketplaceHeaders(
588+
productService.version,
589+
productService,
590+
this.environmentService,
591+
this.configurationService,
592+
this.fileService,
593+
storageService,
594+
this.telemetryService);
588595
}
589596

590597
private api(path = ''): string {
@@ -928,7 +935,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
928935
'Content-Type': 'application/json',
929936
'Accept': 'application/json;api-version=3.0-preview.1',
930937
'Accept-Encoding': 'gzip',
931-
'Content-Length': String(data.length)
938+
'Content-Length': String(data.length),
932939
};
933940

934941
const startTime = new Date().getTime();

src/vs/platform/extensionManagement/test/common/extensionGalleryService.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { resolveMarketplaceHeaders } from 'vs/platform/externalServices/common/m
2323
import { InMemoryStorageService, IStorageService } from 'vs/platform/storage/common/storage';
2424
import { TelemetryConfiguration, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
2525
import { TargetPlatform } from 'vs/platform/extensions/common/extensions';
26+
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
2627

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

5455
test('marketplace machine id', async () => {
55-
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService);
56+
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, NullTelemetryService);
5657
assert.ok(isUUID(headers['X-Market-User-Id']));
57-
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService);
58+
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, NullTelemetryService);
5859
assert.strictEqual(headers['X-Market-User-Id'], headers2['X-Market-User-Id']);
5960
});
6061

src/vs/platform/externalServices/common/marketplace.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@ import { getServiceMachineId } from 'vs/platform/externalServices/common/service
1010
import { IFileService } from 'vs/platform/files/common/files';
1111
import { IProductService } from 'vs/platform/product/common/productService';
1212
import { IStorageService } from 'vs/platform/storage/common/storage';
13-
import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
13+
import { ITelemetryService, TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
1414
import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
1515

16-
export async function resolveMarketplaceHeaders(version: string, productService: IProductService, environmentService: IEnvironmentService, configurationService: IConfigurationService, fileService: IFileService, storageService: IStorageService | undefined): Promise<IHeaders> {
16+
export async function resolveMarketplaceHeaders(version: string,
17+
productService: IProductService,
18+
environmentService: IEnvironmentService,
19+
configurationService: IConfigurationService,
20+
fileService: IFileService,
21+
storageService: IStorageService | undefined,
22+
telemetryService: ITelemetryService): Promise<IHeaders> {
1723
const headers: IHeaders = {
1824
'X-Market-Client-Id': `VSCode ${version}`,
1925
'User-Agent': `VSCode ${version} (${productService.nameShort})`
2026
};
2127
const uuid = await getServiceMachineId(environmentService, fileService, storageService);
28+
const { sessionId } = await telemetryService.getTelemetryInfo();
29+
2230
if (supportsTelemetry(productService, environmentService) && getTelemetryLevel(configurationService) === TelemetryLevel.USAGE) {
2331
headers['X-Market-User-Id'] = uuid;
32+
headers['VSCode-SessionId'] = sessionId;
2433
}
2534
return headers;
2635
}

src/vs/platform/windows/electron-main/window.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,14 @@ export class CodeWindow extends Disposable implements ICodeWindow {
542542
private marketplaceHeadersPromise: Promise<object> | undefined;
543543
private getMarketplaceHeaders(): Promise<object> {
544544
if (!this.marketplaceHeadersPromise) {
545-
this.marketplaceHeadersPromise = resolveMarketplaceHeaders(this.productService.version, this.productService, this.environmentMainService, this.configurationService, this.fileService, this.applicationStorageMainService);
545+
this.marketplaceHeadersPromise = resolveMarketplaceHeaders(
546+
this.productService.version,
547+
this.productService,
548+
this.environmentMainService,
549+
this.configurationService,
550+
this.fileService,
551+
this.applicationStorageMainService,
552+
this.telemetryService);
546553
}
547554

548555
return this.marketplaceHeadersPromise;

0 commit comments

Comments
 (0)