Skip to content

Commit f8eec3f

Browse files
dschomclaude
andcommitted
refactor(sentry): Migrate from fxa-shared/sentry to @fxa/sentry-* packages
Migrated all Sentry imports from the legacy fxa-shared/sentry module to the new scoped @fxa/sentry-* packages in libs/shared/: - Browser code: @fxa/shared/sentry/browser - Node.js code: @fxa/sentry-node - Shared utilities: @fxa/sentry-utils Changes: - Added shorter TypeScript path aliases (@fxa/sentry-*) in tsconfig.base.json - Updated 25 files across auth-server, content-server, settings, admin-panel, event-broker, and payments-server - Removed tagCriticalEvent usage (deprecated) - Added tracesSampler support to SentryConfigOpts types - Deleted legacy packages/fxa-shared/sentry/ directory and tests - Removed sentry exports from fxa-shared package.json - Ports fxa-shared/monitoring to libs - Updates references to fxa-shared/monitoring This completes the migration to the modular sentry package structure. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 1f92bad commit f8eec3f

59 files changed

Lines changed: 362 additions & 1839 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

libs/shared/monitoring/.swcrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"jsc": {
3+
"target": "es2017",
4+
"parser": {
5+
"syntax": "typescript",
6+
"decorators": true,
7+
"dynamicImport": true
8+
},
9+
"transform": {
10+
"decoratorMetadata": true,
11+
"legacyDecorator": true
12+
}
13+
}
14+
}

