package de.tum.in.www1.artemis.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;

import io.sentry.Sentry;
import io.sentry.SentryClient;

@Configuration
public class SentryConfiguration {

    @Value("${server.url}")
    private String SERVER_URL;

    @Value("${artemis.version}")
    private String VERSION;

    @Value("${info.sentry.dsn}")
    private String SENTRY_DSN;

    SentryConfiguration() {
        initSentry();
    }

    private void initSentry() {
        if (SENTRY_DSN == null) {
            return;
        }

        final SentryClient client = Sentry.init(SENTRY_DSN + "?stacktrace.app.packages=de.tum.in.www1.artemis");
        client.setRelease(VERSION);
        client.setEnvironment(getEnvironment());
    }

    @Bean
    public HandlerExceptionResolver sentryExceptionResolver() {
        return new io.sentry.spring.SentryExceptionResolver();
    }

    @Bean
    public ServletContextInitializer sentryServletContextInitializer() {
        return new io.sentry.spring.SentryServletContextInitializer();
    }

    private String getEnvironment() {
        switch (SERVER_URL) {
        case "https://artemis.ase.in.tum.de":
            return "prod";
        case "https://artemistest.ase.in.tum.de":
            return "test";
        case "https://vmbruegge60.in.tum.de":
            return "e2e";
        default:
            return "local";
        }
    }
}

@@ -33,16 +33,113 @@
 onfig;%0A%0A
+import javax.annotation.PostConstruct;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -547,16 +547,100 @@
 tion %7B%0A%0A
+    private final Logger log = LoggerFactory.getLogger(SentryConfiguration.class);%0A%0A
     @Val
@@ -822,35 +822,51 @@
 N;%0A%0A    
-SentryConfiguration
+@PostConstruct%0A    public void init
 () %7B%0A   
@@ -874,60 +874,131 @@
     
+f
 in
-itSentry()
+al String dsn = SENTRY_DSN + %22?stacktrace.app.packages=de.tum.in.www1.artemis%22
 ;%0A    
-%7D%0A%0A
     
-private void initSentry() %7B
+log.info(%22Sentry DSN: %22 + dsn);%0A
 %0A   
@@ -1111,70 +1111,11 @@
 nit(
-SENTRY_DSN + %22?stacktrace.app.packages=de.tum.in.www1.artemis%22
+dsn
 );%0A 

Change call cycle in SentryConfiguration to use @PostConstruct annotation (#326)