Compare commits

...

5 Commits

Author SHA1 Message Date
Anthony LC
8dcba65ddf test 2024-11-14 13:13:07 +01:00
Jacques ROUSSEL
7e8667f80f 🔐(frontend) bump secret
Add sentry secret for the frontend
2024-11-13 15:05:49 +01:00
Anthony LC
8f73b78476 🩹(backend) get current release from pyproject.toml
In Sentry it is nice to have the release version,
it will help us to track the errors.
get_release was returning NA, we fixed it by
getting the version from pyproject.toml.
To do so we use tomllib, native library since
Python 3.11.
Our docker image is using Python 3.12.6, but our
CI was using Python 3.10, so we bump the CI python
version as well to be able to use tomllib.
2024-11-13 15:05:49 +01:00
Anthony LC
60a66e8783 🧐(backend) adapt Sentry config
We add SENTRY_ENV var, to be able to distinguish
errors between different environments in Sentry
(staging / preprod / prod).
2024-11-13 13:26:09 +01:00
Anthony LC
14a1642fb8 🧐(frontend) add sentry on the frontend side
We want to monitor the frontend side with sentry.
This commit adds the necessary configuration
to the frontend side to send errors to sentry.
2024-11-13 13:26:09 +01:00
16 changed files with 1085 additions and 74 deletions

View File

@@ -6,11 +6,13 @@ on:
push:
branches:
- 'main'
- 'feature/add-sentry'
tags:
- 'v*'
env:
DOCKER_USER: 1001:127
SENTRY_DSN: ""
jobs:
build-and-push-backend:
@@ -109,7 +111,10 @@ jobs:
context: .
file: ./src/frontend/Dockerfile
target: frontend-production
build-args: DOCKER_USER=${{ env.DOCKER_USER }}:-1000
build-args: |
DOCKER_USER=${{ env.DOCKER_USER }}:-1000
SENTRY_DSN=${{ env.SENTRY_DSN }}
SENTRY_ENV=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && 'production' || 'staging' }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@@ -107,7 +107,9 @@ jobs:
- name: Install Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: "3.12.6"
- name: Upgrade pip and setuptools
run: pip install --upgrade pip setuptools
- name: Install development dependencies
run: pip install --user .[dev]
- name: Check code formatting with ruff
@@ -199,7 +201,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: "3.12.6"
- name: Install development dependencies
run: pip install --user .[dev]

View File

@@ -13,6 +13,7 @@ and this project adheres to
- 🌐(frontend) Add German translation #255
- ✨(frontend) Add a broadcast store #387
- 🔊(project) Add sentry #410
## Changed

View File

@@ -15,7 +15,7 @@ services:
- "1081:1080"
minio:
user: ${DOCKER_USER:-1000}
# user: ${DOCKER_USER:-1000}
image: minio/minio
environment:
- MINIO_ROOT_USER=impress

View File

@@ -44,3 +44,6 @@ OIDC_AUTH_REQUEST_EXTRA_PARAMS={"acr_values": "eidas1"}
AI_BASE_URL=https://openaiendpoint.com
AI_API_KEY=password
AI_MODEL=llama
# Sentry
SENTRY_ENV=development

Submodule secrets updated: 38594182e8...d91797b97f

View File

@@ -72,6 +72,8 @@ class AIService:
json_response = json.loads(sanitized_content)
raise RuntimeError("Error Test Sentry")
if "answer" not in json_response:
raise RuntimeError("AI response does not contain an answer")

View File

