Skip to content

Commit dbbbf24

Browse files
authored
Merge pull request #20000 from mozilla/PAY-3472
feat(shared-metrics): Set up Glean frontend metrics for Churn intervention
2 parents 5dcc11e + 71caeba commit dbbbf24

25 files changed

Lines changed: 1020 additions & 14 deletions

.circleci/config.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,34 @@ commands:
299299
name: Wait for Customs
300300
command: yarn workspace fxa-customs-server start
301301

302+
ensure-glean-venv:
303+
steps:
304+
- run:
305+
name: Ensure Python venv has pip and glean_parser
306+
command: |
307+
set -euxo pipefail
308+
309+
unset PYTHONDONTWRITEBYTECODE
310+
export PIP_NO_COMPILE=1
311+
312+
python3 --version
313+
rm -rf .venv
314+
python3 -m venv .venv --without-pip
315+
. .venv/bin/activate
316+
317+
curl -sSL https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
318+
python /tmp/get-pip.py --no-compile
319+
320+
python -m pip install --no-compile --upgrade 'glean_parser~=14.5'
321+
python -m pip --version
322+
302323
lint:
303324
parameters:
304325
nx_run:
305326
type: string
306327
default: run-many
307328
steps:
329+
- ensure-glean-venv
308330
- run:
309331
name: Linting
310332
command: npx nx << parameters.nx_run >> --parallel=1 -t lint
@@ -315,6 +337,7 @@ commands:
315337
type: string
316338
default: run-many
317339
steps:
340+
- ensure-glean-venv
318341
- run:
319342
name: Pre building shared libraries
320343
command: NODE_OPTIONS="--max-old-space-size=7168" npx nx run-many -t build --projects=tag:scope:shared:lib --parallel=2 --verbose
@@ -428,6 +451,7 @@ commands:
428451
type: string
429452
default: run-many
430453
steps:
454+
- ensure-glean-venv
431455
- run:
432456
name: Build
433457
command: NODE_OPTIONS="--max-old-space-size=7168" npx nx << parameters.nx_run >> -t build --parallel=2 --all --verbose
@@ -712,6 +736,7 @@ jobs:
712736
- git-checkout
713737
- restore-workspace
714738
- gcp-cli/setup
739+
- ensure-glean-venv
715740
- run:
716741
name: Build shared libs
717742
command: NODE_OPTIONS="--max-old-space-size=7168" npx nx run-many -t build --projects=tag:scope:shared:lib --parallel=2

apps/payments/api/.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ GLEAN_CONFIG__APPLICATION_ID=
5757
GLEAN_CONFIG__VERSION=0.0.0
5858
GLEAN_CONFIG__CHANNEL='development'
5959
GLEAN_CONFIG__LOGGER_APP_NAME='fxa-payments-next'
60+
61+
# Glean Client Config
62+
GLEAN_CLIENT_CONFIG__ENABLED=true
63+
GLEAN_CLIENT_CONFIG__APPLICATION_ID=
64+
GLEAN_CLIENT_CONFIG__VERSION=0.0.0
65+
GLEAN_CLIENT_CONFIG__CHANNEL='development'

apps/payments/next/.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ GLEAN_CONFIG__APPLICATION_ID=
110110
GLEAN_CONFIG__CHANNEL='development'
111111
GLEAN_CONFIG__LOGGER_APP_NAME='fxa-payments-next'
112112

113+
# Glean Client Config
114+
GLEAN_CLIENT_CONFIG__ENABLED=true
115+
GLEAN_CLIENT_CONFIG__APPLICATION_ID=
116+
# GLEAN_CLIENT_CONFIG__VERSION= # Set in next.config.js
117+
GLEAN_CLIENT_CONFIG__CHANNEL='development'
118+
113119
# CSP Config
114120
CSP__ACCOUNTS_STATIC_CDN=https://cdn.accounts.firefox.com
115121
CSP__PAYPAL_API='https://www.sandbox.paypal.com'

