Skip to content

Commit a78374a

Browse files
adinauerclaude
andauthored
feat(core): [Data Collection 1] Add configuration types (#5760)
* 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> * test(core): Remove Data Collection identity assertion Avoid coupling the Data Collection configuration test to reference identity. The test only needs to verify that setting a nested header behavior marks the configuration explicit. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com> * ref(core): Remove unused queue collection option Remove the queue option from the initial Data Collection API because the Java SDK does not collect queue payload data that it could control. Co-Authored-By: Claude <noreply@anthropic.com> * ref(core): Rename URL query parameter option Align the public Java API with the canonical Data Collection specification before release. The option has not shipped, so replace the old name without a compatibility alias. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com> * ref(core): Clarify forced Data Collection configuration Rename the internal override marker to explain that it forces an empty Data Collection object into explicit mode. Align the related tests with the clarified semantics. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
2 parents dd4bdfc + 8afc27f commit a78374a

6 files changed

Lines changed: 447 additions & 0 deletions

File tree

‎sentry/api/sentry.api‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,38 @@ 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 getUrlQueryParams ()Lio/sentry/KeyValueCollectionBehavior;
394+
public fun getUserInfo ()Ljava/lang/Boolean;
395+
public fun setCookies (Lio/sentry/KeyValueCollectionBehavior;)V
396+
public fun setDatabaseQueryData (Z)V
397+
public fun setHttpBodies (Ljava/util/Set;)V
398+
public fun setUrlQueryParams (Lio/sentry/KeyValueCollectionBehavior;)V
399+
public fun setUserInfo (Z)V
400+
}
401+
402+
public final class io/sentry/DataCollection$Graphql {
403+
public fun <init> ()V
404+
public fun getDocument ()Ljava/lang/Boolean;
405+
public fun getVariables ()Ljava/lang/Boolean;
406+
public fun setDocument (Z)V
407+
public fun setVariables (Z)V
408+
}
409+
410+
public final class io/sentry/DataCollection$HttpHeaders {
411+
public fun <init> ()V
412+
public fun getRequest ()Lio/sentry/KeyValueCollectionBehavior;
413+
public fun getResponse ()Lio/sentry/KeyValueCollectionBehavior;
414+
public fun setRequest (Lio/sentry/KeyValueCollectionBehavior;)V
415+
public fun setResponse (Lio/sentry/KeyValueCollectionBehavior;)V
416+
}
417+
386418
public final class io/sentry/DateUtils {
387419
public static fun dateToSeconds (Ljava/util/Date;)D
388420
public static fun doubleToBigDecimal (D)Ljava/math/BigDecimal;
@@ -635,6 +667,15 @@ public final class io/sentry/HostnameCache {
635667
public static fun getInstance ()Lio/sentry/HostnameCache;
636668
}
637669

670+
public final class io/sentry/HttpBodyType : java/lang/Enum {
671+
public static final field INCOMING_REQUEST Lio/sentry/HttpBodyType;
672+
public static final field INCOMING_RESPONSE Lio/sentry/HttpBodyType;
673+
public static final field OUTGOING_REQUEST Lio/sentry/HttpBodyType;
674+
public static final field OUTGOING_RESPONSE Lio/sentry/HttpBodyType;
675+
public static fun valueOf (Ljava/lang/String;)Lio/sentry/HttpBodyType;
676+
public static fun values ()[Lio/sentry/HttpBodyType;
677+
}
678+
638679
public final class io/sentry/HttpStatusCodeRange {
639680
public static final field DEFAULT_MAX I
640681
public static final field DEFAULT_MIN I
@@ -1381,6 +1422,24 @@ public abstract interface class io/sentry/JsonUnknown {
13811422
public abstract fun setUnknown (Ljava/util/Map;)V
13821423
}
13831424

1425+
public final class io/sentry/KeyValueCollectionBehavior {
1426+
public static fun allowList ([Ljava/lang/String;)Lio/sentry/KeyValueCollectionBehavior;
1427+
public static fun denyList ([Ljava/lang/String;)Lio/sentry/KeyValueCollectionBehavior;
1428+
public fun equals (Ljava/lang/Object;)Z
1429+
public fun getMode ()Lio/sentry/KeyValueCollectionBehavior$Mode;
1430+
public fun getTerms ()Ljava/util/List;
1431+
public fun hashCode ()I
1432+
public static fun off ()Lio/sentry/KeyValueCollectionBehavior;
1433+
}
1434+
1435+
public final class io/sentry/KeyValueCollectionBehavior$Mode : java/lang/Enum {
1436+
public static final field ALLOW_LIST Lio/sentry/KeyValueCollectionBehavior$Mode;
1437+
public static final field DENY_LIST Lio/sentry/KeyValueCollectionBehavior$Mode;
1438+
public static final field OFF Lio/sentry/KeyValueCollectionBehavior$Mode;
1439+
public static fun valueOf (Ljava/lang/String;)Lio/sentry/KeyValueCollectionBehavior$Mode;
1440+
public static fun values ()[Lio/sentry/KeyValueCollectionBehavior$Mode;
1441+
}
1442+
13841443
public final class io/sentry/MainEventProcessor : io/sentry/EventProcessor, java/io/Closeable {
13851444
public fun <init> (Lio/sentry/SentryOptions;)V
13861445
public fun close ()V
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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+
}
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)