@@ -10,14 +10,17 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import json
import os
import tomllib
from django.utils.translation import gettext_lazy as _
import sentry_sdk
from configurations import Configuration, values
from sentry_sdk.integrations.django import DjangoIntegration
from logging import getLogger
logger = getLogger(__name__)
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -27,19 +30,12 @@ DATA_DIR = os.path.join("/", "data")
def get_release():
"""
Get the current release of the application
By release, we mean the release from the version.json file à la Mozilla [1]
(if any). If this file has not been found, it defaults to "NA".
[1]
https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md
"""
# Try to get the current release from the version.json file generated by the
# CI during the Docker image build
try:
with open(os.path.join(BASE_DIR, "version.json"), encoding="utf8") as version:
return json.load(version)["version"]
except FileNotFoundError:
with open(os.path.join(BASE_DIR, "pyproject.toml"), "rb") as f:
pyproject_data = tomllib.load(f)
return pyproject_data["project"]["version"]
except (FileNotFoundError, KeyError):
return "NA" # Default: not available
@@ -63,7 +59,7 @@ class Base(Configuration):
* DB_USER
"""
DEBUG = False
DEBUG = True
USE_SWAGGER = False
API_VERSION = "v1.0"
@@ -372,7 +368,8 @@ class Base(Configuration):
CORS_ALLOWED_ORIGIN_REGEXES = values.ListValue([])
# Sentry
SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN")
SENTRY_DSN = values.Value(None, environ_name="SENTRY_DSN", environ_prefix=None)
SENTRY_ENV = values.Value(None, environ_name="SENTRY_ENV", environ_prefix=None)
# Easy thumbnails
THUMBNAIL_EXTENSION = "webp"
@@ -522,6 +519,10 @@ class Base(Configuration):
# The SENTRY_DSN setting should be available to activate sentry for an environment
if cls.SENTRY_DSN is not None:
logger.debug("Sentry is SENTRY_ENV. %s ", cls.SENTRY_ENV)
logger.debug("Sentry is cls.__name__.lower(): %s ", cls.__name__.lower())
print("Sentry is cls.__name__.lower(): %s ", cls.__name__.lower())
print("Sentry is SENTRY_ENV. %s ", cls.SENTRY_ENV)
sentry_sdk.init(
dsn=cls.SENTRY_DSN,
environment=cls.__name__.lower(),

View File

@@ -127,6 +127,7 @@ select = [
[tool.ruff.lint.isort]
section-order = ["future","standard-library","django","third-party","impress","first-party","local-folder"]
sections = { impress=["core"], django=["django"] }
extra-standard-library = ["tomllib"]
[tool.ruff.lint.per-file-ignores]
"**/tests/*" = ["S", "SLF"]

View File

@@ -76,6 +76,12 @@ ENV NEXT_PUBLIC_MEDIA_URL=${MEDIA_URL}
ARG SW_DEACTIVATED
ENV NEXT_PUBLIC_SW_DEACTIVATED=${SW_DEACTIVATED}
ARG SENTRY_DSN
ENV NEXT_PUBLIC_SENTRY_DSN=${SENTRY_DSN}
ARG SENTRY_ENV
ENV NEXT_PUBLIC_SENTRY_ENV=${SENTRY_ENV}
RUN yarn build
# ---- Front-end image ----

View File

@@ -3,3 +3,5 @@ NEXT_PUBLIC_Y_PROVIDER_URL=
NEXT_PUBLIC_MEDIA_URL=
NEXT_PUBLIC_THEME=dsfr
NEXT_PUBLIC_SW_DEACTIVATED=
NEXT_PUBLIC_SENTRY_DSN=
NEXT_PUBLIC_SENTRY_ENV=production

View File

@@ -2,3 +2,4 @@ NEXT_PUBLIC_API_ORIGIN=http://localhost:8071
NEXT_PUBLIC_Y_PROVIDER_URL=ws://localhost:4444
NEXT_PUBLIC_MEDIA_URL=http://localhost:8083
NEXT_PUBLIC_SW_DEACTIVATED=true
NEXT_PUBLIC_SENTRY_ENV=development

View File

@@ -1,5 +1,6 @@
const crypto = require('crypto');
const { withSentryConfig } = require('@sentry/nextjs');
const { InjectManifest } = require('workbox-webpack-plugin');
const buildId = crypto.randomBytes(256).toString('hex').slice(0, 8);
@@ -65,4 +66,6 @@ const nextConfig = {
},
};
module.exports = nextConfig;
module.exports = withSentryConfig(nextConfig, {
silent: false,
});

View File

@@ -21,6 +21,7 @@
"@gouvfr-lasuite/integration": "1.0.2",
"@hocuspocus/provider": "2.13.7",
"@openfun/cunningham-react": "2.9.4",
"@sentry/nextjs": "8.37.1",
"@tanstack/react-query": "5.59.15",
"i18next": "23.16.2",
"i18next-browser-languagedetector": "8.0.0",

View File

@@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';
import packageJson from './package.json';
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
environment: process.env.NEXT_PUBLIC_SENTRY_ENV,
integrations: [Sentry.replayIntegration()],
release: packageJson.version,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
tracesSampleRate: 1.0,
});

File diff suppressed because it is too large Load Diff