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
121 changes: 121 additions & 0 deletions docs/platforms/java/common/async/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ class AsyncWebMvcConfiguration implements WebMvcConfigurer {
}
```

```java {tabTitle:Java (Spring 7)}
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import io.sentry.spring7.SentryTaskDecorator;

@Configuration
class AsyncWebMvcConfiguration implements WebMvcConfigurer {

@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setTaskExecutor(asyncExecutor());
}

private AsyncTaskExecutor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setTaskDecorator(new SentryTaskDecorator());
executor.initialize();
return executor;
}
}
```

```kotlin {tabTitle:Kotlin (Spring 5)}
import org.springframework.context.annotation.Configuration
import org.springframework.core.task.AsyncTaskExecutor
Expand Down Expand Up @@ -113,6 +139,30 @@ class AsyncWebMvcConfiguration : WebMvcConfigurer {
}
```

```kotlin {tabTitle:Kotlin (Spring 7)}
import org.springframework.context.annotation.Configuration
import org.springframework.core.task.AsyncTaskExecutor
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

import io.sentry.spring7.SentryTaskDecorator

@Configuration
class AsyncWebMvcConfiguration : WebMvcConfigurer {
override fun configureAsyncSupport(configurer: AsyncSupportConfigurer) {
configurer.setTaskExecutor(asyncExecutor())
}

private fun asyncExecutor(): AsyncTaskExecutor {
val executor = ThreadPoolTaskExecutor()
executor.setTaskDecorator(SentryTaskDecorator())
executor.initialize()
return executor
}
}
```

<PlatformSection supported={["java.spring-boot"]}>

Alternatively, if there is a single bean of type `TaskDecorator` in the context, instead of custom `WebMvcConfigurer`, it is enough to create a `SentryTaskDecorator` bean.
Expand Down Expand Up @@ -149,6 +199,22 @@ class SentryConfig {
}
```

```java {tabTitle:Java (Spring 7)}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.sentry.spring7.SentryTaskDecorator;

@Configuration
class SentryConfig {

@Bean
public SentryTaskDecorator sentryTaskDecorator() {
return new SentryTaskDecorator();
}
}
```

```kotlin {tabTitle:Kotlin (Spring 5)}
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down Expand Up @@ -177,6 +243,20 @@ class SentryConfig {
}
```

```kotlin {tabTitle:Kotlin (Spring 7)}
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

import io.sentry.spring7.SentryTaskDecorator

@Configuration
class SentryConfig {

@Bean
fun sentryTaskDecorator() = SentryTaskDecorator()
}
```

</PlatformSection>

## Configuring @Async Methods Task Executor
Expand Down Expand Up @@ -225,6 +305,27 @@ class AsyncMethodConfiguration extends AsyncConfigurerSupport {
}
```

```java {tabTitle:Java (Spring 7)}
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import io.sentry.spring7.SentryTaskDecorator;

import java.util.concurrent.Executor;

@Configuration
class AsyncMethodConfiguration extends AsyncConfigurerSupport {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setTaskDecorator(new SentryTaskDecorator());
executor.initialize();
return executor;
}
}
```

```kotlin {tabTitle:Kotlin (Spring 5)}
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.AsyncConfigurerSupport
Expand Down Expand Up @@ -264,3 +365,23 @@ class AsyncMethodConfiguration : AsyncConfigurerSupport() {
}
}
```

```kotlin {tabTitle:Kotlin (Spring 7)}
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.AsyncConfigurerSupport
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor

import io.sentry.spring7.SentryTaskDecorator

import java.util.concurrent.Executor

@Configuration
class AsyncMethodConfiguration : AsyncConfigurerSupport() {
override fun getAsyncExecutor(): Executor {
val executor = ThreadPoolTaskExecutor()
executor.setTaskDecorator(SentryTaskDecorator())
executor.initialize()
return executor
}
}
```
30 changes: 30 additions & 0 deletions docs/platforms/java/guides/spring-boot/record-user.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ class CustomSentryUserProvider implements SentryUserProvider {
}
```

```java {tabTitle:Java (Spring Boot 4)}
import org.springframework.stereotype.Component;
import io.sentry.protocol.User;
import io.sentry.spring7.SentryUserProvider;

@Component
class CustomSentryUserProvider implements SentryUserProvider {
public User provideUser() {
User user = new User();
// ... set user information
return user
}
}
```

```kotlin {tabTitle:Kotlin (Spring Boot 2)}
import org.springframework.stereotype.Component
import io.sentry.protocol.User
Expand Down Expand Up @@ -86,3 +101,18 @@ class CustomSentryUserProvider : SentryUserProvider {
}
}
```

```kotlin {tabTitle:Kotlin (Spring Boot 4)}
import org.springframework.stereotype.Component
import io.sentry.protocol.User
import io.sentry.spring7.SentryUserProvider

@Component
class CustomSentryUserProvider : SentryUserProvider {
override fun provideUser(): User? {
val user = User()
// ... set user information
return user
}
}
```
Loading
Loading