Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QA] Monitorer la plateforme et tracker les erreurs JS #2230

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ MATOMO_SITE_ID=1
ZAPIER_OILHI_TOKEN=
ZAPIER_OILHI_USER_ID=
ZAPIER_OILHI_CREATE_AIRTABLE_RECORD_ZAP_ID=
SECURITY_CSP_HEADER_VALUE="default-src 'self' https://interfaces.zapier.com https://tibot-histologe.zapier.app; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.matomo.cloud https://unpkg.com https://interfaces.zapier.com; style-src 'self' 'unsafe-inline' https://unpkg.com; img-src 'self' data: blob: https://voxusagers.numerique.gouv.fr https://*.tile.openstreetmap.org https://unpkg.com https://jedonnemonavis.numerique.gouv.fr; connect-src 'self' https://api-adresse.data.gouv.fr https://cdn.matomo.cloud https://koumoul.com; font-src 'self'; frame-src 'none'; object-src 'none';"
SECURITY_CSP_HEADER_VALUE="default-src 'self' https://interfaces.zapier.com https://tibot-histologe.zapier.app; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.matomo.cloud https://unpkg.com https://interfaces.zapier.com; style-src 'self' 'unsafe-inline' https://unpkg.com; img-src 'self' data: blob: https://voxusagers.numerique.gouv.fr https://*.tile.openstreetmap.org https://unpkg.com https://jedonnemonavis.numerique.gouv.fr; connect-src 'self' https://api-adresse.data.gouv.fr https://cdn.matomo.cloud https://koumoul.com https://sentry.incubateur.net; font-src 'self'; frame-src 'none'; object-src 'none';"
CHATBOT_ENABLE=0
MAINTENANCE_ENABLE=0
MAINTENANCE_BANNER_ENABLE=0
MAINTENANCE_BANNER_MESSAGE="Une opération de maintenance est prévu le XX/XX/XXXX à XX:XX. Le site sera indisponible pendant la durée de l'opération."

AXIOS_TIMEOUT=30000
### histologe ###

### object storage S3 ###
Expand All @@ -65,8 +65,9 @@ S3_URL_BUCKET=

###> sentry/sentry-symfony ###
SENTRY_DSN=
SENTRY_ENVIRONMENT=
SENTRY_TRACES_SAMPLE_RATE=
SENTRY_DSN_FRONT=https://06f9905de7b646ec902183ce78384f18@sentry.incubateur.net/142
SENTRY_ENVIRONMENT=prod
SENTRY_TRACES_SAMPLE_RATE=1.0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finalement besoin de ces valeurs sur la phase de build js et y'a pas d'enjeu à exposer ces valeurs, faudra par contre filtrer les événements provenant de localhost sur le dashboard

###< sentry/sentry-symfony ###

### wiremock ###
Expand Down
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ MATOMO_SITE_ID=1
ZAPIER_OILHI_TOKEN=
ZAPIER_OILHI_ID=
ZAPIER_OILHI_CREATE_AIRTABLE_RECORD_ZAP_ID=
SECURITY_CSP_HEADER_VALUE="default-src 'self' https://interfaces.zapier.com https://tibot-histologe.zapier.app; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.matomo.cloud https://unpkg.com https://interfaces.zapier.com; style-src 'self' 'unsafe-inline' https://unpkg.com; img-src 'self' data: blob: https://voxusagers.numerique.gouv.fr https://*.tile.openstreetmap.org https://unpkg.com https://jedonnemonavis.numerique.gouv.fr; connect-src 'self' https://api-adresse.data.gouv.fr https://cdn.matomo.cloud https://koumoul.com; font-src 'self'; frame-src 'none'; object-src 'none';"
SECURITY_CSP_HEADER_VALUE="default-src 'self' https://interfaces.zapier.com https://tibot-histologe.zapier.app; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.matomo.cloud https://unpkg.com https://interfaces.zapier.com; style-src 'self' 'unsafe-inline' https://unpkg.com; img-src 'self' data: blob: https://voxusagers.numerique.gouv.fr https://*.tile.openstreetmap.org https://unpkg.com https://jedonnemonavis.numerique.gouv.fr; connect-src 'self' https://api-adresse.data.gouv.fr https://cdn.matomo.cloud https://koumoul.com https://sentry.incubateur.net; font-src 'self'; frame-src 'none'; object-src 'none';"
CHATBOT_ENABLE=0
MAINTENANCE_ENABLE=0
MAINTENANCE_BANNER_ENABLE=0
MAINTENANCE_BANNER_MESSAGE="Une opération de maintenance est prévu le XX/XX/XXXX à XX:XX. Le site sera indisponible pendant la durée de l'opération."
AXIOS_TIMEOUT=30000

###> knplabs/knp-snappy-bundle ###
WKHTMLTOPDF_PATH=wkhtmltopdf
Expand Down Expand Up @@ -69,6 +70,7 @@ S3_URL_BUCKET=

###> sentry/sentry-symfony ###
SENTRY_DSN=
SENTRY_DSN_FRONT=
SENTRY_ENVIRONMENT=
SENTRY_TRACES_SAMPLE_RATE=
###< sentry/sentry-symfony ###
Expand Down
17 changes: 14 additions & 3 deletions assets/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
import './styles/histologe.scss';
import './styles/tooltip.scss';

// start the Stimulus application
// import './bootstrap';
import * as Sentry from '@sentry/browser';

import {
SENTRY_DSN_FRONT,
SENTRY_ENVIRONMENT,
SENTRY_TRACES_SAMPLE_RATE
} from'./controllers/environment'

