From 1461436b41e0317868708f21dca7d6ae69fc6404 Mon Sep 17 00:00:00 2001 From: Cedric Rische Date: Fri, 17 Jun 2022 09:07:39 +0200 Subject: [PATCH 1/5] feat: AB#249 Sentry Integration Added Sentry integration to spring boot. Log4J missing! See https://docs.sentry.io/platforms/java/guides/log4j2/ to learn more --- application/src/main/resources/application.properties | 3 +-- pom.xml | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/application/src/main/resources/application.properties b/application/src/main/resources/application.properties index ed59637a..0eb85541 100644 --- a/application/src/main/resources/application.properties +++ b/application/src/main/resources/application.properties @@ -41,15 +41,14 @@ springdoc.swagger-ui.csrf.enabled=true #spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata #spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create #spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=/home/anett/create.sql - #logging.level.org.springframework.security=DEBUG - keycloak.auth-server-url=http://localhost:8080/auth keycloak.realm=projectbuilder keycloak.resource=projectbuilder keycloak.principal-attribute=preferred_username keycloak.public-client=true keycloak.enabled=true +sentry.dsn= diff --git a/pom.xml b/pom.xml index 8a90dc8a..a2c725ba 100644 --- a/pom.xml +++ b/pom.xml @@ -189,6 +189,16 @@ commons-io 2.11.0 + + io.sentry + sentry-spring-boot-starter + 6.1.0 + + + io.sentry + sentry-log4j2 + 6.1.0 + ${project.groupId} From 23b0926087378dd9921df16a8bb4223d4e98d5e6 Mon Sep 17 00:00:00 2001 From: Cedric Rische Date: Fri, 17 Jun 2022 09:11:05 +0200 Subject: [PATCH 2/5] feat: AB#249 Sentry Integration Added sentry to frontend --- webclient/app/package.json | 2 ++ webclient/app/src/index.js | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/webclient/app/package.json b/webclient/app/package.json index 7300b2ec..19f285fa 100755 --- a/webclient/app/package.json +++ b/webclient/app/package.json @@ -9,6 +9,8 @@ "@mui/lab": "^5.0.0-alpha.63", "@mui/material": "^5.0.0", "@mui/styles": "^5.0.0", + "@sentry/react": "^7.1.1", + "@sentry/tracing": "^7.1.1", "@starwit/react-starwit": "^0.0.1-dev1", "axios": "^0.24.0", "i18next": "^21.0.1", diff --git a/webclient/app/src/index.js b/webclient/app/src/index.js index f530ac1e..2be680d6 100755 --- a/webclient/app/src/index.js +++ b/webclient/app/src/index.js @@ -7,16 +7,28 @@ import {HashRouter as Router} from "react-router-dom"; import "./localization/i18n"; import {SnackbarProvider} from "notistack"; import MainTheme from "./app/commons/mainTheme/MainTheme"; +import {BrowserTracing} from "@sentry/tracing"; +import * as Sentry from "@sentry/react"; + +Sentry.init({ + dsn: "[ENTER DSN KEY HERE!]", + integrations: [new BrowserTracing()], + + // We recommend adjusting this value in production, or using tracesSampler + // for finer control + tracesSampleRate: 1.0, + enabled: process.env.NODE_ENV !== "development" +}); ReactDOM.render(( - - - - - - - -), + + + + + + + + ), document.getElementById("root") ) ; From d7cfb594e6bd84631a937ef67b70070ef3b4a16f Mon Sep 17 00:00:00 2001 From: Cedric Rische Date: Tue, 5 Jul 2022 18:05:31 +0200 Subject: [PATCH 3/5] Added dsn key --- webclient/app/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webclient/app/src/index.js b/webclient/app/src/index.js index 2be680d6..43eb716d 100755 --- a/webclient/app/src/index.js +++ b/webclient/app/src/index.js @@ -11,12 +11,12 @@ import {BrowserTracing} from "@sentry/tracing"; import * as Sentry from "@sentry/react"; Sentry.init({ - dsn: "[ENTER DSN KEY HERE!]", + dsn: "https://89ae8cc61d2545a2a88021f96a433b43@o1305630.ingest.sentry.io/6548197", integrations: [new BrowserTracing()], // We recommend adjusting this value in production, or using tracesSampler // for finer control - tracesSampleRate: 1.0, + tracesSampleRate: 0.75, enabled: process.env.NODE_ENV !== "development" }); From 143e9d879ed5f24d6a193efd4eb0ce40c4c12689 Mon Sep 17 00:00:00 2001 From: Cedric Rische Date: Wed, 6 Jul 2022 16:23:56 +0200 Subject: [PATCH 4/5] Added docker environment rewrite for setting variables to frontend --- Dockerfile | 13 ++++++++ entrypoint.sh | 9 ++++++ webclient/app/src/app/AppConfig.js | 8 ++++- .../src/app/commons/sentryInit/SentryInit.jsx | 23 ++++++++++++++ webclient/app/src/index.js | 30 +++++++------------ 5 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 entrypoint.sh create mode 100644 webclient/app/src/app/commons/sentryInit/SentryInit.jsx diff --git a/Dockerfile b/Dockerfile index d87063f4..0bdb71d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,23 @@ RUN pwd RUN mkdir tmp ENV TMP=/home/${USER}/tmp ENV TEMP=/home/${USER}/tmp +ENV SENTRY_TRACES_SAMPLE_RATE_FRONTEND=__SENTRY_TRACES_SAMPLE_RATE_FRONTEND_HERE__ +ENV SENTRY_DSN_FRONTEND=__SENTRY_DSN_FRONTEND_HERE__ +ENV SENTRY_ENVIRONMENT=__SENTRY_ENVIRONMENT_HERE__ + +# Replace env var placeholders before running +ADD entrypoint.sh ./ +ENTRYPOINT ["/app/entrypoint.sh"] + RUN cd /home/${USER} RUN ls -al # copy application JAR (with libraries inside) COPY application/target/application-*.jar /home/ljprojectbuilder/application.jar #COPY /home/ljprojectbuilder/application/target/application-*.jar /home/ljprojectbuilder/application.jar + +ENV SENTRY_TRACES_SAMPLE_RATE_FRONTEND=.75 +ENV SENTRY_DSN_FRONTEND= +ENV SENTRY_ENVIRONMENT=local-development + # specify default command CMD ["/usr/local/openjdk-17/bin/java", "-jar", "/home/ljprojectbuilder/application.jar", "-Dlog4j2.formatMsgNoLookups=true"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..ce78ef9c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# Replace config env vars +printf "Replacing config env vars ..." +find .next/static -type f -exec sed -i -e "s|__SENTRY_DSN_FRONTEND_HERE__|$SENTRY_DSN_FRONTEND|g" -e "s|__SENTRY_ENVIRONMENT_HERE__|$SENTRY_ENVIRONMENT|g" -e "s|__SENTRY_TRACES_SAMPLE_RATE_FRONTEND_HERE__|$SENTRY_TRACES_SAMPLE_RATE_FRONTEND|g" {} \; +printf " done.\n" + +# Run CMD +exec "$@" diff --git a/webclient/app/src/app/AppConfig.js b/webclient/app/src/app/AppConfig.js index cbce77e5..38fc5df2 100644 --- a/webclient/app/src/app/AppConfig.js +++ b/webclient/app/src/app/AppConfig.js @@ -3,4 +3,10 @@ const appMenuItems = [ {title: "apptemplates.title", link: "/apptemplates/all"} ]; -export {appMenuItems}; +const sentryConfiguration = { + dsn: process.env.SENTRY_DSN_FRONTEND, + tracesSampleRate: Number(process.env.SENTRY_TRACES_SAMPLE_RATE_FRONTEND || .75), + environment: process.env.SENTRY_ENVIRONMENT +}; + +export {appMenuItems, sentryConfiguration}; diff --git a/webclient/app/src/app/commons/sentryInit/SentryInit.jsx b/webclient/app/src/app/commons/sentryInit/SentryInit.jsx new file mode 100644 index 00000000..4e4f94c2 --- /dev/null +++ b/webclient/app/src/app/commons/sentryInit/SentryInit.jsx @@ -0,0 +1,23 @@ +import React from "react"; +import * as Sentry from "@sentry/react"; +import {BrowserTracing} from "@sentry/tracing"; +import {sentryConfiguration} from "../../AppConfig"; + +function SentryInit(props) { + Sentry.init({ + dsn: sentryConfiguration.dsn, + integrations: [new BrowserTracing()], + + // We recommend adjusting this value in production, or using tracesSampler + // for finer control + tracesSampleRate: sentryConfiguration.tracesSampleRate, + enabled: process.env.NODE_ENV !== "development", + environment: sentryConfiguration.environment + }); + + return ( + <> + ); +} + +export default SentryInit; diff --git a/webclient/app/src/index.js b/webclient/app/src/index.js index 43eb716d..ef902298 100755 --- a/webclient/app/src/index.js +++ b/webclient/app/src/index.js @@ -7,28 +7,18 @@ import {HashRouter as Router} from "react-router-dom"; import "./localization/i18n"; import {SnackbarProvider} from "notistack"; import MainTheme from "./app/commons/mainTheme/MainTheme"; -import {BrowserTracing} from "@sentry/tracing"; -import * as Sentry from "@sentry/react"; - -Sentry.init({ - dsn: "https://89ae8cc61d2545a2a88021f96a433b43@o1305630.ingest.sentry.io/6548197", - integrations: [new BrowserTracing()], - - // We recommend adjusting this value in production, or using tracesSampler - // for finer control - tracesSampleRate: 0.75, - enabled: process.env.NODE_ENV !== "development" -}); +import SentryInit from "./app/commons/sentryInit/SentryInit"; ReactDOM.render(( - - - - - - - - ), + + + + + + + + +), document.getElementById("root") ) ; From f33e4a3df6b3d6b7b2492419ba2878f758ba0edb Mon Sep 17 00:00:00 2001 From: Cedric Rische Date: Fri, 8 Jul 2022 11:37:55 +0200 Subject: [PATCH 5/5] Added corrected Dockerfile and entrypoint please change find command! --- Dockerfile | 2 +- entrypoint.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 0bdb71d6..517fb0cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ ENV SENTRY_ENVIRONMENT=__SENTRY_ENVIRONMENT_HERE__ # Replace env var placeholders before running ADD entrypoint.sh ./ -ENTRYPOINT ["/app/entrypoint.sh"] +ENTRYPOINT ["/home/ljprojectbuilder/entrypoint.sh"] RUN cd /home/${USER} RUN ls -al diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755