|
24 | 24 | import io.sentry.IScope; |
25 | 25 | import io.sentry.Sentry; |
26 | 26 | import io.sentry.protocol.User; |
27 | | -import io.sentry.spring.boot.jakarta.SentryProperties; |
28 | 27 | import jakarta.annotation.PostConstruct; |
29 | 28 | import lombok.RequiredArgsConstructor; |
30 | 29 | import org.eclipse.lsp4j.ServerInfo; |
31 | | -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
32 | | -import org.springframework.context.annotation.DependsOn; |
| 30 | +import org.springframework.beans.factory.annotation.Value; |
33 | 31 | import org.springframework.stereotype.Component; |
34 | 32 |
|
35 | 33 | import java.util.UUID; |
|
41 | 39 | */ |
42 | 40 | @Component |
43 | 41 | @RequiredArgsConstructor |
44 | | -@ConditionalOnBean(name = "sentryHub") |
45 | | -@DependsOn("sentryHub") |
46 | 42 | public class SentryScopeConfigurer { |
47 | 43 |
|
48 | 44 | private final ServerInfo serverInfo; |
49 | | - private final SentryProperties sentryProperties; |
| 45 | + |
| 46 | + @Value("${sentry.dsn}") |
| 47 | + private final String dsn; |
| 48 | + |
| 49 | + @Value("${sentry.environment}") |
| 50 | + private final String environment; |
50 | 51 |
|
51 | 52 | @PostConstruct |
52 | 53 | public void init() { |
| 54 | + if (dsn != null && !dsn.isEmpty()) { |
| 55 | + Sentry.init(options -> { |
| 56 | + options.setDsn(dsn); |
| 57 | + options.setEnvironment(environment); |
| 58 | + options.setRelease(serverInfo.getVersion()); |
| 59 | + options.setTag("server.version", serverInfo.getVersion()); |
| 60 | + options.setAttachServerName(false); |
| 61 | + }); |
| 62 | + } |
| 63 | + |
53 | 64 | Sentry.configureScope((IScope scope) -> { |
54 | 65 | var user = new User(); |
55 | 66 | user.setId(UUID.randomUUID().toString()); |
56 | 67 | scope.setUser(user); |
57 | | - |
58 | | - scope.setTag("server.version", serverInfo.getVersion()); |
59 | 68 | }); |
60 | | - |
61 | | - sentryProperties.setRelease(serverInfo.getVersion()); |
62 | 69 | } |
63 | 70 |
|
64 | 71 | } |
0 commit comments