Skip to content

Commit

Permalink
Merge pull request #1770 from BLSQ/IA-3643-sentry-multiple-fix
Browse files Browse the repository at this point in the history
IA-3643: Multiple Sentry integration
  • Loading branch information
beygorghor authored Nov 5, 2024
2 parents 88f0abd + 4281202 commit fe0344d
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 117 deletions.
224 changes: 113 additions & 111 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,119 +1,121 @@
version: "3"
version: '3'
services:
iaso:
stdin_open: true
tty: true
build:
context: .
dockerfile: docker/django/Dockerfile
image: iaso
ports:
- "8081:8081"
volumes: &hat_volumes
- ./manage.py:/opt/app/manage.py
- ./hat:/opt/app/hat
- ./iaso:/opt/app/iaso
- ./setuper:/opt/app/setuper
- ./beanstalk_worker:/opt/app/beanstalk_worker
- ./django_sql_dashboard_export:/opt/app/django_sql_dashboard_export
- ./media:/opt/app/media
- ./plugins:/opt/app/plugins
- ./scripts:/opt/app/scripts
- ./entrypoint.sh:/opt/app/entrypoint.sh
- ./README.md:/opt/app/README.md
- ./tsconfig.json:/opt/app/tsconfig.json
- ./babel-register.js:/opt/app/babel-register.js
- ./mypy.ini:/opt/app/mypy.ini
- ./pyproject.toml:/opt/app/pyproject.toml
# test data
- ./testdata:/opt/app/testdata
# jupyter notebooks
- ./notebooks:/opt/notebooks
# Optional Used to load dev bluesquare-components JS. See `Live Bluesquare components` in doc
- ../bluesquare-components:/opt/bluesquare-components
links: &hat_links
- db
environment: &hat_environment
PREPAREDNESS_TEMPLATE_ID:
PREPAREDNESS_TEMPLATE_FR_ID:
PLUGINS:
GOOGLE_API_KEY_BASE64:
SENTRY_ENVIRONMENT: "development"
RDS_HOSTNAME: db
RDS_DB_NAME:
THEME_PRIMARY_COLOR:
THEME_SECONDARY_COLOR:
THEME_PRIMARY_BACKGROUND_COLOR: #OpenHexa API token
iaso:
stdin_open: true
tty: true
build:
context: .
dockerfile: docker/django/Dockerfile
image: iaso
ports:
- '8081:8081'
volumes: &hat_volumes
- ./manage.py:/opt/app/manage.py
- ./hat:/opt/app/hat
- ./iaso:/opt/app/iaso
- ./setuper:/opt/app/setuper
- ./beanstalk_worker:/opt/app/beanstalk_worker
- ./django_sql_dashboard_export:/opt/app/django_sql_dashboard_export
- ./media:/opt/app/media
- ./plugins:/opt/app/plugins
- ./scripts:/opt/app/scripts
- ./entrypoint.sh:/opt/app/entrypoint.sh
- ./README.md:/opt/app/README.md
- ./tsconfig.json:/opt/app/tsconfig.json
- ./babel-register.js:/opt/app/babel-register.js
- ./mypy.ini:/opt/app/mypy.ini
- ./pyproject.toml:/opt/app/pyproject.toml
# test data
- ./testdata:/opt/app/testdata
# jupyter notebooks
- ./notebooks:/opt/notebooks
# Optional Used to load dev bluesquare-components JS. See `Live Bluesquare components` in doc
- ../bluesquare-components:/opt/bluesquare-components
links: &hat_links
- db
environment: &hat_environment
PREPAREDNESS_TEMPLATE_ID:
PREPAREDNESS_TEMPLATE_FR_ID:
PLUGINS:
GOOGLE_API_KEY_BASE64:
SENTRY_ENVIRONMENT:
SENTRY_URL:
SENTRY_FRONT_ENABLED:
RDS_HOSTNAME: db
RDS_DB_NAME:
THEME_PRIMARY_COLOR:
THEME_SECONDARY_COLOR:
THEME_PRIMARY_BACKGROUND_COLOR: #OpenHexa API token

