From 09c03a1ffd7f68287bd7e1eedfea59e7c7df3347 Mon Sep 17 00:00:00 2001 From: Ryan Golden Date: Thu, 11 Jun 2026 16:54:46 -0500 Subject: [PATCH] feat: add segment source specific identify files --- src/common/impl/reporter.ts | 12 ++++++++---- src/node/redHatServiceNodeProvider.ts | 3 ++- src/webworker/redHatServiceWebWorkerProvider.ts | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/common/impl/reporter.ts b/src/common/impl/reporter.ts index 395b59e..4dcab96 100644 --- a/src/common/impl/reporter.ts +++ b/src/common/impl/reporter.ts @@ -11,7 +11,7 @@ import { toErrorMessage } from '../utils/errorMessages'; */ export class Reporter implements IReporter { - constructor(private analytics?: CoreAnalytics, private cacheService?: CacheService) { + constructor(private analytics?: CoreAnalytics, private cacheService?: CacheService, private writeKey?: any) { } public async report(event: AnalyticsEvent): Promise { @@ -25,14 +25,15 @@ export class Reporter implements IReporter { case 'identify': //Avoid identifying the user several times, until some data has changed. const hash = sha1(payloadString); - const cached = await this.cacheService?.get('identify'); + const identifyCacheName = this.getIdentifyCacheName(this.writeKey); + const cached = await this.cacheService?.get(identifyCacheName); if (hash === cached) { Logger.log(`Skipping 'identify' event! Already sent:\n${payloadString}`); return; } Logger.log(`Sending 'identify' event with\n${payloadString}`); await this.analytics?.identify(event); - this.cacheService?.put('identify', hash); + this.cacheService?.put(identifyCacheName, hash); break; case 'track': Logger.log(`Sending 'track' event with\n${payloadString}`); @@ -52,7 +53,6 @@ export class Reporter implements IReporter { } - public async flush(): Promise { if (isFlusheable(this.analytics)){ this.analytics.flush(); @@ -64,6 +64,10 @@ export class Reporter implements IReporter { return this.analytics.closeAndFlush(); } } + + private getIdentifyCacheName(writeKey: string): string { + return `${writeKey}-identify`; + } } interface Flusheable { diff --git a/src/node/redHatServiceNodeProvider.ts b/src/node/redHatServiceNodeProvider.ts index 280c7c3..62c2fa0 100644 --- a/src/node/redHatServiceNodeProvider.ts +++ b/src/node/redHatServiceNodeProvider.ts @@ -8,6 +8,7 @@ import { AbstractRedHatServiceProvider } from '../common/vscode/redhatServiceIni import { IdManagerFactory } from './idManagerFactory'; import { getEnvironment } from './platform'; import { EventCacheService } from '../common/impl/eventCacheService' +import { getSegmentKey } from '../common/utils/keyLocator'; export class RedHatServiceNodeProvider extends AbstractRedHatServiceProvider { @@ -16,7 +17,7 @@ export class RedHatServiceNodeProvider extends AbstractRedHatServiceProvider { const extensionId = extensionInfo.id; const packageJson = getPackageJson(extensionInfo); const storageService = new FileSystemStorageService(this.getCachePath()); - const reporter = new Reporter(this.getSegmentApi(packageJson), new EventCacheService(storageService)); + const reporter = new Reporter(this.getSegmentApi(packageJson), new EventCacheService(storageService), getSegmentKey(packageJson)); const idManager = IdManagerFactory.getIdManager(); const builder = new TelemetryServiceBuilder(packageJson) .setContext(this.context) diff --git a/src/webworker/redHatServiceWebWorkerProvider.ts b/src/webworker/redHatServiceWebWorkerProvider.ts index 2f4a60c..bc87fb6 100644 --- a/src/webworker/redHatServiceWebWorkerProvider.ts +++ b/src/webworker/redHatServiceWebWorkerProvider.ts @@ -8,6 +8,7 @@ import { getEnvironment } from './platform'; import { Reporter } from '../common/impl/reporter'; import { VFSSystemIdProvider } from './vfsIdManager'; import { EventCacheService } from '../common/impl/eventCacheService'; +import { getSegmentKey } from '../common/utils/keyLocator'; export class RedHatServiceWebWorkerProvider extends AbstractRedHatServiceProvider { @@ -16,7 +17,7 @@ export class RedHatServiceWebWorkerProvider extends AbstractRedHatServiceProvide const extensionId = extensionInfo.id; const packageJson = getPackageJson(extensionInfo); const storageService = new FileSystemStorageService(this.getCachePath()); - const reporter = new Reporter(this.getSegmentApi(packageJson), new EventCacheService(storageService)); + const reporter = new Reporter(this.getSegmentApi(packageJson), new EventCacheService(storageService), getSegmentKey(packageJson)); const idManager = new VFSSystemIdProvider(storageService); const builder = new TelemetryServiceBuilder(packageJson) .setContext(this.context)