Capturing Transactions
Spring MVC Integration
Sentry Spring Boot integration, once enabled, captures each incoming Spring MVC HTTP request and turns it into a transaction with SentryTracingFilter
. Transaction names follow pattern <HTTP method> <Spring MVC route>
, for example for a request to a following controller:
@RestController
class HelloController {
@GetMapping("/person/{id}")
Person person(@PathVariable Long id) {
...
}
}
Each sampled request executed by this controller method will be turned into a transaction GET /person/{id}
.
RestTemplate Instrumentation
Sentry Spring Boot integration provides SentrySpanRestTemplateCustomizer
that creates a span for each outgoing HTTP request executed with a RestTemplate
. To use instrumented RestTemplate
make sure to create RestTemplate
beans using RestTemplateBuilder
:
@Configuration
class AppConfig {
@Bean
RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
}
Capturing Bean Method Execution
Capturing Transaction
Every Spring bean method execution can be turned into a transaction or a span. To enable this feature, you must include spring-boot-starter-aop
in your application:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
Methods executed outside of Spring MVC request processing can be turned into transactions by annotating them with @SentryTransaction
annotation:
@Component
class ScheduledJob {
@Scheduled(...)
@SentryTransaction
void execute() {
...
}
}
@SentryTransaction
can be configured with custom name
and op
properties. If not defined, name
will be resolved from the class, and the method name.
Advanced Spring AOP users can redefine transaction pointcut by providing a custom org.springframework.aop.Pointcut
bean with name sentryTransactionPointcut
.
Capturing Span
To create a span around a method execution, annotate method with @SentrySpan
annotation:
@Component
class PersonService {
@SentrySpan
Person findById(Long id) {
...
}
}
@SentrySpan
can be configured with custom description
and op
properties. If not defined, description
will be resolved from the class, and the method name.
Advanced Spring AOP users can redefine span pointcut by providing a custom org.springframework.aop.Pointcut
bean with name sentrySpanPointcut
.