apps/payments/next/app/[locale]/layout.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export default async function RootProviderLayout({
2626
config={{
2727
stripePublicApiKey: config.stripePublicApiKey,
2828
paypalClientId: config.paypal.clientId,
29+
glean: {
30+
enabled: config.gleanClientConfig.enabled,
31+
applicationId: config.gleanClientConfig.applicationId,
32+
version: config.gleanClientConfig.version,
33+
channel: config.gleanClientConfig.channel,
34+
},
2935
sentry: {
3036
...config.sentry, //spread to make sure its a POJO
3137
},

apps/payments/next/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const {
4444
name: profile.displayName,
4545
email: profile.email,
4646
image: profile.avatar,
47+
metricsEnabled: profile.metricsEnabled ?? true,
4748
};
4849
},
4950
userinfo: {
@@ -71,6 +72,7 @@ export const {
7172
name: profile.displayName,
7273
email: profile.email,
7374
image: profile.avatar,
75+
metricsEnabled: profile.metricsEnabled ?? true,
7476
};
7577
}
7678
return {

apps/payments/next/config/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
validate,
2020
} from '@fxa/payments/ui/server';
2121
import { SP2MapConfig, SP2RedirectConfig } from '@fxa/payments/legacy';
22+
import { PaymentsGleanClientConfig } from '@fxa/payments/metrics';
2223

2324
class CspConfig {
2425
@IsUrl()
@@ -140,6 +141,11 @@ export class PaymentsNextConfig extends NestAppRootConfig {
140141
@IsBoolean()
141142
featureFlagSubManage!: boolean;
142143

144+
@Type(() => PaymentsGleanClientConfig)
145+
@ValidateNested()
146+
@IsDefined()
147+
gleanClientConfig!: PaymentsGleanClientConfig;
148+
143149
/**
144150
* Nextjs Public Environment Variables
145151
*/
@@ -159,6 +165,7 @@ export const config = validate(
159165
{
160166
...process.env,
161167
GLEAN_CONFIG__VERSION: process.env['GLEAN_CONFIG__VERSION'],
168+
GLEAN_CLIENT_CONFIG__VERSION: process.env['GLEAN_CLIENT_CONFIG__VERSION'],
162169
},
163170
PaymentsNextConfig
164171
);

apps/payments/next/next.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const nextConfig = {
2121
env: {
2222
version,
2323
GLEAN_CONFIG__VERSION: version,
24+
GLEAN_CLIENT_CONFIG__VERSION: version,
2425
},
2526
distDir: 'build',
2627
experimental: {
@@ -96,11 +97,11 @@ const nextConfig = {
9697
headers: [
9798
{
9899
key: 'Strict-Transport-Security',
99-
value: 'max-age=63072000; includeSubDomains; preload'
100-
}
100+
value: 'max-age=63072000; includeSubDomains; preload',
101+
},
101102
],
102103
},
103-
]
104+
];
104105
},
105106
};
106107

apps/payments/next/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"projectType": "application",
66
"targets": {
77
"build": {
8-
"dependsOn": ["l10n-bundle", "glean-generate"]
8+
"dependsOn": ["l10n-bundle", "glean-generate", "payments-metrics:glean-generate-frontend"]
99
},
1010
"dev": {
1111
"options": {
@@ -39,7 +39,7 @@
3939
},
4040
"start": {
4141
"command": "pm2 start apps/payments/next/pm2.config.js && yarn check:url localhost:3035/__heartbeat__",
42-
"dependsOn": ["l10n-bundle", "glean-generate"]
42+
"dependsOn": ["l10n-bundle", "glean-generate", "payments-metrics:glean-generate-frontend"]
4343
},
4444
"stop": {
4545
"command": "pm2 stop apps/payments/next/pm2.config.js"

libs/payments/metrics/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const config: Config = {
2828
},
2929
moduleFileExtensions: ['ts', 'js', 'html'],
3030
coverageDirectory: '../../../coverage/libs/payments/metrics',
31+
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.ts'],
3132
reporters: [
3233
'default',
3334
[

libs/payments/metrics/project.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"assets": ["libs/payments/metrics/*.md"],
1616
"declaration": true
1717
},
18-
"dependsOn": ["glean-generate"]
18+
"dependsOn": ["glean-generate", "glean-generate-frontend"]
1919
},
2020
"compile": {
2121
"command": "tsc -p libs/payments/metrics/tsconfig.json --noEmit",
22-
"dependsOn": ["glean-generate"]
22+
"dependsOn": ["glean-generate", "glean-generate-frontend"]
2323
},
2424
"glean-generate": {
2525
"dependsOn": ["glean-lint"],
@@ -28,6 +28,13 @@
2828
"glean-lint": {
2929
"command": "yarn glean glinter libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml"
3030
},
31+
"glean-generate-frontend": {
32+
"dependsOn": ["glean-lint-frontend"],
33+
"command": "yarn glean translate libs/shared/metrics/glean/src/registry/subplat-frontend-metrics.yaml -f typescript -o libs/payments/metrics/src/lib/glean/__generated__"
34+
},
35+
"glean-lint-frontend": {
36+
"command": "yarn glean glinter libs/shared/metrics/glean/src/registry/subplat-frontend-metrics.yaml"
37+
},
3138
"test-unit": {
3239
"executor": "@nx/jest:jest",
3340
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],

0 commit comments

Comments
 (0)