Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Enchancement: Do not serialize empty collections and maps (#1245)
* Ref: Simplify RestTemplate instrumentation (#1246)

Breaking Changes:
* Enchancement: SentryExceptionResolver should not send handled errors by default (#1248).


# 4.1.0

* Improve Kotlin compatibility for SdkVersion (#1213)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SentryProperties extends SentryOptions {
private boolean enableTracing;

/** Report all or only uncaught web exceptions. */
private int exceptionResolverOrder = Integer.MIN_VALUE;
private int exceptionResolverOrder = 1;

/** Logging framework integration properties. */
private @NotNull Logging logging = new Logging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package io.sentry.spring.boot.it
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.anyOrNull
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.never
import com.nhaarman.mockitokotlin2.reset
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import io.sentry.IHub
import io.sentry.ITransportFactory
import io.sentry.Sentry
import io.sentry.spring.tracing.SentrySpan
Expand All @@ -21,13 +23,15 @@ import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.SpyBean
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.core.userdetails.User
Expand All @@ -38,6 +42,8 @@ import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.stereotype.Service
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

Expand All @@ -52,6 +58,9 @@ class SentrySpringIntegrationTest {
@Autowired
lateinit var transport: ITransport

@SpyBean
lateinit var hub: IHub

@LocalServerPort
lateinit var port: Integer

Expand Down Expand Up @@ -137,6 +146,15 @@ class SentrySpringIntegrationTest {
}, anyOrNull())
}
}

@Test
fun `does not send events for handled exceptions`() {
val restTemplate = TestRestTemplate().withBasicAuth("user", "password")

restTemplate.getForEntity("http://localhost:$port/throws-handled", String::class.java)

verify(hub, never()).captureEvent(any())
}
}

@SpringBootApplication
Expand Down Expand Up @@ -168,6 +186,11 @@ class HelloController(private val helloService: HelloService) {
throw RuntimeException("something went wrong")
}

@GetMapping("/throws-handled")
fun throwsHandled() {
throw CustomException("handled exception")
}

@GetMapping("/performance")
fun performance() {
helloService.throws()
Expand Down Expand Up @@ -211,3 +234,12 @@ open class SecurityConfiguration : WebSecurityConfigurerAdapter() {
return InMemoryUserDetailsManager(user)
}
}

class CustomException(message: String) : RuntimeException(message)

@ControllerAdvice
class ExceptionHandlers {

@ExceptionHandler(CustomException::class)
fun handle(e: CustomException) = ResponseEntity.badRequest().build<Void>()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;

/**
* Enables Sentry error handling capabilities.
Expand Down Expand Up @@ -44,5 +43,5 @@
*
* @return the order to use for {@link SentryExceptionResolver}
*/
int exceptionResolverOrder() default Ordered.HIGHEST_PRECEDENCE;
int exceptionResolverOrder() default 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class EnableSentryTest {
contextRunner.run {
assertThat(it).hasSingleBean(SentryExceptionResolver::class.java)
assertThat(it).getBean(SentryExceptionResolver::class.java)
.hasFieldOrPropertyWithValue("order", Integer.MIN_VALUE)
.hasFieldOrPropertyWithValue("order", 1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.Ordered
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
Expand Down Expand Up @@ -140,7 +139,7 @@ class SentrySpringIntegrationTest {
}

@SpringBootApplication
@EnableSentry(dsn = "http://key@localhost/proj", sendDefaultPii = true, exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE)
@EnableSentry(dsn = "http://key@localhost/proj", sendDefaultPii = true)
open class App {

private val transport = mock<ITransport>()
Expand Down