зеркало из https://github.com/mozilla/fxa.git
feat(payments-metrics): add glean enabled env var
Because: - Need to be able to enable or disable glean recording of events. This commit: - Adds enabled value to payments metrics glean config - Updates payments metrics glean manager to respect enabled config value Closes #FXA-10564
This commit is contained in:
Родитель
ffd4e0d55a
Коммит
914440bd7e
|
@ -37,7 +37,7 @@ STRIPE_CONFIG__TAX_IDS={}
|
||||||
STRIPE_PUBLIC_API_KEY=pk_test_VNpCidC0a2TJJB3wqXq7drhN00sF8r9mhs
|
STRIPE_PUBLIC_API_KEY=pk_test_VNpCidC0a2TJJB3wqXq7drhN00sF8r9mhs
|
||||||
|
|
||||||
# PayPal Config
|
# PayPal Config
|
||||||
PAYPAL_CLIENT_CONFIG__SANDBOX=false
|
PAYPAL_CLIENT_CONFIG__SANDBOX=true
|
||||||
PAYPAL_CLIENT_CONFIG__USER=ASDF
|
PAYPAL_CLIENT_CONFIG__USER=ASDF
|
||||||
PAYPAL_CLIENT_CONFIG__PWD=ASDF
|
PAYPAL_CLIENT_CONFIG__PWD=ASDF
|
||||||
PAYPAL_CLIENT_CONFIG__SIGNATURE=ASDF
|
PAYPAL_CLIENT_CONFIG__SIGNATURE=ASDF
|
||||||
|
@ -80,6 +80,7 @@ STATS_D_CONFIG__PORT=
|
||||||
STATS_D_CONFIG__PREFIX=
|
STATS_D_CONFIG__PREFIX=
|
||||||
|
|
||||||
# Glean Config
|
# Glean Config
|
||||||
|
GLEAN_CONFIG__ENABLED=true
|
||||||
GLEAN_CONFIG__APPLICATION_ID=
|
GLEAN_CONFIG__APPLICATION_ID=
|
||||||
# GLEAN_CONFIG__VERSION= # Set in next.config.js
|
# GLEAN_CONFIG__VERSION= # Set in next.config.js
|
||||||
GLEAN_CONFIG__CHANNEL='development'
|
GLEAN_CONFIG__CHANNEL='development'
|
||||||
|
|
|
@ -33,7 +33,7 @@ STRIPE_CONFIG__TAX_IDS={}
|
||||||
STRIPE_PUBLIC_API_KEY=
|
STRIPE_PUBLIC_API_KEY=
|
||||||
|
|
||||||
# PayPal Config
|
# PayPal Config
|
||||||
PAYPAL_CLIENT_CONFIG__SANDBOX=false
|
PAYPAL_CLIENT_CONFIG__SANDBOX=
|
||||||
PAYPAL_CLIENT_CONFIG__USER=ASDF
|
PAYPAL_CLIENT_CONFIG__USER=ASDF
|
||||||
PAYPAL_CLIENT_CONFIG__PWD=ASDF
|
PAYPAL_CLIENT_CONFIG__PWD=ASDF
|
||||||
PAYPAL_CLIENT_CONFIG__SIGNATURE=ASDF
|
PAYPAL_CLIENT_CONFIG__SIGNATURE=ASDF
|
||||||
|
@ -76,6 +76,7 @@ STATS_D_CONFIG__PORT=
|
||||||
STATS_D_CONFIG__PREFIX=
|
STATS_D_CONFIG__PREFIX=
|
||||||
|
|
||||||
# Glean Config
|
# Glean Config
|
||||||
|
GLEAN_CONFIG__ENABLED=
|
||||||
GLEAN_CONFIG__APPLICATION_ID=
|
GLEAN_CONFIG__APPLICATION_ID=
|
||||||
# GLEAN_CONFIG__VERSION= # Set in next.config.js
|
# GLEAN_CONFIG__VERSION= # Set in next.config.js
|
||||||
GLEAN_CONFIG__CHANNEL='production'
|
GLEAN_CONFIG__CHANNEL='production'
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
import { IsEnum, IsString } from 'class-validator';
|
import { faker } from '@faker-js/faker';
|
||||||
|
import { Provider } from '@nestjs/common';
|
||||||
|
import { IsBoolean, IsEnum, IsString } from 'class-validator';
|
||||||
|
|
||||||
enum GleanChannel {
|
enum GleanChannel {
|
||||||
Development = 'development',
|
Development = 'development',
|
||||||
|
@ -10,6 +12,9 @@ enum GleanChannel {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PaymentsGleanConfig {
|
export class PaymentsGleanConfig {
|
||||||
|
@IsBoolean()
|
||||||
|
enabled!: boolean;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
applicationId!: string;
|
applicationId!: string;
|
||||||
|
|
||||||
|
@ -22,3 +27,16 @@ export class PaymentsGleanConfig {
|
||||||
@IsString()
|
@IsString()
|
||||||
loggerAppName!: string;
|
loggerAppName!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MockPaymentsGleanConfig = {
|
||||||
|
enabled: true,
|
||||||
|
applicationId: faker.string.uuid(),
|
||||||
|
version: '0.0.1',
|
||||||
|
channel: GleanChannel.Development,
|
||||||
|
loggerAppName: 'payments-next-test',
|
||||||
|
} satisfies PaymentsGleanConfig;
|
||||||
|
|
||||||
|
export const MockPaymentsGleanConfigProvider = {
|
||||||
|
provide: PaymentsGleanConfig,
|
||||||
|
useValue: MockPaymentsGleanConfig,
|
||||||
|
} satisfies Provider<PaymentsGleanConfig>;
|
||||||
|
|
|
@ -10,6 +10,10 @@ import {
|
||||||
} from './glean.factory';
|
} from './glean.factory';
|
||||||
import { PaymentsGleanProvider } from './glean.types';
|
import { PaymentsGleanProvider } from './glean.types';
|
||||||
import { MockPaymentsGleanFactory } from './glean.test-provider';
|
import { MockPaymentsGleanFactory } from './glean.test-provider';
|
||||||
|
import {
|
||||||
|
MockPaymentsGleanConfigProvider,
|
||||||
|
PaymentsGleanConfig,
|
||||||
|
} from './glean.config';
|
||||||
|
|
||||||
const mockCommonMetricsData = {
|
const mockCommonMetricsData = {
|
||||||
commonMetricsData: CommonMetricsFactory(),
|
commonMetricsData: CommonMetricsFactory(),
|
||||||
|
@ -26,7 +30,11 @@ describe('PaymentsGleanManager', () => {
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const moduleRef = await Test.createTestingModule({
|
const moduleRef = await Test.createTestingModule({
|
||||||
providers: [MockPaymentsGleanFactory, PaymentsGleanManager],
|
providers: [
|
||||||
|
MockPaymentsGleanFactory,
|
||||||
|
PaymentsGleanManager,
|
||||||
|
MockPaymentsGleanConfigProvider,
|
||||||
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
paymentsGleanManager = moduleRef.get(PaymentsGleanManager);
|
paymentsGleanManager = moduleRef.get(PaymentsGleanManager);
|
||||||
|
@ -156,4 +164,70 @@ describe('PaymentsGleanManager', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('enabled is false', () => {
|
||||||
|
{
|
||||||
|
let paymentsGleanManager: PaymentsGleanManager;
|
||||||
|
let paymentsGleanServerEventsLogger: any;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const moduleRef = await Test.createTestingModule({
|
||||||
|
providers: [
|
||||||
|
MockPaymentsGleanFactory,
|
||||||
|
PaymentsGleanManager,
|
||||||
|
MockPaymentsGleanConfigProvider,
|
||||||
|
{
|
||||||
|
provide: PaymentsGleanConfig,
|
||||||
|
useValue: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
paymentsGleanManager = moduleRef.get(PaymentsGleanManager);
|
||||||
|
paymentsGleanServerEventsLogger = moduleRef.get(PaymentsGleanProvider);
|
||||||
|
jest.spyOn(paymentsGleanServerEventsLogger, 'recordPaySetupView');
|
||||||
|
jest.spyOn(paymentsGleanServerEventsLogger, 'recordPaySetupEngage');
|
||||||
|
jest.spyOn(paymentsGleanServerEventsLogger, 'recordPaySetupSubmit');
|
||||||
|
jest.spyOn(paymentsGleanServerEventsLogger, 'recordPaySetupSuccess');
|
||||||
|
jest.spyOn(paymentsGleanServerEventsLogger, 'recordPaySetupFail');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recordFxaPaySetupView', () => {
|
||||||
|
paymentsGleanManager.recordFxaPaySetupView(mockCommonMetricsData);
|
||||||
|
expect(
|
||||||
|
paymentsGleanServerEventsLogger.recordPaySetupView
|
||||||
|
).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recordFxaPaySetupEngage', () => {
|
||||||
|
paymentsGleanManager.recordFxaPaySetupEngage(mockCommonMetricsData);
|
||||||
|
expect(
|
||||||
|
paymentsGleanServerEventsLogger.recordPaySetupEngage
|
||||||
|
).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recordFxaPaySetupSubmit', () => {
|
||||||
|
paymentsGleanManager.recordFxaPaySetupSubmit(mockCommonMetricsData);
|
||||||
|
expect(
|
||||||
|
paymentsGleanServerEventsLogger.recordPaySetupSubmit
|
||||||
|
).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recordFxaPaySetupSuccess', () => {
|
||||||
|
paymentsGleanManager.recordFxaPaySetupSuccess(mockCommonMetricsData);
|
||||||
|
expect(
|
||||||
|
paymentsGleanServerEventsLogger.recordPaySetupSuccess
|
||||||
|
).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recordFxaPaySetupFail', () => {
|
||||||
|
paymentsGleanManager.recordFxaPaySetupFail(mockCommonMetricsData);
|
||||||
|
expect(
|
||||||
|
paymentsGleanServerEventsLogger.recordPaySetupFail
|
||||||
|
).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,10 +15,12 @@ import { mapUtm } from './utils/mapUtm';
|
||||||
import { mapSubscription } from './utils/mapSubscription';
|
import { mapSubscription } from './utils/mapSubscription';
|
||||||
import { mapRelyingParty } from './utils/mapRelyingParty';
|
import { mapRelyingParty } from './utils/mapRelyingParty';
|
||||||
import { normalizeGleanFalsyValues } from './utils/normalizeGleanFalsyValues';
|
import { normalizeGleanFalsyValues } from './utils/normalizeGleanFalsyValues';
|
||||||
|
import { PaymentsGleanConfig } from './glean.config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PaymentsGleanManager {
|
export class PaymentsGleanManager {
|
||||||
constructor(
|
constructor(
|
||||||
|
private paymentsGleanConfig: PaymentsGleanConfig,
|
||||||
@Inject(PaymentsGleanProvider)
|
@Inject(PaymentsGleanProvider)
|
||||||
private paymentsGleanServerEventsLogger: PaymentsGleanServerEventsLogger
|
private paymentsGleanServerEventsLogger: PaymentsGleanServerEventsLogger
|
||||||
) {}
|
) {}
|
||||||
|
@ -28,9 +30,11 @@ export class PaymentsGleanManager {
|
||||||
cartMetricsData: CartMetrics;
|
cartMetricsData: CartMetrics;
|
||||||
cmsMetricsData: CmsMetricsData;
|
cmsMetricsData: CmsMetricsData;
|
||||||
}) {
|
}) {
|
||||||
this.paymentsGleanServerEventsLogger.recordPaySetupView(
|
if (this.paymentsGleanConfig.enabled) {
|
||||||
this.populateCommonMetrics(metrics)
|
this.paymentsGleanServerEventsLogger.recordPaySetupView(
|
||||||
);
|
this.populateCommonMetrics(metrics)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recordFxaPaySetupEngage(metrics: {
|
recordFxaPaySetupEngage(metrics: {
|
||||||
|
@ -38,9 +42,11 @@ export class PaymentsGleanManager {
|
||||||
cartMetricsData: CartMetrics;
|
cartMetricsData: CartMetrics;
|
||||||
cmsMetricsData: CmsMetricsData;
|
cmsMetricsData: CmsMetricsData;
|
||||||
}) {
|
}) {
|
||||||
this.paymentsGleanServerEventsLogger.recordPaySetupEngage(
|
if (this.paymentsGleanConfig.enabled) {
|
||||||
this.populateCommonMetrics(metrics)
|
this.paymentsGleanServerEventsLogger.recordPaySetupEngage(
|
||||||
);
|
this.populateCommonMetrics(metrics)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recordFxaPaySetupSubmit(
|
recordFxaPaySetupSubmit(
|
||||||
|
@ -51,10 +57,13 @@ export class PaymentsGleanManager {
|
||||||
},
|
},
|
||||||
paymentProvider?: PaymentProvidersType
|
paymentProvider?: PaymentProvidersType
|
||||||
) {
|
) {
|
||||||
this.paymentsGleanServerEventsLogger.recordPaySetupSubmit({
|
if (this.paymentsGleanConfig.enabled) {
|
||||||
...this.populateCommonMetrics(metrics),
|
this.paymentsGleanServerEventsLogger.recordPaySetupSubmit({
|
||||||
subscription_payment_provider: normalizeGleanFalsyValues(paymentProvider),
|
...this.populateCommonMetrics(metrics),
|
||||||
});
|
subscription_payment_provider:
|
||||||
|
normalizeGleanFalsyValues(paymentProvider),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recordFxaPaySetupSuccess(
|
recordFxaPaySetupSuccess(
|
||||||
|
@ -67,10 +76,13 @@ export class PaymentsGleanManager {
|
||||||
) {
|
) {
|
||||||
const commonMetrics = this.populateCommonMetrics(metrics);
|
const commonMetrics = this.populateCommonMetrics(metrics);
|
||||||
|
|
||||||
this.paymentsGleanServerEventsLogger.recordPaySetupSuccess({
|
if (this.paymentsGleanConfig.enabled) {
|
||||||
...commonMetrics,
|
this.paymentsGleanServerEventsLogger.recordPaySetupSuccess({
|
||||||
subscription_payment_provider: normalizeGleanFalsyValues(paymentProvider),
|
...commonMetrics,
|
||||||
});
|
subscription_payment_provider:
|
||||||
|
normalizeGleanFalsyValues(paymentProvider),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recordFxaPaySetupFail(
|
recordFxaPaySetupFail(
|
||||||
|
@ -83,10 +95,13 @@ export class PaymentsGleanManager {
|
||||||
) {
|
) {
|
||||||
const commonMetrics = this.populateCommonMetrics(metrics);
|
const commonMetrics = this.populateCommonMetrics(metrics);
|
||||||
|
|
||||||
this.paymentsGleanServerEventsLogger.recordPaySetupFail({
|
if (this.paymentsGleanConfig.enabled) {
|
||||||
...commonMetrics,
|
this.paymentsGleanServerEventsLogger.recordPaySetupFail({
|
||||||
subscription_payment_provider: normalizeGleanFalsyValues(paymentProvider),
|
...commonMetrics,
|
||||||
});
|
subscription_payment_provider:
|
||||||
|
normalizeGleanFalsyValues(paymentProvider),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private populateCommonMetrics(metrics: {
|
private populateCommonMetrics(metrics: {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { MockFirestoreProvider } from '@fxa/shared/db/firestore';
|
||||||
import {
|
import {
|
||||||
CheckoutParamsFactory,
|
CheckoutParamsFactory,
|
||||||
CommonMetricsFactory,
|
CommonMetricsFactory,
|
||||||
|
MockPaymentsGleanConfigProvider,
|
||||||
MockPaymentsGleanFactory,
|
MockPaymentsGleanFactory,
|
||||||
PaymentProvidersType,
|
PaymentProvidersType,
|
||||||
PaymentsGleanManager,
|
PaymentsGleanManager,
|
||||||
|
@ -48,6 +49,7 @@ describe('PaymentsEmitterService', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const moduleRef = await Test.createTestingModule({
|
const moduleRef = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
|
MockPaymentsGleanConfigProvider,
|
||||||
MockAccountDatabaseNestFactory,
|
MockAccountDatabaseNestFactory,
|
||||||
MockPaymentsGleanFactory,
|
MockPaymentsGleanFactory,
|
||||||
MockStrapiClientConfigProvider,
|
MockStrapiClientConfigProvider,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче