---
title: "Automatic Instrumentation"
description: "Learn what transactions we capture after tracing is enabled."
url: https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/automatic-instrumentation/
---

# Automatic Instrumentation | Sentry for Spring

Capturing transactions requires that you first [set up tracing](https://docs.sentry.io/platforms/java/guides/spring/tracing.md) if you haven't already.

### [Spring MVC Integration](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/automatic-instrumentation.md#spring-mvc-integration)

Sentry Spring 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:

**Java**

```java
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@RestController
class HelloController {

  @GetMapping("/person/{id}")
  Person person(@PathVariable Long id) {
    ...
  }
}
```

**Kotlin**

```kotlin
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable

@RestController
class HelloController {

  @GetMapping("/person/{id}")
  fun person(@PathVariable id: Long) {
    ...
  }
}
```

Each sampled request executed by this controller method will be turned into a transaction `GET /person/{id}`.

### [RestTemplate Instrumentation](https://docs.sentry.io/platforms/java/guides/spring/tracing/instrumentation/automatic-instrumentation.md#resttemplate-instrumentation)

Sentry Spring integration provides `SentrySpanClientHttpRequestInterceptor` that creates a span for each outgoing HTTP request executed with a `RestTemplate`. To use instrumented `RestTemplate` make sure to set interceptor on the `RestTemplate` bean:

**Java (Spring 5)**

```java
import io.sentry.IScopes;
import io.sentry.spring.tracing.SentrySpanClientHttpRequestInterceptor;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriTemplateHandler;

@Configuration
class AppConfig {

  @Bean
  RestTemplate restTemplate(IScopes scopes) {
    RestTemplate restTemplate = new RestTemplate();
    SentrySpanClientHttpRequestInterceptor sentryRestTemplateInterceptor =
        new SentrySpanClientHttpRequestInterceptor(scopes);
    restTemplate.setInterceptors(Collections.singletonList(sentryRestTemplateInterceptor));
    return restTemplate;
  }
}
```

**Java (Spring 6)**

```java
import io.sentry.IScopes;
import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriTemplateHandler;

@Configuration
class AppConfig {

  @Bean
  RestTemplate restTemplate(IScopes scopes) {
    RestTemplate restTemplate = new RestTemplate();
    SentrySpanClientHttpRequestInterceptor sentryRestTemplateInterceptor =
        new SentrySpanClientHttpRequestInterceptor(scopes);
    restTemplate.setInterceptors(Collections.singletonList(sentryRestTemplateInterceptor));
    return restTemplate;
  }
}
```

**Java (Spring 7)**

```java
import io.sentry.IScopes;
import io.sentry.spring7.tracing.SentrySpanClientHttpRequestInterceptor;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriTemplateHandler;

@Configuration
class AppConfig {

  @Bean
  RestTemplate restTemplate(IScopes scopes) {
    RestTemplate restTemplate = new RestTemplate();
    SentrySpanClientHttpRequestInterceptor sentryRestTemplateInterceptor =
        new SentrySpanClientHttpRequestInterceptor(scopes);
    restTemplate.setInterceptors(Collections.singletonList(sentryRestTemplateInterceptor));
    return restTemplate;
  }
}
```

**Kotlin (Spring 5)**

```kotlin
import io.sentry.IScopes
import io.sentry.spring.tracing.SentrySpanClientHttpRequestInterceptor
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.client.RestTemplate
import org.springframework.web.util.UriTemplateHandler

@Configuration
class AppConfig {

  @Bean
  fun restTemplate(scopes: IScopes): RestTemplate {
    val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor(scopes)

    return RestTemplate().apply {
      interceptors = listOf(sentryRestTemplateInterceptor)
    }
  }
}
```

**Kotlin (Spring 6)**

```kotlin
import io.sentry.IScopes
import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.client.RestTemplate
import org.springframework.web.util.UriTemplateHandler

@Configuration
class AppConfig {

  @Bean
  fun restTemplate(scopes: IScopes): RestTemplate {
    val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor(scopes)

    return RestTemplate().apply {
      interceptors = listOf(sentryRestTemplateInterceptor)
    }
  }
}
```

**Kotlin (Spring 7)**

```kotlin
import io.sentry.IScopes
import io.sentry.spring7.tracing.SentrySpanClientHttpRequestInterceptor
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.client.RestTemplate
import org.springframework.web.util.UriTemplateHandler

@Configuration
class AppConfig {

  @Bean
  fun restTemplate(scopes: IScopes): RestTemplate {
    val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor(scopes)

    return RestTemplate().apply {
      interceptors = listOf(sentryRestTemplateInterceptor)
    }
  }
}
```
