Repository navigation
Expand file tree
/
Copy pathSentryGraphqlAutoConfiguration.java
More file actions
72 lines (65 loc) · 3.13 KB
/
Copy pathSentryGraphqlAutoConfiguration.java
File metadata and controls
72 lines (65 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package io.sentry.spring.boot.graphql;
import com.jakewharton.nopen.annotation.Open;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.graphql.SentryGraphqlInstrumentation;
import io.sentry.graphql.SentryInstrumentation;
import io.sentry.spring.boot.SentryProperties;
import io.sentry.spring.graphql.SentryDataFetcherExceptionResolverAdapter;
import io.sentry.spring.graphql.SentryGraphqlBeanPostProcessor;
import io.sentry.spring.graphql.SentrySpringSubscriptionHandler;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@Configuration(proxyBeanMethods = false)
@Open
public class SentryGraphqlAutoConfiguration {
@Bean(name = "sentryInstrumentation")
@ConditionalOnMissingBean
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public SentryInstrumentation sentryInstrumentationWebMvc(
final @NotNull SentryProperties sentryProperties,
final @NotNull ObjectProvider<SentryGraphqlInstrumentation.BeforeSpanCallback>
beforeSpanCallback) {
SentryIntegrationPackageStorage.getInstance().addIntegration("Spring5GraphQLWebMVC");
return createInstrumentation(sentryProperties, beforeSpanCallback, false);
}
@Bean(name = "sentryInstrumentation")
@ConditionalOnMissingBean
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public SentryInstrumentation sentryInstrumentationWebflux(
final @NotNull SentryProperties sentryProperties,
final @NotNull ObjectProvider<SentryGraphqlInstrumentation.BeforeSpanCallback>
beforeSpanCallback) {
SentryIntegrationPackageStorage.getInstance().addIntegration("Spring5GraphQLWebFlux");
return createInstrumentation(sentryProperties, beforeSpanCallback, true);
}
/**
* We're not setting defaultDataFetcherExceptionHandler here on purpose and instead use the
* resolver adapter below. This way Springs handler can still forward to other resolver adapters.
*/
private SentryInstrumentation createInstrumentation(
final @NotNull SentryProperties sentryProperties,
final @NotNull ObjectProvider<SentryGraphqlInstrumentation.BeforeSpanCallback>
beforeSpanCallback,
final boolean captureRequestBody) {
return new SentryInstrumentation(
beforeSpanCallback.getIfAvailable(),
new SentrySpringSubscriptionHandler(),
captureRequestBody,
sentryProperties.getGraphql().getIgnoredErrorTypes());
}
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public SentryDataFetcherExceptionResolverAdapter exceptionResolverAdapter() {
return new SentryDataFetcherExceptionResolverAdapter();
}
@Bean
public static SentryGraphqlBeanPostProcessor graphqlBeanPostProcessor() {
return new SentryGraphqlBeanPostProcessor();
}
}