Skip to content

Commit 2f6d495

Browse files
committed
Merge branch 'master' of github.com:microting/eform-angular-frontend
2 parents ce251dd + 1badfcb commit 2f6d495

File tree

9 files changed

+111
-61
lines changed

9 files changed

+111
-61
lines changed

.github/workflows/dotnet-core-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- name: Build Docker image
1515
id: build
16-
run: docker build . -t microtingas/frontend-container:latest --build-arg GITVERSION=1.0.0 --build-arg SENTRY_AUTH_TOKEN=${{secrets.SENTRY_AUTH_TOKEN}}
16+
run: docker build . -t microtingas/frontend-container:latest --build-arg GITVERSION=1.0.0 --build-arg SENTRY_AUTH_TOKEN=${{secrets.SENTRY_AUTH_TOKEN}} --build-arg DISABLE_SENTRY=true
1717
shell: bash
1818
- run: docker save microtingas/frontend-container:latest -o container.tar
1919
- uses: actions/upload-artifact@v4

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ FROM node:22-bookworm-slim as node-env
22

33
WORKDIR /app
44
ARG SENTRY_AUTH_TOKEN
5+
ARG DISABLE_SENTRY
56
ENV PATH /app/node_modules/.bin:$PATH
67
COPY eform-client ./
78
RUN apt-get update
89
RUN apt-get -y -q install ca-certificates
910
RUN yarn install
1011
RUN yarn build
11-
RUN if [ -n "$SENTRY_AUTH_TOKEN" ]; then yarn sentrysourcemap; else echo "SENTRY_AUTH_TOKEN is not set"; fi
12+
RUN if [ -n "$SENTRY_AUTH_TOKEN" ] && [ "$DISABLE_SENTRY" != "true" ]; then yarn sentrysourcemap; else echo "Sentry sourcemap upload skipped (DISABLE_SENTRY=$DISABLE_SENTRY)"; fi
1213

1314
FROM mcr.microsoft.com/dotnet/sdk:9.0-noble AS build-env
1415
WORKDIR /app
1516
ARG GITVERSION
17+
ARG DISABLE_SENTRY
1618

1719
# Copy csproj and restore as distinct layers
1820
COPY eFormAPI/eFormAPI.Web ./
@@ -22,6 +24,8 @@ RUN pwd
2224
# Build runtime image
2325
FROM mcr.microsoft.com/dotnet/aspnet:9.0-noble
2426
WORKDIR /app
27+
ARG DISABLE_SENTRY
28+
ENV DISABLE_SENTRY=${DISABLE_SENTRY}
2529
COPY --from=build-env /app/out .
2630
COPY --from=node-env /app/dist/browser wwwroot
2731
RUN rm connection.json; exit 0

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ You need to create an account for Microting API and get your access credentials.
4444

4545
* Call Microting at +45 66 11 10 66 to get started.
4646

47+
## Sentry Configuration
48+
49+
Sentry error tracking is enabled by default in production environments but disabled in development mode to prevent unnecessary test data collection.
50+
51+
### Development Mode
52+
When running locally with `yarn start`, Sentry is automatically disabled via the `environment.ts` configuration file where `enableSentry: false`.
53+
54+
### Production Mode
55+
In production builds, Sentry is enabled through `environment.prod.ts` where `enableSentry: true`.
56+
57+
### Docker Configuration
58+
When building Docker images, you can control Sentry behavior using the `DISABLE_SENTRY` build argument:
59+
60+
```bash
61+
# Disable Sentry for testing/CI environments
62+
docker build --build-arg DISABLE_SENTRY=true -t my-image .
63+
64+
# Enable Sentry for production (default behavior)
65+
docker build -t my-image .
66+
```
67+
68+
The `DISABLE_SENTRY` environment variable can be set to `true` or `1` to disable Sentry in both the Angular frontend and C# backend.
69+
4770
## Testing
4871

4972
### E2E Test Migration

eFormAPI/eFormAPI.Web/Program.cs

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,36 @@ public class Program
7171

