Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/common/impl/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -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}`);
Expand All @@ -52,7 +53,6 @@ export class Reporter implements IReporter {

}


public async flush(): Promise<void> {
if (isFlusheable(this.analytics)){
this.analytics.flush();
Expand All @@ -64,6 +64,10 @@ export class Reporter implements IReporter {
return this.analytics.closeAndFlush();
}
}

private getIdentifyCacheName(writeKey: string): string {
return `${writeKey}-identify`;
}
}

interface Flusheable {
Expand Down
3 changes: 2 additions & 1 deletion src/node/redHatServiceNodeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/webworker/redHatServiceWebWorkerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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)
Expand Down