Skip to content

Commit f4f0bc4

Browse files
authored
Added testing for each instrument.ts file to ensure Sentry doesn't start unless the environment is not 'test' (#230)
1 parent c85e833 commit f4f0bc4

7 files changed

Lines changed: 112 additions & 91 deletions

File tree

‎packages/analytics-service/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

‎packages/api-gateway/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

‎packages/auth-service/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

‎packages/db-service/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

‎packages/email-service/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

‎packages/file-service/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

‎packages/logging-service/src/instrument.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import * as Sentry from '@sentry/nestjs';
22
import { nodeProfilingIntegration } from '@sentry/profiling-node';
33

44
// Ensure to call this before importing any other modules!
5-
Sentry.init({
6-
dsn: process.env.SENTRY_DSN,
7-
integrations: [
8-
// Add our Profiling integration
9-
nodeProfilingIntegration(),
10-
],
5+
// Only initialize Sentry if not in test environment
6+
if (process.env.NODE_ENV !== 'test') {
7+
Sentry.init({
8+
dsn: process.env.SENTRY_DSN,
9+
integrations: [
10+
// Add our Profiling integration
11+
nodeProfilingIntegration(),
12+
],
1113

12-
// Add Tracing by setting tracesSampleRate
13-
// We recommend adjusting this value in production
14-
tracesSampleRate: 1.0,
14+
// Add Tracing by setting tracesSampleRate
15+
// We recommend adjusting this value in production
16+
tracesSampleRate: 1.0,
1517

16-
// Set sampling rate for profiling
17-
// This is relative to tracesSampleRate
18-
profilesSampleRate: 1.0,
19-
});
18+
// Set sampling rate for profiling
19+
// This is relative to tracesSampleRate
20+
profilesSampleRate: 1.0,
21+
});
22+
}

0 commit comments

Comments
 (0)