7272
public static void Main(string[] args)
7373
{
74-
SentrySdk.Init(options =>
75-
{
76-
// A Sentry Data Source Name (DSN) is required.
77-
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
78-
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
79-
options.Dsn = "https://a20910d51f605d94e956163ffbf9dd5a@o4506241219428352.ingest.sentry.io/4506279162019840";
80-
81-
// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
82-
// This might be helpful, or might interfere with the normal operation of your application.
83-
// We enable it here for demonstration purposes when first trying Sentry.
84-
// You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
85-
options.Debug = false;
86-
87-
// This option is recommended. It enables Sentry's "Release Health" feature.
88-
options.AutoSessionTracking = true;
74+
var disableSentry = Environment.GetEnvironmentVariable("DISABLE_SENTRY");
75+
var sentryDisabled = !string.IsNullOrEmpty(disableSentry) &&
76+
(disableSentry.ToLower() == "true" || disableSentry == "1");
8977

90-
// This option is recommended for client applications only. It ensures all threads use the same global scope.
91-
// If you're writing a background service of any kind, you should remove this.
92-
options.IsGlobalModeEnabled = false;
93-
94-
// This option will enable Sentry's tracing features. You still need to start transactions and spans.
95-
//options.EnableTracing = true;
96-
});
78+
if (!sentryDisabled)
79+
{
80+
SentrySdk.Init(options =>
81+
{
82+
// A Sentry Data Source Name (DSN) is required.
83+
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
84+
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
85+
options.Dsn = "https://a20910d51f605d94e956163ffbf9dd5a@o4506241219428352.ingest.sentry.io/4506279162019840";
86+
87+
// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
88+
// This might be helpful, or might interfere with the normal operation of your application.
89+
// We enable it here for demonstration purposes when first trying Sentry.
90+
// You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
91+
options.Debug = false;
92+
93+
// This option is recommended. It enables Sentry's "Release Health" feature.
94+
options.AutoSessionTracking = true;
95+
96+
// This option is recommended for client applications only. It ensures all threads use the same global scope.
97+
// If you're writing a background service of any kind, you should remove this.
98+
options.IsGlobalModeEnabled = false;
99+
100+
// This option will enable Sentry's tracing features. You still need to start transactions and spans.
101+
//options.EnableTracing = true;
102+
});
103+
}
97104

98105
var host = BuildWebHost(args);
99106
InitializeSettings(host, args).Wait();
@@ -518,17 +525,23 @@ private static IWebHost BuildWebHost(string[] args)
518525
{
519526
string numberString = match.Groups[1].Value;
520527
int number = int.Parse(numberString);
521-
SentrySdk.ConfigureScope(scope =>
528+
var disableSentry = Environment.GetEnvironmentVariable("DISABLE_SENTRY");
529+
var sentryDisabled = !string.IsNullOrEmpty(disableSentry) &&
530+
(disableSentry.ToLower() == "true" || disableSentry == "1");
531+
if (!sentryDisabled)
522532
{
523-
scope.SetTag("customerNo", number.ToString());
524-
Console.WriteLine("customerNo: " + number);
525-
scope.SetTag("osVersion", Environment.OSVersion.ToString());
526-
Console.WriteLine("osVersion: " + Environment.OSVersion);
527-
scope.SetTag("osArchitecture", RuntimeInformation.OSArchitecture.ToString());
528-
Console.WriteLine("osArchitecture: " + RuntimeInformation.OSArchitecture);
529-
scope.SetTag("osName", RuntimeInformation.OSDescription);
530-
Console.WriteLine("osName: " + RuntimeInformation.OSDescription);
531-
});
533+
SentrySdk.ConfigureScope(scope =>
534+
{
535+
scope.SetTag("customerNo", number.ToString());
536+
Console.WriteLine("customerNo: " + number);
537+
scope.SetTag("osVersion", Environment.OSVersion.ToString());
538+
Console.WriteLine("osVersion: " + Environment.OSVersion);
539+
scope.SetTag("osArchitecture", RuntimeInformation.OSArchitecture.ToString());
540+
Console.WriteLine("osArchitecture: " + RuntimeInformation.OSArchitecture);
541+
scope.SetTag("osName", RuntimeInformation.OSDescription);
542+
Console.WriteLine("osName: " + RuntimeInformation.OSDescription);
543+
});
544+
}
532545
}
533546