OPENHEXA_TOKEN: #OpenHexa API url
OPENHEXA_TOKEN: #OpenHexa API url

OPENHEXA_URL: #OpenHexa pipeline ID
OPENHEXA_URL: #OpenHexa pipeline ID

LQAS_PIPELINE: #Optional: the version of the pipeline to run
LQAS_PIPELINE: #Optional: the version of the pipeline to run

LQAS_PIPELINE_VERSION: # "prod", "staging" or "custom". Use "custom" for local testing
LQAS_PIPELINE_VERSION: # "prod", "staging" or "custom". Use "custom" for local testing

OH_PIPELINE_TARGET:
OH_PIPELINE_TARGET:

FAVICON_PATH:
LOGO_PATH:
APP_TITLE:
SHOW_NAME_WITH_LOGO:
RDS_USERNAME: postgres
RDS_PASSWORD: postgres
DB_READONLY_USERNAME: postgres
DB_READONLY_PASSWORD: postgres
DEBUG: "true"
DEBUG_SQL:
DNS_DOMAIN:
TEST_PROD:
SECRET_KEY: secret
AWS_STORAGE_BUCKET_NAME:
AWS_ACCESS_KEY_ID:
AWS_SECRET_ACCESS_KEY:
PYTHONUNBUFFERED: "true"
ENKETO_DEV: "true"
ENKETO_API_TOKEN: AZE78974654azeAZE
ENKETO_URL: http://enketo:8005/
EMAIL_BACKEND: "django.core.mail.backends.console.EmailBackend"
LIVE_COMPONENTS:
WFP_AUTH_CLIENT_ID:
WFP_AUTH_ACCOUNT:
WFP_EMAIL_RECIPIENTS_NEW_ACCOUNT:
DISABLE_PASSWORD_LOGINS:
MAINTENANCE_MODE:
SERVER_URL: # Limit logging in dev to not overflow terminal
logging: &iaso_logging
driver: "json-file"
options:
max-size: "5k"
command: start_dev
FAVICON_PATH:
LOGO_PATH:
APP_TITLE:
SHOW_NAME_WITH_LOGO:
RDS_USERNAME: postgres
RDS_PASSWORD: postgres
DB_READONLY_USERNAME: postgres
DB_READONLY_PASSWORD: postgres
DEBUG: 'true'
DEBUG_SQL:
DNS_DOMAIN:
TEST_PROD:
SECRET_KEY: secret
AWS_STORAGE_BUCKET_NAME:
AWS_ACCESS_KEY_ID:
AWS_SECRET_ACCESS_KEY:
PYTHONUNBUFFERED: 'true'
ENKETO_DEV: 'true'
ENKETO_API_TOKEN: AZE78974654azeAZE
ENKETO_URL: http://enketo:8005/
EMAIL_BACKEND: 'django.core.mail.backends.console.EmailBackend'
LIVE_COMPONENTS:
WFP_AUTH_CLIENT_ID:
WFP_AUTH_ACCOUNT:
WFP_EMAIL_RECIPIENTS_NEW_ACCOUNT:
DISABLE_PASSWORD_LOGINS:
MAINTENANCE_MODE:
SERVER_URL: # Limit logging in dev to not overflow terminal
logging: &iaso_logging
driver: 'json-file'
options:
max-size: '5k'
command: start_dev

