|
| 1 | +package io.sentry; |
| 2 | + |
| 3 | +import java.util.Collections; |
| 4 | +import java.util.EnumSet; |
| 5 | +import java.util.Set; |
| 6 | +import org.jetbrains.annotations.ApiStatus; |
| 7 | +import org.jetbrains.annotations.NotNull; |
| 8 | +import org.jetbrains.annotations.Nullable; |
| 9 | + |
| 10 | +/** Configures data that the SDK collects automatically. */ |
| 11 | +public final class DataCollection { |
| 12 | + |
| 13 | + // Forces Data Collection to be used even when no individual option has been configured. |
| 14 | + private boolean forceDataCollection; |
| 15 | + private @Nullable Boolean userInfo; |
| 16 | + private @Nullable KeyValueCollectionBehavior cookies; |
| 17 | + private @Nullable KeyValueCollectionBehavior urlQueryParams; |
| 18 | + private @Nullable Set<HttpBodyType> httpBodies; |
| 19 | + private @Nullable Boolean databaseQueryData; |
| 20 | + private final @NotNull HttpHeaders httpHeaders = new HttpHeaders(); |
| 21 | + private final @NotNull Graphql graphql = new Graphql(); |
| 22 | + |
| 23 | + public DataCollection() { |
| 24 | + this(true); |
| 25 | + } |
| 26 | + |
| 27 | + DataCollection(final boolean forceDataCollection) { |
| 28 | + this.forceDataCollection = forceDataCollection; |
| 29 | + } |
| 30 | + |
| 31 | + public @Nullable Boolean getUserInfo() { |
| 32 | + return userInfo; |
| 33 | + } |
| 34 | + |
| 35 | + public void setUserInfo(final boolean userInfo) { |
| 36 | + this.userInfo = userInfo; |
| 37 | + } |
| 38 | + |
| 39 | + public @Nullable KeyValueCollectionBehavior getCookies() { |
| 40 | + return cookies; |
| 41 | + } |
| 42 | + |
| 43 | + public void setCookies(final @Nullable KeyValueCollectionBehavior cookies) { |
| 44 | + this.cookies = cookies; |
| 45 | + } |
| 46 | + |
| 47 | + public @Nullable KeyValueCollectionBehavior getUrlQueryParams() { |
| 48 | + return urlQueryParams; |
| 49 | + } |
| 50 | + |
| 51 | + public void setUrlQueryParams(final @Nullable KeyValueCollectionBehavior urlQueryParams) { |
| 52 | + this.urlQueryParams = urlQueryParams; |
| 53 | + } |
| 54 | + |
| 55 | + public @Nullable Set<HttpBodyType> getHttpBodies() { |
| 56 | + return httpBodies; |
| 57 | + } |
| 58 | + |
| 59 | + public void setHttpBodies(final @Nullable Set<HttpBodyType> httpBodies) { |
| 60 | + this.httpBodies = |
| 61 | + httpBodies == null |
| 62 | + ? null |
| 63 | + : httpBodies.isEmpty() |
| 64 | + ? Collections.<HttpBodyType>emptySet() |
| 65 | + : Collections.unmodifiableSet(EnumSet.copyOf(httpBodies)); |
| 66 | + } |
| 67 | + |
| 68 | + public @Nullable Boolean getDatabaseQueryData() { |
| 69 | + return databaseQueryData; |
| 70 | + } |
| 71 | + |
| 72 | + public void setDatabaseQueryData(final boolean databaseQueryData) { |
| 73 | + this.databaseQueryData = databaseQueryData; |
| 74 | + } |
| 75 | + |
| 76 | + public @NotNull HttpHeaders getHttpHeaders() { |
| 77 | + return httpHeaders; |
| 78 | + } |
| 79 | + |
| 80 | + public @NotNull Graphql getGraphql() { |
| 81 | + return graphql; |
| 82 | + } |
| 83 | + |
| 84 | + @ApiStatus.Internal |
| 85 | + boolean isExplicitlyConfigured() { |
| 86 | + return forceDataCollection |
| 87 | + || userInfo != null |
| 88 | + || cookies != null |
| 89 | + || urlQueryParams != null |
| 90 | + || httpBodies != null |
| 91 | + || databaseQueryData != null |
| 92 | + || httpHeaders.hasOverrides() |
| 93 | + || graphql.hasOverrides(); |
| 94 | + } |
| 95 | + |
| 96 | + /** Configures collection of request and response HTTP headers. */ |
| 97 | + public static final class HttpHeaders { |
| 98 | + private @Nullable KeyValueCollectionBehavior request; |
| 99 | + private @Nullable KeyValueCollectionBehavior response; |
| 100 | + |
| 101 | + public @Nullable KeyValueCollectionBehavior getRequest() { |
| 102 | + return request; |
| 103 | + } |
| 104 | + |
| 105 | + public void setRequest(final @Nullable KeyValueCollectionBehavior request) { |
| 106 | + this.request = request; |
| 107 | + } |
| 108 | + |
| 109 | + public @Nullable KeyValueCollectionBehavior getResponse() { |
| 110 | + return response; |
| 111 | + } |
| 112 | + |
| 113 | + public void setResponse(final @Nullable KeyValueCollectionBehavior response) { |
| 114 | + this.response = response; |
| 115 | + } |
| 116 | + |
| 117 | + private boolean hasOverrides() { |
| 118 | + return request != null || response != null; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + /** Configures collection of GraphQL document and variable content. */ |
| 123 | + public static final class Graphql { |
| 124 | + private @Nullable Boolean document; |
| 125 | + private @Nullable Boolean variables; |
| 126 | + |
| 127 | + public @Nullable Boolean getDocument() { |
| 128 | + return document; |
| 129 | + } |
| 130 | + |
| 131 | + public void setDocument(final boolean document) { |
| 132 | + this.document = document; |
| 133 | + } |
| 134 | + |
| 135 | + public @Nullable Boolean getVariables() { |
| 136 | + return variables; |
| 137 | + } |
| 138 | + |
| 139 | + public void setVariables(final boolean variables) { |
| 140 | + this.variables = variables; |
| 141 | + } |
| 142 | + |
| 143 | + private boolean hasOverrides() { |
| 144 | + return document != null || variables != null; |
| 145 | + } |
| 146 | + } |
| 147 | +} |
0 commit comments