534547
using var dbContext = contextFactory.CreateDbContext([_defaultConnectionString]);

eform-client/src/app/app.declarations.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import {
7070
CustomMatPaginatorIntl
7171
} from './common/modules/eform-shared/components/eform-pagination/mat_paginator_intl';
7272
import {MAT_FORM_FIELD_DEFAULT_OPTIONS} from '@angular/material/form-field';
73+
import {environment} from '../environments/environment';
7374
// Guards
7475

7576
export let providers = [
@@ -126,21 +127,23 @@ export let providers = [
126127
},
127128
},
128129
{provide: MAT_DATE_LOCALE, useValue: new BehaviorSubject(null)},
129-
{
130-
provide: ErrorHandler,
131-
useValue: Sentry.createErrorHandler({
132-
showDialog: false,
133-
}),
134-
}, {
135-
provide: Sentry.TraceService,
136-
deps: [Router],
137-
},
138-
{
139-
provide: APP_INITIALIZER,
140-
useFactory: () => () => {},
141-
deps: [Sentry.TraceService],
142-
multi: true,
143-
},
130+
...(environment.enableSentry ? [
131+
{
132+
provide: ErrorHandler,
133+
useValue: Sentry.createErrorHandler({
134+
showDialog: false,
135+
}),
136+
}, {
137+
provide: Sentry.TraceService,
138+
deps: [Router],
139+
},
140+
{
141+
provide: APP_INITIALIZER,
142+
useFactory: () => () => {},
143+
deps: [Sentry.TraceService],
144+
multi: true,
145+
}
146+
] : []),
144147
AuthStateService,
145148
AppMenuStateService,
146149
// Helpers

eform-client/src/app/common/interceptors/http-error.interceptor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Injectable, inject } from '@angular/core';
2020
import {AuthMethods, LoaderService} from 'src/app/common/services';
2121
import {AuthResponseModel, OperationDataResult} from 'src/app/common/models';
2222
import * as Sentry from '@sentry/angular';
23+
import {environment} from '../../../environments/environment';
2324

2425

2526
@Injectable()
@@ -45,7 +46,9 @@ export class HttpErrorInterceptor implements HttpInterceptor {
4546
// Handle 400 - Bad Request
4647
catchError((error: HttpErrorResponse) => {
4748
let errorMessage = '';
48-
Sentry.captureException(error); // Log to Sentry
49+
if (environment.enableSentry) {
50+
Sentry.captureException(error); // Log to Sentry only if enabled
51+
}
4952
switch (error.status) {
5053
case 400: {
5154
let errors;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

22
export const environment = {
3-
production: true
3+
production: true,
4+
enableSentry: true // Enable Sentry in production mode
45
};

eform-client/src/environments/environment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
33
// The list of file replacements can be found in `angular.json`.
44
export const environment = {
5-
production: false
5+
production: false,
6+
enableSentry: false // Disable Sentry in development mode
67
};
78

89
/*

eform-client/src/main.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ registerLocaleData(localeTr);
5959
registerLocaleData(localeUk);
6060

6161

62-
Sentry.init({
63-
dsn: 'https://38b1e86a3c4d2532158903ab783bfe5e@o4506241219428352.ingest.sentry.io/4506268847112192',
64-
integrations: [Sentry.browserTracingIntegration()],
65-
// Performance Monitoring
66-
tracesSampleRate: 1.0, // Capture 100% of the transactions
67-
// Session Replay
68-
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
69-
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
70-
});
62+
if (environment.enableSentry) {
63+
Sentry.init({
64+
dsn: 'https://38b1e86a3c4d2532158903ab783bfe5e@o4506241219428352.ingest.sentry.io/4506268847112192',
65+
integrations: [Sentry.browserTracingIntegration()],
66+
// Performance Monitoring
67+
tracesSampleRate: 1.0, // Capture 100% of the transactions
68+
// Session Replay
69+
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
70+
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
71+
});
72+
}
7173

7274
if (environment.production) {
7375
enableProdMode();

0 commit comments

Comments
 (0)