-
-
Notifications
You must be signed in to change notification settings - Fork 540
feat(data-collection): Add base DataCollection configuration with defaults and backfill #3022
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
Open
+319
−1
Open
Changes from all commits
Commits
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,161 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Sentry | ||
| class DataCollection | ||
| # Configuration for the categories of data collected by the SDK. | ||
| # Replacement for send_default_pii. | ||
| # Spec: https://develop.sentry.dev/sdk/foundations/client/data-collection/ | ||
| # | ||
| # @example Configure data collection | ||
| # Sentry.init do |config| | ||
| # data_collection = config.data_collection | ||
| # data_collection.user_info = true | ||
| # data_collection.cookies.mode = :deny_list | ||
| # data_collection.cookies.terms = ["session", "token"] | ||
| # data_collection.http_headers.request.mode = :deny_list | ||
| # data_collection.http_headers.request.terms = nil | ||
| # data_collection.http_headers.response.mode = :allow_list | ||
| # data_collection.http_headers.response.terms = ["my_special_header"] | ||
| # data_collection.http_bodies = [:incoming_request] | ||
| # data_collection.url_query_params.mode = :allow_list | ||
| # data_collection.url_query_params.terms = ["page", "limit"] | ||
| # data_collection.graphql.document = true | ||
| # data_collection.graphql.variables = true | ||
| # data_collection.database_query_data = true | ||
| # data_collection.queues = true | ||
| # data_collection.stack_frame_variables = true | ||
| # data_collection.frame_context_lines = 5 | ||
| # end | ||
| MODES = %i[off deny_list allow_list].freeze | ||
| BODY_TYPES = %i[ | ||
| incoming_request | ||
| outgoing_request | ||
| incoming_response | ||
| outgoing_response | ||
| ].freeze | ||
|
|
||
| # Configuration for key-value data collection. | ||
| class KeyValueCollection | ||
| # `mode` controls whether values are collected: | ||
| # - `:off` disables collection. | ||
| # - `:deny_list` collects values except those matching `terms`. | ||
| # - `:allow_list` collects only values matching `terms`. | ||
| # @return [:off, :deny_list, :allow_list] | ||
| attr_accessor :mode | ||
|
|
||
| # `terms` contains the keys or patterns used by the selected mode. | ||
| # @return [Array<String>, nil] | ||
| attr_accessor :terms | ||
|
|
||
| def initialize(mode:, terms:) | ||
| @mode = mode | ||
| @terms = terms | ||
| end | ||
| end | ||
|
|
||
| class HttpHeaders | ||
| # @return [KeyValueCollection] | ||
| attr_accessor :request | ||
|
|
||
| # @return [KeyValueCollection] | ||
| attr_accessor :response | ||
|
|
||
| def initialize(request:, response:) | ||
| @request = request | ||
| @response = response | ||
| end | ||
| end | ||
|
|
||
| class GraphQL | ||
| # @return [Boolean] | ||
| attr_accessor :document | ||
|
|
||
| # @return [Boolean] | ||
| attr_accessor :variables | ||
|
|
||
| def initialize(document:, variables:) | ||
| @document = document | ||
| @variables = variables | ||
| end | ||
| end | ||
|
|
||
| # @return [Boolean] | ||
| # @default `true` | ||
| attr_accessor :user_info | ||
|
|
||
| # @return [KeyValueCollection] | ||
| # @default `mode: :deny_list, terms: nil` | ||
| attr_accessor :cookies | ||
|
|
||
| # @return [HttpHeaders] | ||
| # @default request and response use `mode: :deny_list, terms: nil` | ||
| attr_accessor :http_headers | ||
|
|
||
| # @return [Array<Symbol>] containing values from BODY_TYPES | ||
| # @default `nil` (all valid body types) | ||
| attr_accessor :http_bodies | ||
|
|
||
| # @return [KeyValueCollection] | ||
| # @default `mode: :deny_list, terms: nil` | ||
| attr_accessor :url_query_params | ||
|
|
||
| # @return [Boolean] | ||
| # @default `true` | ||
| attr_accessor :database_query_data | ||
|
|
||
| # @return [GraphQL] | ||
| # @default `document: true, variables: true` | ||
| attr_accessor :graphql | ||
|
|
||
| # @return [Boolean] | ||
| # @default `true` | ||
| attr_accessor :queues | ||
|
|
||
| # @return [Boolean] | ||
| # @default `false` | ||
| attr_accessor :stack_frame_variables | ||
|
|
||
| # @return [Integer] | ||
| # @default `3` | ||
| attr_accessor :frame_context_lines | ||
|
|
||
| # Builds data collection settings compatible with the legacy send_default_pii | ||
| # configuration. | ||
| def self.backfill(configuration) | ||
| # the new DataCollection defaults are already correct if pii is enabled | ||
| data_collection = new | ||
| return data_collection if configuration.send_default_pii | ||
|
|
||
| # TODO-neel-data map to exact ruby behaviour for backwards compat behavior | ||
| data_collection.user_info = false | ||
| data_collection.cookies.mode = :off | ||
| data_collection.http_headers.request.mode = :off | ||
| data_collection.http_headers.response.mode = :off | ||
| data_collection.http_bodies = [] | ||
| data_collection.url_query_params.mode = :off | ||
| data_collection.graphql.document = false | ||
| data_collection.graphql.variables = false | ||
| data_collection.database_query_data = false | ||
| data_collection.queues = false | ||
| data_collection.stack_frame_variables = configuration.include_local_variables | ||
| data_collection.frame_context_lines = configuration.context_lines | ||
| data_collection | ||
| end | ||
|
sl0thentr0py marked this conversation as resolved.
|
||
|
|
||
| def initialize | ||
| @user_info = true | ||
| @cookies = KeyValueCollection.new(mode: :deny_list, terms: nil) | ||
| @http_headers = HttpHeaders.new( | ||
| request: KeyValueCollection.new(mode: :deny_list, terms: nil), | ||
| response: KeyValueCollection.new(mode: :deny_list, terms: nil) | ||
| ) | ||
| @http_bodies = nil | ||
| @url_query_params = KeyValueCollection.new(mode: :deny_list, terms: nil) | ||
| @database_query_data = true | ||
| @graphql = GraphQL.new(document: true, variables: true) | ||
| @queues = true | ||
| @stack_frame_variables = false | ||
| @frame_context_lines = 3 | ||
| end | ||
| end | ||
| end | ||
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,92 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Sentry::DataCollection do | ||
| subject(:data_collection) { described_class.new } | ||
|
|
||
| describe ".backfill" do | ||
| it "uses the send_default_pii=false defaults" do | ||
| configuration = Sentry::Configuration.new | ||
| data_collection = described_class.backfill(configuration) | ||
|
|
||
| expect(data_collection.user_info).to eq(false) | ||
| expect(data_collection.cookies.mode).to eq(:off) | ||
| expect(data_collection.http_headers.request.mode).to eq(:off) | ||
| expect(data_collection.http_headers.response.mode).to eq(:off) | ||
| expect(data_collection.http_bodies).to eq([]) | ||
| expect(data_collection.url_query_params.mode).to eq(:off) | ||
| expect(data_collection.database_query_data).to eq(false) | ||
| expect(data_collection.graphql.document).to eq(false) | ||
| expect(data_collection.graphql.variables).to eq(false) | ||
| expect(data_collection.queues).to eq(false) | ||
| expect(data_collection.stack_frame_variables).to eq(false) | ||
| expect(data_collection.frame_context_lines).to eq(3) | ||
| end | ||
|
|
||
| it "uses the send_default_pii=true defaults when enabled later" do | ||
| configuration = Sentry::Configuration.new | ||
| configuration.send_default_pii = true | ||
|
|
||
| expect(configuration.data_collection.user_info).to eq(true) | ||
| expect(configuration.data_collection.cookies.mode).to eq(:deny_list) | ||
| end | ||
| end | ||
|
|
||
| describe "defaults" do | ||
| it "uses the defaults from the Data Collection specification" do | ||
| expect(data_collection.user_info).to eq(true) | ||
| expect(data_collection.cookies.mode).to eq(:deny_list) | ||
| expect(data_collection.cookies.terms).to be_nil | ||
| expect(data_collection.http_headers.request.mode).to eq(:deny_list) | ||
| expect(data_collection.http_headers.request.terms).to be_nil | ||
| expect(data_collection.http_headers.response.mode).to eq(:deny_list) | ||
| expect(data_collection.http_headers.response.terms).to be_nil | ||
| expect(data_collection.http_bodies).to be_nil | ||
| expect(data_collection.url_query_params.mode).to eq(:deny_list) | ||
| expect(data_collection.url_query_params.terms).to be_nil | ||
| expect(data_collection.database_query_data).to eq(true) | ||
| expect(data_collection.graphql.document).to eq(true) | ||
| expect(data_collection.graphql.variables).to eq(true) | ||
| expect(data_collection.queues).to eq(true) | ||
| expect(data_collection.stack_frame_variables).to eq(false) | ||
| expect(data_collection.frame_context_lines).to eq(3) | ||
| end | ||
| end | ||
|
|
||
| describe "constants" do | ||
| it "defines the supported modes" do | ||
| expect(described_class::MODES).to eq(%i[off deny_list allow_list]) | ||
| end | ||
|
|
||
| it "defines the supported body types" do | ||
| expect(described_class::BODY_TYPES).to eq( | ||
| %i[incoming_request outgoing_request incoming_response outgoing_response] | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| describe "nested configuration objects" do | ||
| it "supports configuring key-value collection modes and terms" do | ||
| data_collection.cookies.mode = :allow_list | ||
| data_collection.cookies.terms = ["page"] | ||
|
|
||
| expect(data_collection.cookies.mode).to eq(:allow_list) | ||
| expect(data_collection.cookies.terms).to eq(["page"]) | ||
| end | ||
|
|
||
| it "supports configuring request and response headers independently" do | ||
| data_collection.http_headers.request.mode = :off | ||
| data_collection.http_headers.response.terms = ["x-request-id"] | ||
|
|
||
| expect(data_collection.http_headers.request.mode).to eq(:off) | ||
| expect(data_collection.http_headers.response.terms).to eq(["x-request-id"]) | ||
| end | ||
|
|
||
| it "supports configuring GraphQL fields independently" do | ||
| data_collection.graphql.document = false | ||
| data_collection.graphql.variables = false | ||
|
|
||
| expect(data_collection.graphql.document).to eq(false) | ||
| expect(data_collection.graphql.variables).to eq(false) | ||
| end | ||
| end | ||
| end |
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.
Uh oh!
There was an error while loading. Please reload this page.