feat(backend): add Sentry/GlitchTip error reporting via sentry-spring-boot-starter-jakarta #592
@@ -225,11 +225,13 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Sentry error reporting (GlitchTip-compatible) -->
|
<!-- Sentry error reporting (GlitchTip-compatible) — sentry-spring-boot-4 is the
|
||||||
|
Spring Boot 4 / Spring Framework 7 compatible module (replaces the jakarta starter
|
||||||
|
which crashes with SF7 due to bean-name generation for triply-nested @Import classes) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.sentry</groupId>
|
<groupId>io.sentry</groupId>
|
||||||
<artifactId>sentry-spring-boot-starter-jakarta</artifactId>
|
<artifactId>sentry-spring-boot-4</artifactId>
|
||||||
<version>8.5.0</version>
|
<version>8.41.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package org.raddatz.familienarchiv.config;
|
|
||||||
|
|
||||||
import io.sentry.Sentry;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import org.raddatz.familienarchiv.exception.DomainException;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
// SentryAutoConfiguration is excluded (see application.yaml) because Spring Boot 4 / Spring
|
|
||||||
// Framework 7 cannot generate a bean name for the triply-nested
|
|
||||||
// SentryAutoConfiguration$HubConfiguration$SentrySpanRestClientConfiguration class.
|
|
||||||
// This bean replicates the essential init: DSN, environment, sample rate, PII guard,
|
|
||||||
// and DomainException filter.
|
|
||||||
@Configuration
|
|
||||||
public class SentryConfig {
|
|
||||||
|
|
||||||
@Value("${sentry.dsn:}")
|
|
||||||
private String dsn;
|
|
||||||
|
|
||||||
@Value("${sentry.environment:dev}")
|
|
||||||
private String environment;
|
|
||||||
|
|
||||||
@Value("${sentry.traces-sample-rate:1.0}")
|
|
||||||
private double tracesSampleRate;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
if (dsn == null || dsn.isBlank()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Sentry.init(options -> {
|
|
||||||
options.setDsn(dsn);
|
|
||||||
options.setEnvironment(environment);
|
|
||||||
options.setTracesSampleRate(tracesSampleRate);
|
|
||||||
options.setSendDefaultPii(false);
|
|
||||||
options.addIgnoredExceptionForType(DomainException.class);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,13 +38,6 @@ spring:
|
|||||||
starttls:
|
starttls:
|
||||||
enable: true
|
enable: true
|
||||||
|
|
||||||
autoconfigure:
|
|
||||||
exclude:
|
|
||||||
# SentryAutoConfiguration fails on Spring Boot 4/Spring Framework 7: Spring cannot generate a
|
|
||||||
# bean name for the triply-nested SentryAutoConfiguration$HubConfiguration$SentrySpanRestClientConfiguration.
|
|
||||||
# Sentry is initialized manually via SentryConfig instead. See #580.
|
|
||||||
- io.sentry.spring.boot.jakarta.SentryAutoConfiguration
|
|
||||||
|
|
||||||
server:
|
server:
|
||||||
# Behind Caddy/reverse proxy: trust X-Forwarded-{Proto,For,Host} so that
|
# Behind Caddy/reverse proxy: trust X-Forwarded-{Proto,For,Host} so that
|
||||||
# request.getScheme(), redirect URLs, and Spring Session "Secure" cookies
|
# request.getScheme(), redirect URLs, and Spring Session "Secure" cookies
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ class ApplicationContextTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sentry_auto_configuration_is_excluded_from_context() {
|
void sentry_is_disabled_when_no_dsn_is_configured() {
|
||||||
// SentryAutoConfiguration crashes on Spring Boot 4/SF7 — must stay excluded (see #580)
|
// application-test.yaml has no sentry.dsn — SDK must stay inactive so tests are clean
|
||||||
assertThat(ctx.containsBean("sentryAutoConfiguration")).isFalse();
|
assertThat(io.sentry.Sentry.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package org.raddatz.familienarchiv.config;
|
|
||||||
|
|
||||||
import io.sentry.Sentry;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.MockedStatic;
|
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.Mockito.mockStatic;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
|
|
||||||
class SentryConfigTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void init_does_not_call_sentry_when_dsn_is_blank() {
|
|
||||||
SentryConfig config = new SentryConfig();
|
|
||||||
ReflectionTestUtils.setField(config, "dsn", "");
|
|
||||||
ReflectionTestUtils.setField(config, "environment", "test");
|
|
||||||
ReflectionTestUtils.setField(config, "tracesSampleRate", 1.0);
|
|
||||||
|
|
||||||
try (MockedStatic<Sentry> sentryMock = mockStatic(Sentry.class)) {
|
|
||||||
config.init();
|
|
||||||
sentryMock.verifyNoInteractions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void init_calls_sentry_init_when_dsn_is_set() {
|
|
||||||
SentryConfig config = new SentryConfig();
|
|
||||||
ReflectionTestUtils.setField(config, "dsn", "https://key@glitchtip.example.com/1");
|
|
||||||
ReflectionTestUtils.setField(config, "environment", "test");
|
|
||||||
ReflectionTestUtils.setField(config, "tracesSampleRate", 0.5);
|
|
||||||
|
|
||||||
try (MockedStatic<Sentry> sentryMock = mockStatic(Sentry.class)) {
|
|
||||||
config.init();
|
|
||||||
sentryMock.verify(() -> Sentry.init(any(Sentry.OptionsConfiguration.class)), times(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void init_does_not_call_sentry_when_dsn_is_null() {
|
|
||||||
SentryConfig config = new SentryConfig();
|
|
||||||
ReflectionTestUtils.setField(config, "dsn", null);
|
|
||||||
ReflectionTestUtils.setField(config, "environment", "test");
|
|
||||||
ReflectionTestUtils.setField(config, "tracesSampleRate", 1.0);
|
|
||||||
|
|
||||||
try (MockedStatic<Sentry> sentryMock = mockStatic(Sentry.class)) {
|
|
||||||
config.init();
|
|
||||||
sentryMock.verifyNoInteractions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,12 +13,6 @@ spring:
|
|||||||
password: test
|
password: test
|
||||||
mail:
|
mail:
|
||||||
host: localhost
|
host: localhost
|
||||||
autoconfigure:
|
|
||||||
exclude:
|
|
||||||
# SentryAutoConfiguration fails on Spring Boot 4/Spring Framework 7: Spring cannot generate a
|
|
||||||
# bean name for the triply-nested SentryAutoConfiguration$HubConfiguration$SentrySpanRestClientConfiguration.
|
|
||||||
# Sentry is wired manually via SentryConfig instead. See #580.
|
|
||||||
- io.sentry.spring.boot.jakarta.SentryAutoConfiguration
|
|
||||||
|
|
||||||
# Disable OTel SDK entirely in tests — prevents auto-configuration from loading resource providers
|
# Disable OTel SDK entirely in tests — prevents auto-configuration from loading resource providers
|
||||||
# (e.g. AzureAppServiceResourceProvider) that fail against the semconv version used here.
|
# (e.g. AzureAppServiceResourceProvider) that fail against the semconv version used here.
|
||||||
|
|||||||
Reference in New Issue
Block a user