Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public HttpServletRequestSentryUserProvider(final @NotNull SentryOptions options
public @Nullable User provideUser() {
if (options.getDataCollectionResolver().isUserInfo()) {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
final ServletRequestAttributes servletRequestAttributes =
(ServletRequestAttributes) requestAttributes;
if (requestAttributes instanceof ServletRequestAttributes servletRequestAttributes) {

final HttpServletRequest request = servletRequestAttributes.getRequest();

final User user = new User();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public SentryInitBeanPostProcessor() {
@SuppressWarnings({"unchecked", "deprecation"})
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, @NotNull final String beanName) throws BeansException {
if (bean instanceof SentryOptions) {
final SentryOptions options = (SentryOptions) bean;
if (bean instanceof SentryOptions options) {

if (applicationContext != null) {
applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public final class SentryCacheBeanPostProcessor implements BeanPostProcessor, Pr
@Override
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, final @NotNull String beanName) throws BeansException {
if (bean instanceof CacheManager && !(bean instanceof SentryCacheManagerWrapper)) {
return new SentryCacheManagerWrapper((CacheManager) bean, ScopesAdapter.getInstance());
if (bean instanceof CacheManager cacheManager && !(bean instanceof SentryCacheManagerWrapper)) {
return new SentryCacheManagerWrapper(cacheManager, ScopesAdapter.getInstance());
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public SentryCheckInAdvice(final @NotNull IScopes scopes) {
}

@Override
public Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
public @Nullable Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
final @Nullable Object target = invocation.getThis();
final Method mostSpecificMethod =
AopUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass());
AopUtils.getMostSpecificMethod(
invocation.getMethod(), target != null ? target.getClass() : null);

@Nullable
SentryCheckIn checkInAnnotation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.aopalliance.intercept.MethodInvocation;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.annotation.AnnotationUtils;

Expand All @@ -33,17 +34,19 @@ public SentryCaptureExceptionParameterAdvice(final @NotNull IScopes scopes) {
}

@Override
public Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
public @Nullable Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
final @Nullable Object target = invocation.getThis();
final Method mostSpecificMethod =
AopUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass());
AopUtils.getMostSpecificMethod(
invocation.getMethod(), target != null ? target.getClass() : null);
SentryCaptureExceptionParameter sentryCaptureExceptionParameter =
AnnotationUtils.findAnnotation(mostSpecificMethod, SentryCaptureExceptionParameter.class);

if (sentryCaptureExceptionParameter != null) {
Object[] args = invocation.getArguments();
for (Object arg : args) {
if (arg instanceof Exception) {
captureException((Exception) arg);
if (arg instanceof Exception exception) {
captureException(exception);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void registerMappedBatchLoader(

private @NotNull IScopes scopesFromContext(final @NotNull BatchLoaderEnvironment environment) {
Object context = environment.getContext();
if (context instanceof GraphQLContext) {
GraphQLContext graphqlContext = (GraphQLContext) context;
if (context instanceof GraphQLContext graphqlContext) {

return graphqlContext.getOrDefault(SENTRY_SCOPES_CONTEXT_KEY, NoOpScopes.getInstance());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public final class SentryGraphqlBeanPostProcessor implements BeanPostProcessor,

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof BatchLoaderRegistry) {
return new SentryBatchLoaderRegistry((BatchLoaderRegistry) bean);
if (bean instanceof BatchLoaderRegistry batchLoaderRegistry) {
return new SentryBatchLoaderRegistry(batchLoaderRegistry);
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public final class SentryKafkaProducerBeanPostProcessor
@SuppressWarnings({"unchecked", "rawtypes"})
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, final @NotNull String beanName) throws BeansException {
if (bean instanceof ProducerFactory) {
final @NotNull ProducerFactory factory = (ProducerFactory) bean;
if (bean instanceof ProducerFactory<?, ?> factory) {

final @NotNull SentryProducerPostProcessor pp = new SentryProducerPostProcessor<>();
factory.addPostProcessor(pp);
if (!factory.getPostProcessors().contains(pp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ private boolean isIgnored() {
if (enqueuedTimeStr != null) {
try {
final double enqueuedTimeSeconds = Double.parseDouble(enqueuedTimeStr);
final double nowSeconds = DateUtils.millisToSeconds(System.currentTimeMillis());
// millisToSeconds takes a double; the cast is explicit for Error Prone's
// LongDoubleConversion check.
final double nowSeconds = DateUtils.millisToSeconds((double) System.currentTimeMillis());
final long latencyMs = (long) ((nowSeconds - enqueuedTimeSeconds) * 1000);
if (latencyMs >= 0) {
transaction.setData(SpanDataConvention.MESSAGING_MESSAGE_RECEIVE_LATENCY, latencyMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ public SentrySpanAdvice(final @NotNull IScopes scopes) {

@SuppressWarnings("deprecation")
@Override
public Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
public @Nullable Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
final ISpan activeSpan = scopes.getSpan();

if (activeSpan == null || activeSpan.isNoOp()) {
// there is no active transaction, we do not start new span
return invocation.proceed();
} else {
final @Nullable Object target = invocation.getThis();
final Method mostSpecificMethod =
AopUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass());
AopUtils.getMostSpecificMethod(
invocation.getMethod(), target != null ? target.getClass() : null);
final Class<?> targetClass = invocation.getMethod().getDeclaringClass();
SentrySpan sentrySpan = AnnotationUtils.findAnnotation(mostSpecificMethod, SentrySpan.class);
if (sentrySpan == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SentrySpanClientHttpRequestInterceptor(final @NotNull IScopes scopes) {
}

public SentrySpanClientHttpRequestInterceptor(
final @NotNull IScopes scopes, final @NotNull boolean isRestTemplate) {
final @NotNull IScopes scopes, final boolean isRestTemplate) {
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
this.traceOrigin = isRestTemplate ? TRACE_ORIGIN_REST_TEMPLATE : TRACE_ORIGIN_REST_CLIENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public SentryTransactionAdvice(final @NotNull IScopes scopes) {

@SuppressWarnings("deprecation")
@Override
public Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
public @Nullable Object invoke(final @NotNull MethodInvocation invocation) throws Throwable {
final @Nullable Object target = invocation.getThis();
final Method mostSpecificMethod =
AopUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass());
AopUtils.getMostSpecificMethod(
invocation.getMethod(), target != null ? target.getClass() : null);

@Nullable
SentryTransaction sentryTransaction =
Expand Down Expand Up @@ -116,7 +118,7 @@ private static class TransactionNameAndSource {
private final @NotNull String name;
private final @NotNull TransactionNameSource source;

public TransactionNameAndSource(
TransactionNameAndSource(
final @NotNull String name, final @NotNull TransactionNameSource source) {
this.name = name;
this.source = source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SentryWebExceptionHandler(final @NotNull IScopes scopes) {
public @NotNull Mono<Void> handle(
final @NotNull ServerWebExchange serverWebExchange, final @NotNull Throwable ex) {
final @Nullable IScopes requestScopes =
serverWebExchange.getAttributeOrDefault(SentryWebFilter.SENTRY_SCOPES_KEY, null);
serverWebExchange.getAttribute(SentryWebFilter.SENTRY_SCOPES_KEY);
final @NotNull IScopes scopesToUse = requestScopes != null ? requestScopes : scopes;

return SentryReactorUtils.withSentryScopes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ public boolean supportsEventType(final @NotNull ResolvableType eventType) {
@Override
public void onApplicationEvent(final @NotNull ApplicationEvent event) {
final Object context = LogManager.getContext(false);
if (!(context instanceof LoggerContext)) {
if (!(context instanceof LoggerContext loggerContext)) {
logger.info(
"Sentry Log4j2 appender was not configured because Log4j2 Core is not the active logging backend. Log4j2 API calls may be routed through SLF4J.");
return;
}

final LoggerContext loggerContext = (LoggerContext) context;
final Configuration configuration = loggerContext.getConfiguration();

boolean changed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ final class SentryOkHttpClientBeanPostProcessor implements BeanPostProcessor, Pr
@Override
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, final @NotNull String beanName) throws BeansException {
if (!(bean instanceof OkHttpClient)) {
if (!(bean instanceof OkHttpClient client)) {
return bean;
}

final @NotNull OkHttpClient client = (OkHttpClient) bean;
if (client.getClass() != OkHttpClient.class) {
ScopesAdapter.getInstance()
.getOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ public boolean supportsEventType(final @NotNull ResolvableType eventType) {
@Override
public void onApplicationEvent(final @NotNull ApplicationEvent event) {
final Object context = LogManager.getContext(false);
if (!(context instanceof LoggerContext)) {
if (!(context instanceof LoggerContext loggerContext)) {
logger.info(
"Sentry Log4j2 appender was not configured because Log4j2 Core is not the active logging backend. Log4j2 API calls may be routed through SLF4J.");
return;
}

final LoggerContext loggerContext = (LoggerContext) context;
final Configuration configuration = loggerContext.getConfiguration();

boolean changed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ final class SentryOkHttpClientBeanPostProcessor implements BeanPostProcessor, Pr
@Override
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, final @NotNull String beanName) throws BeansException {
if (!(bean instanceof OkHttpClient)) {
if (!(bean instanceof OkHttpClient client)) {
return bean;
}

final @NotNull OkHttpClient client = (OkHttpClient) bean;
if (client.getClass() != OkHttpClient.class) {
ScopesAdapter.getInstance()
.getOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public HttpServletRequestSentryUserProvider(final @NotNull SentryOptions options
public @Nullable User provideUser() {
if (options.getDataCollectionResolver().isUserInfo()) {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
final ServletRequestAttributes servletRequestAttributes =
(ServletRequestAttributes) requestAttributes;
if (requestAttributes instanceof ServletRequestAttributes servletRequestAttributes) {

final HttpServletRequest request = servletRequestAttributes.getRequest();

final User user = new User();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public SentryInitBeanPostProcessor() {
@SuppressWarnings({"unchecked", "deprecation"})
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, @NotNull final String beanName) throws BeansException {
if (bean instanceof SentryOptions) {
final SentryOptions options = (SentryOptions) bean;
if (bean instanceof SentryOptions options) {

if (applicationContext != null) {
applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public final class SentryCacheBeanPostProcessor implements BeanPostProcessor, Pr
@Override
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, final @NotNull String beanName) throws BeansException {
if (bean instanceof CacheManager && !(bean instanceof SentryCacheManagerWrapper)) {
return new SentryCacheManagerWrapper((CacheManager) bean, ScopesAdapter.getInstance());
if (bean instanceof CacheManager cacheManager && !(bean instanceof SentryCacheManagerWrapper)) {
return new SentryCacheManagerWrapper(cacheManager, ScopesAdapter.getInstance());
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
if (sentryCaptureExceptionParameter != null) {
Object[] args = invocation.getArguments();
for (Object arg : args) {
if (arg instanceof Exception) {
captureException((Exception) arg);
if (arg instanceof Exception exception) {
captureException(exception);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void registerMappedBatchLoader(

private @NotNull IScopes scopesFromContext(final @NotNull BatchLoaderEnvironment environment) {
Object context = environment.getContext();
if (context instanceof GraphQLContext) {
GraphQLContext graphqlContext = (GraphQLContext) context;
if (context instanceof GraphQLContext graphqlContext) {

return graphqlContext.getOrDefault(SENTRY_SCOPES_CONTEXT_KEY, NoOpScopes.getInstance());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public final class SentryGraphqlBeanPostProcessor implements BeanPostProcessor,

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof BatchLoaderRegistry) {
return new SentryBatchLoaderRegistry((BatchLoaderRegistry) bean);
if (bean instanceof BatchLoaderRegistry batchLoaderRegistry) {
return new SentryBatchLoaderRegistry(batchLoaderRegistry);
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public final class SentryKafkaProducerBeanPostProcessor
@SuppressWarnings({"unchecked", "rawtypes"})
public @NotNull Object postProcessAfterInitialization(
final @NotNull Object bean, final @NotNull String beanName) throws BeansException {
if (bean instanceof ProducerFactory) {
final @NotNull ProducerFactory factory = (ProducerFactory) bean;
if (bean instanceof ProducerFactory<?, ?> factory) {

final @NotNull SentryProducerPostProcessor pp = new SentryProducerPostProcessor<>();
factory.addPostProcessor(pp);
if (!factory.getPostProcessors().contains(pp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private boolean isIgnored() {
if (enqueuedTimeStr != null) {
try {
final double enqueuedTimeSeconds = Double.parseDouble(enqueuedTimeStr);
final double nowSeconds = DateUtils.millisToSeconds(System.currentTimeMillis());
final double nowSeconds = DateUtils.millisToSeconds((double) System.currentTimeMillis());
final long latencyMs = (long) ((nowSeconds - enqueuedTimeSeconds) * 1000);
if (latencyMs >= 0) {
transaction.setData(SpanDataConvention.MESSAGING_MESSAGE_RECEIVE_LATENCY, latencyMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SentrySpanClientHttpRequestInterceptor(final @NotNull IScopes scopes) {
}

public SentrySpanClientHttpRequestInterceptor(
final @NotNull IScopes scopes, final @NotNull boolean isRestTemplate) {
final @NotNull IScopes scopes, final boolean isRestTemplate) {
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
this.traceOrigin = isRestTemplate ? TRACE_ORIGIN_REST_TEMPLATE : TRACE_ORIGIN_REST_CLIENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static class TransactionNameAndSource {
private final @NotNull String name;
private final @NotNull TransactionNameSource source;

public TransactionNameAndSource(
TransactionNameAndSource(
final @NotNull String name, final @NotNull TransactionNameSource source) {
this.name = name;
this.source = source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private boolean isIgnored() {
if (enqueuedTimeStr != null) {
try {
final double enqueuedTimeSeconds = Double.parseDouble(enqueuedTimeStr);
final double nowSeconds = DateUtils.millisToSeconds(System.currentTimeMillis());
final double nowSeconds = DateUtils.millisToSeconds((double) System.currentTimeMillis());
final long latencyMs = (long) ((nowSeconds - enqueuedTimeSeconds) * 1000);
if (latencyMs >= 0) {
transaction.setData(SpanDataConvention.MESSAGING_MESSAGE_RECEIVE_LATENCY, latencyMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static class TransactionNameAndSource {
private final @NotNull String name;
private final @NotNull TransactionNameSource source;

public TransactionNameAndSource(
TransactionNameAndSource(
final @NotNull String name, final @NotNull TransactionNameSource source) {
this.name = name;
this.source = source;
Expand Down
Loading