Sentry.init({
dsn: SENTRY_DSN_FRONT,
integrations: [Sentry.browserTracingIntegration()],
environment: SENTRY_ENVIRONMENT,
tracesSampleRate: SENTRY_TRACES_SAMPLE_RATE,
});

import './vue/index';
import './vue/front-stats';
Expand All @@ -28,4 +40,3 @@ import './controllers/view_signalement';
import './controllers/cookie_banner';
import './controllers/maintenance_banner';
import './controllers/activate_account/activate_account';

11 changes: 11 additions & 0 deletions assets/controllers/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const SENTRY_DSN_FRONT = process.env.SENTRY_DSN_FRONT
const SENTRY_ENVIRONMENT = process.env.SENTRY_ENVIRONMENT
const SENTRY_TRACES_SAMPLE_RATE = parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE)
const AXIOS_TIMEOUT = parseInt(process.env.AXIOS_TIMEOUT)

export {
SENTRY_DSN_FRONT,
SENTRY_ENVIRONMENT,
SENTRY_TRACES_SAMPLE_RATE,
AXIOS_TIMEOUT
};
Copy link
Collaborator Author

@sfinx13 sfinx13 Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Les variables d'environnements ne sont pas tous exposé à travers process.env mais l'accès se fait directement à travers son nom (console.log(process.env) ne marchera pas)
  • Une fois le build effectué, seule la valeur est présente dans le fichier buildé
  • Exposer uniquement les données utile et non sensible (utilise le .env en locale)
    image

Pour en savoir plus
https://www.npmjs.com/package/dotenv-webpack#how-secure

4 changes: 3 additions & 1 deletion assets/vue/components/dashboard/requests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios'
import { store } from './store'
import * as Sentry from '@sentry/browser'

export const requests = {
doRequest (ajaxUrl: string, functionReturn: Function) {
Expand All @@ -10,7 +11,8 @@ export const requests = {
functionReturn(responseData)
})
.catch(error => {
console.log(error)
console.error(error)
Sentry.captureException(new Error(error))
functionReturn('error')
})
},
Expand Down
13 changes: 6 additions & 7 deletions assets/vue/components/front-stats/requests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios'
import { store } from './store'
import * as Sentry from '@sentry/browser'

export const requests = {
/**
Expand All @@ -11,15 +12,13 @@ export const requests = {
axios
.get(ajaxUrl, { timeout: 15000 })
.then(response => {
const responseData = response.data
console.log('then')
console.log(responseData)
functionReturn(responseData)
const responseData = response.data
functionReturn(responseData)
})
.catch(error => {
console.log('error.toJSON')
console.log(error)
functionReturn('error')
console.error(error)
Sentry.captureException(new Error(error))
functionReturn('error')
})
}
}
20 changes: 12 additions & 8 deletions assets/vue/components/signalement-form/requests.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import axios from 'axios'
import formStore from './store'
import * as Sentry from '@sentry/browser'
import { AXIOS_TIMEOUT } from '../../../controllers/environment'

export const requests = {
// TODO : voir avec Emilien pour ne plus gérer via des callbacks mais faire de l'async pour rendre le code plus lisible
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Réflexion partagé cette été mais pas d'enjeu je supprime (une histoire d'habitude)

doRequestGet (ajaxUrl: string, functionReturn: Function) {
axios
.get(ajaxUrl, { timeout: 15000 })
.get(ajaxUrl, { timeout: AXIOS_TIMEOUT })
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai pas appliqué la constante à tous les composants car l'enjeu est uniquement sur le formulaire

.then(response => {
const responseData = response.data
functionReturn(responseData)
})
.catch(error => {
console.log(error)
console.error(error)
Sentry.captureException(new Error(error))
functionReturn('error')
})
},
doRequestPost (ajaxUrl: string, data: any, functionReturn: Function, config: any) {
if (config !== undefined) {
config.timeout = 15000
config.timeout = AXIOS_TIMEOUT
} else {
config = { timeout: 15000 }
config = { timeout: AXIOS_TIMEOUT }
}
axios
.post(ajaxUrl, data, config)
Expand All @@ -28,19 +30,21 @@ export const requests = {
functionReturn(responseData)
})
.catch(error => {
console.log(error)
console.error(error)
Sentry.captureException(new Error(error))
functionReturn(error)
})
},
doRequestPut (ajaxUrl: string, data: any, functionReturn: Function) {
axios
.put(ajaxUrl, data, { timeout: 15000 })
.put(ajaxUrl, data, { timeout: AXIOS_TIMEOUT })
.then(response => {
const responseData = response.data
functionReturn(responseData)
})
.catch(error => {
console.log(error)
console.error(error)
Sentry.captureException(new Error(error))
functionReturn('error')
})
},
Expand Down
7 changes: 3 additions & 4 deletions assets/vue/components/stats/requests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios'
import { store } from './store'
import * as Sentry from '@sentry/browser'

export const requests = {
filter (functionReturn: Function) {
Expand Down Expand Up @@ -29,13 +30,11 @@ export const requests = {
.post(store.props.ajaxurl, data, { timeout: 15000 })
.then(response => {
const responseData = response.data
console.log('then')
console.log(responseData)
functionReturn(responseData)
})
.catch(error => {
console.log('error.toJSON')
console.log(error)
console.error(error)
Sentry.captureException(new Error(error))
functionReturn('error')
})
}
Expand Down
Loading
Loading