-
-
Notifications
You must be signed in to change notification settings - Fork 473
feat(core): [Data Collection 1] Add configuration types #5760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
adinauer
wants to merge
3
commits into
feat/data-collection
Choose a base branch
from
feat/data-collection-foundation
base: feat/data-collection
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package io.sentry; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.EnumSet; | ||
| import java.util.Set; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** Configures data that the SDK collects automatically. */ | ||
| public final class DataCollection { | ||
|
|
||
| private boolean overridden; | ||
| private @Nullable Boolean userInfo; | ||
| private @Nullable KeyValueCollectionBehavior cookies; | ||
| private @Nullable KeyValueCollectionBehavior queryParams; | ||
| private @Nullable Set<HttpBodyType> httpBodies; | ||
| private @Nullable Boolean databaseQueryData; | ||
| private final @NotNull HttpHeaders httpHeaders = new HttpHeaders(); | ||
| private final @NotNull Graphql graphql = new Graphql(); | ||
|
|
||
| public DataCollection() { | ||
| this(true); | ||
| } | ||
|
|
||
| DataCollection(final boolean overridden) { | ||
| this.overridden = overridden; | ||
| } | ||
|
|
||
| public @Nullable Boolean getUserInfo() { | ||
| return userInfo; | ||
| } | ||
|
|
||
| public void setUserInfo(final boolean userInfo) { | ||
| this.userInfo = userInfo; | ||
| } | ||
|
|
||
| public @Nullable KeyValueCollectionBehavior getCookies() { | ||
| return cookies; | ||
| } | ||
|
|
||
| public void setCookies(final @Nullable KeyValueCollectionBehavior cookies) { | ||
| this.cookies = cookies; | ||
| } | ||
|
|
||
| public @Nullable KeyValueCollectionBehavior getQueryParams() { | ||
| return queryParams; | ||
| } | ||
|
|
||
| public void setQueryParams(final @Nullable KeyValueCollectionBehavior queryParams) { | ||
| this.queryParams = queryParams; | ||
| } | ||
|
|
||
| public @Nullable Set<HttpBodyType> getHttpBodies() { | ||
| return httpBodies; | ||
| } | ||
|
|
||
| public void setHttpBodies(final @Nullable Set<HttpBodyType> httpBodies) { | ||
| this.httpBodies = | ||
| httpBodies == null | ||
| ? null | ||
| : httpBodies.isEmpty() | ||
| ? Collections.<HttpBodyType>emptySet() | ||
| : Collections.unmodifiableSet(EnumSet.copyOf(httpBodies)); | ||
| } | ||
|
|
||
| public @Nullable Boolean getDatabaseQueryData() { | ||
| return databaseQueryData; | ||
| } | ||
|
|
||
| public void setDatabaseQueryData(final boolean databaseQueryData) { | ||
| this.databaseQueryData = databaseQueryData; | ||
| } | ||
|
|
||
| public @NotNull HttpHeaders getHttpHeaders() { | ||
| return httpHeaders; | ||
| } | ||
|
|
||
| public @NotNull Graphql getGraphql() { | ||
| return graphql; | ||
| } | ||
|
|
||
| @ApiStatus.Internal | ||
| boolean isExplicitlyConfigured() { | ||
| return overridden | ||
| || userInfo != null | ||
| || cookies != null | ||
| || queryParams != null | ||
| || httpBodies != null | ||
| || databaseQueryData != null | ||
| || httpHeaders.hasOverrides() | ||
| || graphql.hasOverrides(); | ||
| } | ||
|
|
||
| /** Configures collection of request and response HTTP headers. */ | ||
| public static final class HttpHeaders { | ||
| private @Nullable KeyValueCollectionBehavior request; | ||
| private @Nullable KeyValueCollectionBehavior response; | ||
|
|
||
| public @Nullable KeyValueCollectionBehavior getRequest() { | ||
| return request; | ||
| } | ||
|
|
||
| public void setRequest(final @Nullable KeyValueCollectionBehavior request) { | ||
| this.request = request; | ||
| } | ||
|
|
||
| public @Nullable KeyValueCollectionBehavior getResponse() { | ||
| return response; | ||
| } | ||
|
|
||
| public void setResponse(final @Nullable KeyValueCollectionBehavior response) { | ||
| this.response = response; | ||
| } | ||
|
|
||
| private boolean hasOverrides() { | ||
| return request != null || response != null; | ||
| } | ||
| } | ||
|
|
||
| /** Configures collection of GraphQL document and variable content. */ | ||
| public static final class Graphql { | ||
| private @Nullable Boolean document; | ||
| private @Nullable Boolean variables; | ||
|
|
||
| public @Nullable Boolean getDocument() { | ||
| return document; | ||
| } | ||
|
|
||
| public void setDocument(final boolean document) { | ||
| this.document = document; | ||
| } | ||
|
|
||
| public @Nullable Boolean getVariables() { | ||
| return variables; | ||
| } | ||
|
|
||
| public void setVariables(final boolean variables) { | ||
| this.variables = variables; | ||
| } | ||
|
|
||
| private boolean hasOverrides() { | ||
| return document != null || variables != null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.sentry; | ||
|
|
||
| /** A direction of automatically collected HTTP body content. */ | ||
| public enum HttpBodyType { | ||
| /** A request received by a server integration. */ | ||
| INCOMING_REQUEST, | ||
| /** A request sent by a client integration. */ | ||
| OUTGOING_REQUEST, | ||
| /** A response received by a client integration. */ | ||
| INCOMING_RESPONSE, | ||
| /** A response sent by a server integration. */ | ||
| OUTGOING_RESPONSE | ||
| } |
76 changes: 76 additions & 0 deletions
76
sentry/src/main/java/io/sentry/KeyValueCollectionBehavior.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package io.sentry; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** Controls how automatically collected key-value data is filtered. */ | ||
| public final class KeyValueCollectionBehavior { | ||
|
|
||
| /** The collection strategy applied to key-value data. */ | ||
| public enum Mode { | ||
| /** Do not collect keys or values. */ | ||
| OFF, | ||
| /** Collect keys and filter values whose keys match a deny-list term. */ | ||
| DENY_LIST, | ||
| /** Collect keys and filter values unless their keys match an allow-list term. */ | ||
| ALLOW_LIST | ||
| } | ||
|
|
||
| private final @NotNull Mode mode; | ||
| private final @NotNull List<String> terms; | ||
|
|
||
| private KeyValueCollectionBehavior(final @NotNull Mode mode, final @NotNull List<String> terms) { | ||
| this.mode = mode; | ||
| this.terms = Collections.unmodifiableList(new ArrayList<>(terms)); | ||
| } | ||
|
|
||
| /** Disables collection of the category. */ | ||
| public static @NotNull KeyValueCollectionBehavior off() { | ||
| return new KeyValueCollectionBehavior(Mode.OFF, Collections.<String>emptyList()); | ||
| } | ||
|
|
||
| /** | ||
| * Collects the category and filters values whose keys match the built-in sensitive deny-list or | ||
| * one of {@code terms}. | ||
| */ | ||
| public static @NotNull KeyValueCollectionBehavior denyList(final @NotNull String... terms) { | ||
| return new KeyValueCollectionBehavior(Mode.DENY_LIST, Arrays.asList(terms)); | ||
| } | ||
|
|
||
| /** | ||
| * Collects the category and only includes plaintext values whose keys match one of {@code terms}. | ||
| * Values matching the built-in sensitive deny-list are still filtered. | ||
| */ | ||
| public static @NotNull KeyValueCollectionBehavior allowList(final @NotNull String... terms) { | ||
| return new KeyValueCollectionBehavior(Mode.ALLOW_LIST, Arrays.asList(terms)); | ||
| } | ||
|
|
||
| public @NotNull Mode getMode() { | ||
| return mode; | ||
| } | ||
|
|
||
| public @NotNull List<String> getTerms() { | ||
| return terms; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object other) { | ||
| if (this == other) { | ||
| return true; | ||
| } | ||
| if (other == null || getClass() != other.getClass()) { | ||
| return false; | ||
| } | ||
| final KeyValueCollectionBehavior that = (KeyValueCollectionBehavior) other; | ||
| return mode == that.mode && terms.equals(that.terms); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(mode, terms); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec calls this
urlQueryParams, is this difference intentional, or already fixed in a later pr?