libs/shared/monitoring/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# shared-monitoring
2+
3+
This library provides monitoring functionality including error tracking with Sentry and distributed tracing.
4+
5+
It exports the `initMonitoring` function which initializes both error monitoring (Sentry) and performance monitoring (tracing) for server applications.
6+
7+
## Installation
8+
9+
```bash
10+
npm install @fxa/shared/monitoring
11+
```
12+
13+
## Usage
14+
15+
```typescript
16+
import { initMonitoring } from '@fxa/shared/monitoring';
17+
18+
initMonitoring({
19+
log: logger,
20+
config: {
21+
tracing: {
22+
/* tracing config */
23+
},
24+
sentry: {
25+
/* sentry config */
26+
},
27+
},
28+
});
29+
```
30+
31+
## Exported APIs
32+
33+
- `initMonitoring(opts: MonitoringConfig)` - Initialize monitoring components
34+
- `MonitoringConfig` - Type definition for monitoring configuration
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Config } from 'jest';
2+
/* eslint-disable */
3+
import { readFileSync } from 'fs';
4+
5+
// Reading the SWC compilation config and remove the "exclude"
6+
// for the test files to be compiled by SWC
7+
const { exclude: _, ...swcJestConfig } = JSON.parse(
8+
readFileSync(`${__dirname}/.swcrc`, 'utf-8')
9+
);
10+
11+
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
12+
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
13+
if (swcJestConfig.swcrc === undefined) {
14+
swcJestConfig.swcrc = false;
15+
}
16+
17+
// Uncomment if using global setup/teardown files being transformed via swc
18+
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
19+
// jest needs EsModule Interop to find the default exported setup/teardown functions
20+
// swcJestConfig.module.noInterop = false;
21+
22+
const config: Config = {
23+
displayName: 'shared-monitoring',
24+
preset: '../../../jest.preset.js',
25+
transform: {
26+
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
27+
},
28+
moduleFileExtensions: ['ts', 'js', 'html'],
29+
testEnvironment: 'node',
30+
coverageDirectory: '../../../coverage/libs/shared/monitoring',
31+
reporters: [
32+
'default',
33+
[
34+
'jest-junit',
35+
{
36+
outputDirectory: 'artifacts/tests/shared-monitoring',
37+
outputName: 'shared-monitoring-jest-unit-results.xml',
38+
},
39+
],
40+
],
41+
};
42+
export default config;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@fxa/shared/monitoring",
3+
"version": "0.0.0"
4+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "shared-monitoring",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/shared/monitoring/src",
5+
"projectType": "library",
6+
"tags": ["scope:shared:lib"],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/esbuild:esbuild",
10+
"outputs": ["{options.outputPath}"],
11+
"defaultConfiguration": "production",
12+
"options": {
13+
"main": "libs/shared/monitoring/src/index.ts",
14+
"outputPath": "dist/libs/shared/monitoring",
15+
"outputFileName": "main.js",
16+
"tsConfig": "libs/shared/monitoring/tsconfig.lib.json",
17+
"declaration": true,
18+
"assets": [
19+
{
20+
"glob": "libs/shared/monitoring/README.md",
21+
"input": ".",
22+
"output": "."
23+
}
24+
],
25+
"platform": "node"
26+
},
27+
"configurations": {
28+
"development": {
29+
"minify": false
30+
},
31+
"production": {
32+
"minify": true
33+
}
34+
}
35+
},
36+
"lint": {
37+
"executor": "@nx/eslint:lint",
38+
"outputs": ["{options.outputFile}"],
39+
"options": {
40+
"lintFilePatterns": ["libs/shared/monitoring/**/*.ts"]
41+
}
42+
},
43+
"test-unit": {
44+
"executor": "@nx/jest:jest",
45+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
46+
"options": {
47+
"jestConfig": "libs/shared/monitoring/jest.config.ts"
48+
}
49+
}
50+
}
51+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { initTracing } from '@fxa/shared/otel';
2+
import { initSentry } from '@fxa/sentry-node';
3+
import { initMonitoring } from '@fxa/shared/monitoring';
4+
5+
jest.mock('@fxa/shared/otel', () => ({ initTracing: jest.fn() }));
6+
jest.mock('@fxa/sentry-node', () => ({ initSentry: jest.fn() }));
7+
8+
describe('shared-monitoring', () => {
9+
beforeEach(() => {
10+
jest.resetAllMocks();
11+
jest.resetModules();
12+
});
13+
14+
it('initializes tracing and sentry when config contains them', () => {
15+
const log = {
16+
info: jest.fn(),
17+
warn: jest.fn(),
18+
error: jest.fn(),
19+
debug: jest.fn(),
20+
};
21+
const opts = {
22+
log,
23+
config: {
24+
sentry: { dsn: 'https://example.com' },
25+
tracing: { enabled: true, serviceName: 'test' },
26+
},
27+
};
28+
29+
initMonitoring(opts);
30+
31+
expect(initTracing).toHaveBeenCalledWith(opts.config.tracing, log);
32+
expect(initSentry).toHaveBeenCalledWith(opts.config, log);
33+
});
34+
35+
it('does not call tracing or sentry when not configured', () => {
36+
const log = { warn: jest.fn() };
37+
const opts = { log, config: {} };
38+
39+
initMonitoring(opts);
40+
41+
expect(initTracing).not.toHaveBeenCalled();
42+
expect(initSentry).not.toHaveBeenCalled();
43+
});
44+
45+
it('warns and skips when initialized more than once', () => {
46+
const log = { warn: jest.fn() };
47+
const opts = {
48+
log,
49+
config: {
50+
sentry: { dsn: 'https://example.com' },
51+
tracing: { enabled: true, serviceName: 'test' },
52+
},
53+
};
54+
55+
initMonitoring(opts);
56+
initMonitoring(opts);
57+
58+
expect(log.warn).toHaveBeenCalledWith(
59+
'monitoring',
60+
'Monitoring can only be initialized once'
61+
);
62+
});
63+
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { initTracing } from '../tracing/node-tracing';
6-
import { InitSentryOpts, initSentry } from '../sentry/node';
7-
import { TracingOpts } from '../tracing/config';
8-
import { ILogger } from '../log';
5+
import { initTracing } from '@fxa/shared/otel';
6+
import { InitSentryOpts, initSentry } from '@fxa/sentry-node';
7+
import { TracingOpts } from '@fxa/shared/otel';
8+
import { ILogger } from '@fxa/shared/log';
99

1010
export type MonitoringConfig = {
1111
log?: ILogger;
@@ -14,7 +14,7 @@ export type MonitoringConfig = {
1414

1515
let initialized = false;
1616

17-
// IMPORTANT! This initialization function must be called first thing when a server starts.If it's called after server
17+
// IMPORTANT! This initialization function must be called first thing when a server starts. If it's called after server
1818
// frameworks initialized instrumentation might not work properly.
1919
/**
2020
* Initializes modules related to error monitoring, performance monitoring, and tracing.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "commonjs"
5+
},
6+
"files": [],
7+
"include": [],
8+
"references": [
9+
{
10+
"path": "./tsconfig.lib.json"
11+
},
12+
{
13+
"path": "./tsconfig.spec.json"
14+
}
15+
]
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "../../../dist/out-tsc",
6+
"declaration": true,
7+
"types": ["node"]
8+
},
9+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
10+
"include": ["src/**/*.ts"]
11+
}

0 commit comments

Comments
 (0)