Skip to content

Commit d9ccb7e

Browse files
committed
assign 'VSCode-SessionId' header in marketplace.ts
1 parent 68ec3ef commit d9ccb7e

File tree

4 files changed

+83
-9
lines changed

4 files changed

+83
-9
lines changed

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

Lines changed: 8 additions & 3 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 {
@@ -923,14 +930,12 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
923930

924931
const commonHeaders = await this.commonHeadersPromise;
925932
const data = JSON.stringify(query.raw);
926-
const { sessionId } = await this.telemetryService.getTelemetryInfo();
927933
const headers = {
928934
...commonHeaders,
929935
'Content-Type': 'application/json',
930936
'Accept': 'application/json;api-version=3.0-preview.1',
931937
'Accept-Encoding': 'gzip',
932938
'Content-Length': String(data.length),
933-
'VSCode-SessionId': sessionId
934939
};
935940

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

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import product from 'vs/platform/product/common/product';
2121
import { IProductService } from 'vs/platform/product/common/productService';
2222
import { resolveMarketplaceHeaders } from 'vs/platform/externalServices/common/marketplace';
2323
import { InMemoryStorageService, IStorageService } from 'vs/platform/storage/common/storage';
24-
import { TelemetryConfiguration, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
24+
import { ITelemetryInfo, ITelemetryService, TelemetryConfiguration, TelemetryLevel, TELEMETRY_SETTING_ID } from 'vs/platform/telemetry/common/telemetry';
2525
import { TargetPlatform } from 'vs/platform/extensions/common/extensions';
26+
import { ClassifiedEvent, GDPRClassification, StrictPropertyCheck } from 'vs/platform/telemetry/common/gdprTypings';
27+
import { staticObservableValue } from 'vs/base/common/observableValue';
28+
import { Emitter, Event } from 'vs/base/common/event';
2629

2730
class EnvironmentServiceMock extends mock<IEnvironmentService>() {
2831
override readonly serviceMachineIdResource: URI;
@@ -36,6 +39,7 @@ class EnvironmentServiceMock extends mock<IEnvironmentService>() {
3639
suite('Extension Gallery Service', () => {
3740
const disposables: DisposableStore = new DisposableStore();
3841
let fileService: IFileService, environmentService: IEnvironmentService, storageService: IStorageService, productService: IProductService, configurationService: IConfigurationService;
42+
let telemetryService: ITelemetryService;
3943

4044
setup(() => {
4145
const serviceMachineIdResource = joinPath(URI.file('tests').with({ scheme: 'vscode-tests' }), 'machineid');
@@ -47,14 +51,15 @@ suite('Extension Gallery Service', () => {
4751
configurationService = new TestConfigurationService({ [TELEMETRY_SETTING_ID]: TelemetryConfiguration.ON });
4852
configurationService.updateValue(TELEMETRY_SETTING_ID, TelemetryConfiguration.ON);
4953
productService = { _serviceBrand: undefined, ...product, enableTelemetry: true };
54+
telemetryService = new MockTelemetryService();
5055
});
5156

5257
teardown(() => disposables.clear());
5358

5459
test('marketplace machine id', async () => {
55-
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService);
60+
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, telemetryService);
5661
assert.ok(isUUID(headers['X-Market-User-Id']));
57-
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService);
62+
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, telemetryService);
5863
assert.strictEqual(headers['X-Market-User-Id'], headers2['X-Market-User-Id']);
5964
});
6065

@@ -153,3 +158,51 @@ suite('Extension Gallery Service', () => {
153158
return { version, targetPlatform } as IRawGalleryExtensionVersion;
154159
}
155160
});
161+
162+
class MockTelemetryService implements ITelemetryService {
163+
public _serviceBrand: undefined;
164+
public telemetryLevel = staticObservableValue(TelemetryLevel.USAGE);
165+
public sendErrorTelemetry = true;
166+
167+
public events: any[] = [];
168+
169+
private readonly emitter = new Emitter<any>();
170+
171+
public get eventLogged(): Event<any> {
172+
return this.emitter.event;
173+
}
174+
175+
public setEnabled(value: boolean): void {
176+
}
177+
178+
public setExperimentProperty(name: string, value: string): void {
179+
}
180+
181+
public publicLog(eventName: string, data?: any): Promise<void> {
182+
const event = { name: eventName, data: data };
183+
this.events.push(event);
184+
this.emitter.fire(event);
185+
return Promise.resolve();
186+
}
187+
188+
public publicLog2<E extends ClassifiedEvent<T> = never, T extends GDPRClassification<T> = never>(eventName: string, data?: StrictPropertyCheck<T, E>) {
189+
return this.publicLog(eventName, data as any);
190+
}
191+
192+
public publicLogError(eventName: string, data?: any): Promise<void> {
193+
return this.publicLog(eventName, data);
194+
}
195+
196+
public publicLogError2<E extends ClassifiedEvent<T> = never, T extends GDPRClassification<T> = never>(eventName: string, data?: StrictPropertyCheck<T, E>) {
197+
return this.publicLogError(eventName, data as any);
198+
}
199+
200+
public getTelemetryInfo(): Promise<ITelemetryInfo> {
201+
return Promise.resolve({
202+
instanceId: 'someValue.instanceId',
203+
sessionId: 'someValue.sessionId',
204+
machineId: 'someValue.machineId',
205+
firstSessionDate: 'someValue.firstSessionDate'
206+
});
207+
}
208+
}

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)