Skip to content

Commit 11d1ff7

Browse files
Craete all eqatec analytics monitors in the broker process
Eqatec Analytics monitors can be created in the broker process directly instead of starting multiple child processes. So delete some unneeded files and move tracking of `AcceptUsageReporting` out of CLI process.
1 parent c473722 commit 11d1ff7

7 files changed

+73
-305
lines changed

lib/services/analytics/analytics-broker.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export class AnalyticsBroker implements IAnalyticsBroker {
2020
for (const provider of this.analyticsProviders) {
2121
switch (trackInfo.type) {
2222
case TrackingTypes.Exception:
23-
await provider.trackException(<IExceptionsTrackingInformation>trackInfo);
23+
await provider.trackError(<IExceptionsTrackingInformation>trackInfo);
2424
break;
2525
case TrackingTypes.Feature:
26-
await provider.trackFeature(<IFeatureTrackingInformation>trackInfo);
26+
await provider.trackInformation(<IFeatureTrackingInformation>trackInfo);
27+
break;
28+
case TrackingTypes.AcceptTrackFeatureUsage:
29+
await provider.acceptFeatureUsageTracking(<IAcceptUsageReportingInformation>trackInfo);
2730
break;
2831
case TrackingTypes.Finish:
2932
await provider.finishTracking();

lib/services/analytics/analytics-service.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import { cache } from "../../common/decorators";
55

66
export class AnalyticsService extends AnalyticsServiceBase implements IAnalyticsService {
7-
private static ANALYTICS_FEATURE_USAGE_TRACKING_API_KEY = "9912cff308334c6d9ad9c33f76a983e3";
87
private static ANALYTICS_BROKER_START_TIMEOUT = 30 * 1000;
98

109
constructor(protected $logger: ILogger,
@@ -13,11 +12,10 @@ export class AnalyticsService extends AnalyticsServiceBase implements IAnalytics
1312
$prompter: IPrompter,
1413
$userSettingsService: UserSettings.IUserSettingsService,
1514
$analyticsSettingsService: IAnalyticsSettingsService,
16-
$progressIndicator: IProgressIndicator,
1715
$osInfo: IOsInfo,
1816
private $childProcess: IChildProcess,
1917
private $processService: IProcessService) {
20-
super($logger, $options, $staticConfig, $prompter, $userSettingsService, $analyticsSettingsService, $progressIndicator, $osInfo);
18+
super($logger, $options, $staticConfig, $prompter, $userSettingsService, $analyticsSettingsService, $osInfo);
2119
}
2220

2321
public track(featureName: string, featureValue: string): Promise<void> {
@@ -28,12 +26,12 @@ export class AnalyticsService extends AnalyticsServiceBase implements IAnalytics
2826
return this.sendExceptionForTracking(exception, message);
2927
}
3028

31-
protected async checkConsentCore(trackFeatureUsage: boolean): Promise<void> {
32-
await this.restartEqatecMonitor(AnalyticsService.ANALYTICS_FEATURE_USAGE_TRACKING_API_KEY);
33-
await super.checkConsentCore(trackFeatureUsage);
29+
public async trackAcceptFeatureUsage(settings: { acceptTrackFeatureUsage: boolean }): Promise<void> {
3430

35-
// Stop the monitor, so correct API_KEY will be used when features are tracked.
36-
this.tryStopEqatecMonitor();
31+
this.sendMessageToBroker(<IAcceptUsageReportingInformation> {
32+
type: TrackingTypes.AcceptTrackFeatureUsage,
33+
acceptTrackFeatureUsage: settings.acceptTrackFeatureUsage
34+
});
3735
}
3836

3937
@cache()
@@ -93,7 +91,7 @@ export class AnalyticsService extends AnalyticsServiceBase implements IAnalytics
9391

9492
if (this.analyticsStatuses[this.$staticConfig.TRACK_FEATURE_USAGE_SETTING_NAME] === AnalyticsStatus.enabled) {
9593
return this.sendMessageToBroker(
96-
{
94+
<IFeatureTrackingInformation> {
9795
type: TrackingTypes.Feature,
9896
featureName: featureName,
9997
featureValue: featureValue
@@ -107,7 +105,7 @@ export class AnalyticsService extends AnalyticsServiceBase implements IAnalytics
107105

108106
if (this.analyticsStatuses[this.$staticConfig.ERROR_REPORT_SETTING_NAME] === AnalyticsStatus.enabled) {
109107
return this.sendMessageToBroker(
110-
{
108+
<IExceptionsTrackingInformation> {
111109
type: TrackingTypes.Exception,
112110
exception,
113111
message
@@ -116,7 +114,7 @@ export class AnalyticsService extends AnalyticsServiceBase implements IAnalytics
116114
}
117115
}
118116

119-
private async sendMessageToBroker(message: any): Promise<void> {
117+
private async sendMessageToBroker(message: ITrackingInformation): Promise<void> {
120118
const broker = await this.getAnalyticsBroker();
121119
return new Promise<void>((resolve, reject) => broker.send(message, resolve));
122120
}

lib/services/analytics/analytics.d.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Describes if the user allows to be tracked.
3+
*/
4+
interface IAcceptUsageReportingInformation extends ITrackingInformation {
5+
/**
6+
* The answer of the question if user allows us to track them.
7+
*/
8+
acceptTrackFeatureUsage: boolean;
9+
}
10+
111
/**
212
* Describes information used for tracking feature.
313
*/
@@ -49,14 +59,21 @@ interface IAnalyticsProvider {
4959
* @param {IExceptionsTrackingInformation} trackInfo The information for exception that should be tracked.
5060
* @returns {Promise<void>}
5161
*/
52-
trackException(trackInfo: IExceptionsTrackingInformation): Promise<void>;
62+
trackError(trackInfo: IExceptionsTrackingInformation): Promise<void>;
5363

5464
/**
5565
* Sends feature for tracking in the analytics service provider.
5666
* @param {IFeatureTrackingInformation} trackInfo The information for feature that should be tracked.
5767
* @returns {Promise<void>}
5868
*/
59-
trackFeature(trackInfo: IFeatureTrackingInformation): Promise<void>;
69+
trackInformation(trackInfo: IFeatureTrackingInformation): Promise<void>;
70+
71+
/**
72+
* Sends information if user accepts to be tracked.
73+
* @param {IAcceptUsageReportingInformation} trackInfo The information, containing user's answer if they allow to be tracked.
74+
* @returns {Promise<void>}
75+
*/
76+
acceptFeatureUsageTracking(data: IAcceptUsageReportingInformation): Promise<void>;
6077

6178
/**
6279
* Waits for execution of all pending requests and finishes tracking operation

lib/services/analytics/eqatec-analytics-process.ts

-89
This file was deleted.

0 commit comments

Comments
 (0)