db:
image: iaso/postgis
# Workaround until there is a stable Postgis image for Apple Silicon
build: docker/db
logging: *iaso_logging
ports:
- "5433:5432"
volumes:
- ../pgdata-iaso:/var/lib/postgresql/data
environment:
POSTGRES_DB: ${RDS_DB_NAME}
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
# the webpack dev server
webpack:
image: iaso-webpack
platform: linux/amd64
build:
context: .
dockerfile: docker/webpack/Dockerfile
depends_on:
- iaso
ports:
- "3000:3000"
volumes: *hat_volumes
environment: *hat_environment
logging: *iaso_logging
command: start_webpack
db:
image: iaso/postgis
# Workaround until there is a stable Postgis image for Apple Silicon
build: docker/db
logging: *iaso_logging
ports:
- '5433:5432'
volumes:
- ../pgdata-iaso:/var/lib/postgresql/data
environment:
POSTGRES_DB: ${RDS_DB_NAME}
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
# the webpack dev server
webpack:
image: iaso-webpack
platform: linux/amd64
build:
context: .
dockerfile: docker/webpack/Dockerfile
depends_on:
- iaso
ports:
- '3000:3000'
volumes: *hat_volumes
environment: *hat_environment
logging: *iaso_logging
command: start_webpack
21 changes: 15 additions & 6 deletions hat/assets/js/apps/Iaso/domains/app/contexts/SentryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type SentryContextType = {
export type SentryConfig = {
SENTRY_URL?: string;
SENTRY_ENVIRONMENT?: string;
SENTRY_FRONT_ENABLED?: boolean;
};

type Props = {
Expand All @@ -43,6 +44,7 @@ export const useSentry = () => {
return context;
};
const initSentry = (consent: boolean) => {
window.SENTRY_INITIALIZED = true;
if (!consent || !window.SENTRY_CONFIG?.SENTRY_URL) return;
Sentry.init({
dsn: window.SENTRY_CONFIG.SENTRY_URL,
Expand Down Expand Up @@ -109,12 +111,19 @@ export const SentryProvider: FunctionComponent<Props> = ({ children }) => {
const { formatMessage } = useSafeIntl();

useEffect(() => {
const hasStoredConsent = localStorage.getItem('sentry-consent');
if (!hasStoredConsent && Boolean(window.SENTRY_CONFIG?.SENTRY_URL)) {
setShowDialog(true);
}
if (hasStoredConsent) {
initSentry(hasStoredConsent === 'true');
if (window.SENTRY_CONFIG?.SENTRY_FRONT_ENABLED) {
const hasStoredConsent = localStorage.getItem('sentry-consent');
if (
!hasStoredConsent &&
Boolean(window.SENTRY_CONFIG?.SENTRY_URL)
) {
setShowDialog(true);
}
if (hasStoredConsent) {
if (!window.SENTRY_INITIALIZED) {
initSentry(hasStoredConsent === 'true');
}
}
}
}, []);

Expand Down
1 change: 1 addition & 0 deletions hat/assets/js/apps/Iaso/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const queryClient = new QueryClient({
declare global {
interface Window {
SENTRY_CONFIG?: SentryConfig;
SENTRY_INITIALIZED?: boolean;
iasoApp: (
element: HTMLElement,
enabledPluginsName: string[],
Expand Down
1 change: 1 addition & 0 deletions hat/common/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def sentry_config(request: HttpRequest) -> Dict[str, Any]:
"sentry_config": {
"SENTRY_URL": settings.SENTRY_URL or None,
"SENTRY_ENVIRONMENT": settings.ENVIRONMENT or None,
"SENTRY_FRONT_ENABLED": settings.SENTRY_FRONT_ENABLED or None,
}
}
return {"sentry_config": json.dumps(config["sentry_config"])}
Expand Down
1 change: 1 addition & 0 deletions hat/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
DEV_SERVER = os.environ.get("DEV_SERVER", "").lower() == "true"
ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", "development").lower()
SENTRY_URL = os.environ.get("SENTRY_URL", "")
SENTRY_FRONT_ENABLED = os.environ.get("SENTRY_FRONT_ENABLED", "false").lower() == "true"

# There exists plugins using celery for the backend task (but it's not the default task mechanism of Iaso)
# If you have such plugin, you can activate the use of celery by setting this env variable to "true"
Expand Down

0 comments on commit fe0344d

Please sign in to comment.