Description
When sentry.dsn property contains trailing whitespace characters (commonly introduced by copy-paste from documents, wikis, or configuration management tools), the Sentry SDK fails to initialize and crashes the entire Spring Boot application with a URISyntaxException.
Steps to Reproduce
-
Set the DSN with trailing whitespace in application.properties:
sentry.dsn=https://examplePublicKey@o0.ingest.sentry.io/0
(note the trailing spaces after the project ID)
-
Start the Spring Boot application
-
Application fails to start:
Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException.
Message: Error creating bean with name 'sentryUserFilter' ...
Failed to instantiate [io.sentry.IScopes]: Factory method 'sentryHub' threw exception with message:
java.net.URISyntaxException: Illegal character in path at index 95:
https://examplePublicKey@o0.ingest.sentry.io/0
Expected Behavior
The SDK should trim whitespace from the DSN string before parsing it as a URI. The application should initialize normally.
Actual Behavior
The application crashes on startup because Dsn.java constructor passes the raw (untrimmed) string directly to new URI(dsn).
Root Cause
In sentry/src/main/java/io/sentry/Dsn.java:
Dsn(@Nullable String dsn) throws IllegalArgumentException {
try {
Objects.requireNonNull(dsn, "The DSN is required.");
final URI uri = new URI(dsn).normalize(); // No trim() before URI parsing
Proposed Fix
final URI uri = new URI(dsn.trim()).normalize();
Impact
This is a production-breaking issue. A single trailing space in the DSN configuration causes the entire application to fail to start. This is especially common when:
- Copy-pasting DSN from Sentry dashboard or documentation
- Editing properties files manually on servers
- Configuration values are set via environment variables with accidental whitespace
Environment
sentry-spring-boot-starter-jakarta: 8.x
- Spring Boot: 3.5.5
- Java: 21 (Amazon Corretto)
I'd be happy to submit a PR for this fix if the team agrees with the approach.
Description
When
sentry.dsnproperty contains trailing whitespace characters (commonly introduced by copy-paste from documents, wikis, or configuration management tools), the Sentry SDK fails to initialize and crashes the entire Spring Boot application with aURISyntaxException.Steps to Reproduce
Set the DSN with trailing whitespace in
application.properties:sentry.dsn=https://examplePublicKey@o0.ingest.sentry.io/0(note the trailing spaces after the project ID)
Start the Spring Boot application
Application fails to start:
Expected Behavior
The SDK should trim whitespace from the DSN string before parsing it as a URI. The application should initialize normally.
Actual Behavior
The application crashes on startup because
Dsn.javaconstructor passes the raw (untrimmed) string directly tonew URI(dsn).Root Cause
In
sentry/src/main/java/io/sentry/Dsn.java:Proposed Fix
Impact
This is a production-breaking issue. A single trailing space in the DSN configuration causes the entire application to fail to start. This is especially common when:
Environment
sentry-spring-boot-starter-jakarta: 8.xI'd be happy to submit a PR for this fix if the team agrees with the approach.