Skip to content

Commit e38fdbd

Browse files
adinauerclaude
andcommitted
feat(core): Add Data Collection configuration types
Add the public Data Collection model, key-value collection behavior, and HTTP body direction types. Preserve unset values internally so the resolver can distinguish legacy bridge mode from explicit configuration. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent dd4bdfc commit e38fdbd

6 files changed

Lines changed: 470 additions & 0 deletions

File tree

sentry/api/sentry.api

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,40 @@ public final class io/sentry/DataCategory : java/lang/Enum {
383383
public static fun values ()[Lio/sentry/DataCategory;
384384
}
385385

386+
public final class io/sentry/DataCollection {
387+
public fun <init> ()V
388+
public fun getCookies ()Lio/sentry/KeyValueCollectionBehavior;
389+
public fun getDatabaseQueryData ()Ljava/lang/Boolean;
390+
public fun getGraphql ()Lio/sentry/DataCollection$Graphql;
391+
public fun getHttpBodies ()Ljava/util/Set;
392+
public fun getHttpHeaders ()Lio/sentry/DataCollection$HttpHeaders;
393+
public fun getQueryParams ()Lio/sentry/KeyValueCollectionBehavior;
394+
public fun getQueues ()Ljava/lang/Boolean;
395+
public fun getUserInfo ()Ljava/lang/Boolean;
396+
public fun setCookies (Lio/sentry/KeyValueCollectionBehavior;)V
397+
public fun setDatabaseQueryData (Z)V
398+
public fun setHttpBodies (Ljava/util/Set;)V
399+
public fun setQueryParams (Lio/sentry/KeyValueCollectionBehavior;)V
400+
public fun setQueues (Z)V
401+
public fun setUserInfo (Z)V
402+
}
403+
404+
public final class io/sentry/DataCollection$Graphql {
405+
public fun <init> ()V
406+
public fun getDocument ()Ljava/lang/Boolean;
407+
public fun getVariables ()Ljava/lang/Boolean;
408+
public fun setDocument (Z)V
409+
public fun setVariables (Z)V
410+
}
411+
412+
public final class io/sentry/DataCollection$HttpHeaders {
413+
public fun <init> ()V
414+
public fun getRequest ()Lio/sentry/KeyValueCollectionBehavior;
415+
public fun getResponse ()Lio/sentry/KeyValueCollectionBehavior;
416+
public fun setRequest (Lio/sentry/KeyValueCollectionBehavior;)V
417+
public fun setResponse (Lio/sentry/KeyValueCollectionBehavior;)V
418+
}
419+
386420
public final class io/sentry/DateUtils {
387421
public static fun dateToSeconds (Ljava/util/Date;)D
388422
public static fun doubleToBigDecimal (D)Ljava/math/BigDecimal;
@@ -635,6 +669,15 @@ public final class io/sentry/HostnameCache {
635669
public static fun getInstance ()Lio/sentry/HostnameCache;
636670
}
637671

672+
public final class io/sentry/HttpBodyType : java/lang/Enum {
673+
public static final field INCOMING_REQUEST Lio/sentry/HttpBodyType;
674+
public static final field INCOMING_RESPONSE Lio/sentry/HttpBodyType;
675+
public static final field OUTGOING_REQUEST Lio/sentry/HttpBodyType;
676+
public static final field OUTGOING_RESPONSE Lio/sentry/HttpBodyType;
677+
public static fun valueOf (Ljava/lang/String;)Lio/sentry/HttpBodyType;
678+
public static fun values ()[Lio/sentry/HttpBodyType;
679+
}
680+
638681
public final class io/sentry/HttpStatusCodeRange {
639682
public static final field DEFAULT_MAX I
640683
public static final field DEFAULT_MIN I
@@ -1381,6 +1424,24 @@ public abstract interface class io/sentry/JsonUnknown {
13811424
public abstract fun setUnknown (Ljava/util/Map;)V
13821425
}
13831426

1427+
public final class io/sentry/KeyValueCollectionBehavior {
1428+
public static fun allowList ([Ljava/lang/String;)Lio/sentry/KeyValueCollectionBehavior;
1429+
public static fun denyList ([Ljava/lang/String;)Lio/sentry/KeyValueCollectionBehavior;
1430+
public fun equals (Ljava/lang/Object;)Z
1431+
public fun getMode ()Lio/sentry/KeyValueCollectionBehavior$Mode;
1432+
public fun getTerms ()Ljava/util/List;
1433+
public fun hashCode ()I
1434+
public static fun off ()Lio/sentry/KeyValueCollectionBehavior;
1435+
}
1436+
1437+
public final class io/sentry/KeyValueCollectionBehavior$Mode : java/lang/Enum {
1438+
public static final field ALLOW_LIST Lio/sentry/KeyValueCollectionBehavior$Mode;
1439+
public static final field DENY_LIST Lio/sentry/KeyValueCollectionBehavior$Mode;
1440+
public static final field OFF Lio/sentry/KeyValueCollectionBehavior$Mode;
1441+
public static fun valueOf (Ljava/lang/String;)Lio/sentry/KeyValueCollectionBehavior$Mode;
1442+
public static fun values ()[Lio/sentry/KeyValueCollectionBehavior$Mode;
1443+
}
1444+
13841445
public final class io/sentry/MainEventProcessor : io/sentry/EventProcessor, java/io/Closeable {
13851446
public fun <init> (Lio/sentry/SentryOptions;)V
13861447
public fun close ()V
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
private boolean overridden;
14+
private @Nullable Boolean userInfo;
15+
private @Nullable KeyValueCollectionBehavior cookies;
16+
private @Nullable KeyValueCollectionBehavior queryParams;
17+
private @Nullable Set<HttpBodyType> httpBodies;
18+
private @Nullable Boolean databaseQueryData;
19+
private @Nullable Boolean queues;
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 overridden) {
28+
this.overridden = overridden;
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 getQueryParams() {
48+
return queryParams;
49+
}
50+
51+
public void setQueryParams(final @Nullable KeyValueCollectionBehavior queryParams) {
52+
this.queryParams = queryParams;
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 @Nullable Boolean getQueues() {
77+
return queues;
78+
}
79+
80+
public void setQueues(final boolean queues) {
81+
this.queues = queues;
82+
}
83+
84+
public @NotNull HttpHeaders getHttpHeaders() {
85+
return httpHeaders;
86+
}
87+
88+
public @NotNull Graphql getGraphql() {
89+
return graphql;
90+
}
91+
92+
@ApiStatus.Internal
93+
boolean isExplicitlyConfigured() {
94+
return overridden
95+
|| userInfo != null
96+
|| cookies != null
97+
|| queryParams != null
98+
|| httpBodies != null
99+
|| databaseQueryData != null
100+
|| queues != null
101+
|| httpHeaders.hasOverrides()
102+
|| graphql.hasOverrides();
103+
}
104+
105+
/** Configures collection of request and response HTTP headers. */
106+
public static final class HttpHeaders {
107+
private @Nullable KeyValueCollectionBehavior request;
108+
private @Nullable KeyValueCollectionBehavior response;
109+
110+
public @Nullable KeyValueCollectionBehavior getRequest() {
111+
return request;
112+
}
113+
114+
public void setRequest(final @Nullable KeyValueCollectionBehavior request) {
115+
this.request = request;
116+
}
117+
118+
public @Nullable KeyValueCollectionBehavior getResponse() {
119+
return response;
120+
}
121+
122+
public void setResponse(final @Nullable KeyValueCollectionBehavior response) {
123+
this.response = response;
124+
}
125+
126+
private boolean hasOverrides() {
127+
return request != null || response != null;
128+
}
129+
}
130+
131+
/** Configures collection of GraphQL document and variable content. */
132+
public static final class Graphql {
133+
private @Nullable Boolean document;
134+
private @Nullable Boolean variables;
135+
136+
public @Nullable Boolean getDocument() {
137+
return document;
138+
}
139+
140+
public void setDocument(final boolean document) {
141+
this.document = document;
142+
}
143+
144+
public @Nullable Boolean getVariables() {
145+
return variables;
146+
}
147+
148+
public void setVariables(final boolean variables) {
149+
this.variables = variables;
150+
}
151+
152+
private boolean hasOverrides() {
153+
return document != null || variables != null;
154+
}
155+
}
156+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.sentry;
2+
3+
/** A direction of automatically collected HTTP body content. */
4+
public enum HttpBodyType {
5+
/** A request received by a server integration. */
6+
INCOMING_REQUEST,
7+
/** A request sent by a client integration. */
8+
OUTGOING_REQUEST,
9+
/** A response received by a client integration. */
10+
INCOMING_RESPONSE,
11+
/** A response sent by a server integration. */
12+
OUTGOING_RESPONSE
13+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package io.sentry;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.Collections;
6+
import java.util.List;
7+
import java.util.Objects;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
/** Controls how automatically collected key-value data is filtered. */
11+
public final class KeyValueCollectionBehavior {
12+
13+
/** The collection strategy applied to key-value data. */
14+
public enum Mode {
15+
/** Do not collect keys or values. */
16+
OFF,
17+
/** Collect keys and filter values whose keys match a deny-list term. */
18+
DENY_LIST,
19+
/** Collect keys and filter values unless their keys match an allow-list term. */
20+
ALLOW_LIST
21+
}
22+
23+
private final @NotNull Mode mode;
24+
private final @NotNull List<String> terms;
25+
26+
private KeyValueCollectionBehavior(final @NotNull Mode mode, final @NotNull List<String> terms) {
27+
this.mode = mode;
28+
this.terms = Collections.unmodifiableList(new ArrayList<>(terms));
29+
}
30+
31+
/** Disables collection of the category. */
32+
public static @NotNull KeyValueCollectionBehavior off() {
33+
return new KeyValueCollectionBehavior(Mode.OFF, Collections.<String>emptyList());
34+
}
35+
36+
/**
37+
* Collects the category and filters values whose keys match the built-in sensitive deny-list or
38+
* one of {@code terms}.
39+
*/
40+
public static @NotNull KeyValueCollectionBehavior denyList(final @NotNull String... terms) {
41+
return new KeyValueCollectionBehavior(Mode.DENY_LIST, Arrays.asList(terms));
42+
}
43+
44+
/**
45+
* Collects the category and only includes plaintext values whose keys match one of {@code terms}.
46+
* Values matching the built-in sensitive deny-list are still filtered.
47+
*/
48+
public static @NotNull KeyValueCollectionBehavior allowList(final @NotNull String... terms) {
49+
return new KeyValueCollectionBehavior(Mode.ALLOW_LIST, Arrays.asList(terms));
50+
}
51+
52+
public @NotNull Mode getMode() {
53+
return mode;
54+
}
55+
56+
public @NotNull List<String> getTerms() {
57+
return terms;
58+
}
59+
60+
@Override
61+
public boolean equals(final Object other) {
62+
if (this == other) {
63+
return true;
64+
}
65+
if (other == null || getClass() != other.getClass()) {
66+
return false;
67+
}
68+
final KeyValueCollectionBehavior that = (KeyValueCollectionBehavior) other;
69+
return mode == that.mode && terms.equals(that.terms);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
return Objects.hash(mode, terms);
75+
}
76+
}

0 commit comments

Comments
 (0)