Class: Sentry::DataCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/data_collection.rb,
lib/sentry/data_collection/key_value_collection.rb

Defined Under Namespace

Classes: GraphQL, HttpHeaders, KeyValueCollection

Constant Summary collapse

MODES =

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/

Examples:

Configure data collection

Sentry.init do |config|
  data_collection = config.data_collection
  data_collection. = 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
%i[off deny_list allow_list].freeze
PII_HEADER_SNIPPETS =
%w[forwarded -ip _ip remote via _user -user].freeze
BODY_TYPES =
%i[
  incoming_request
  outgoing_request
  incoming_response
  outgoing_response
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDataCollection

Returns a new instance of DataCollection.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/sentry/data_collection.rb', line 153

def initialize
  @user_info = true
  self.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 = BODY_TYPES.dup
  self.url_query_params = KeyValueCollection.new(mode: :deny_list, terms: nil)
  @database_query_data = true
  @graphql = GraphQL.new(document: true, variables: true)
  @queues = true
  self.stack_frame_variables = false
  @frame_context_lines = 3
end

Instance Attribute Details

#cookiesBoolean, KeyValueCollection

A boolean is shorthand for mode: :deny_list (true) or mode: :off (false).

Returns:



84
85
86
# File 'lib/sentry/data_collection.rb', line 84

def cookies
  @cookies
end

#database_query_dataBoolean

Returns:



101
102
103
# File 'lib/sentry/data_collection.rb', line 101

def database_query_data
  @database_query_data
end

#frame_context_linesInteger

Returns:



118
119
120
# File 'lib/sentry/data_collection.rb', line 118

def frame_context_lines
  @frame_context_lines
end

#graphqlGraphQL

Returns:



105
106
107
# File 'lib/sentry/data_collection.rb', line 105

def graphql
  @graphql
end

#http_bodiesArray<Symbol>

Returns containing values from BODY_TYPES.

Returns:

  • containing values from BODY_TYPES



92
93
94
# File 'lib/sentry/data_collection.rb', line 92

def http_bodies
  @http_bodies
end

#http_headersHttpHeaders

Returns:



88
89
90
# File 'lib/sentry/data_collection.rb', line 88

def http_headers
  @http_headers
end

#queuesBoolean

Returns:



109
110
111
# File 'lib/sentry/data_collection.rb', line 109

def queues
  @queues
end

#stack_frame_variablesBoolean, KeyValueCollection

A boolean is shorthand for mode: :deny_list (true) or mode: :off (false).

Returns:



114
115
116
# File 'lib/sentry/data_collection.rb', line 114

def stack_frame_variables
  @stack_frame_variables
end

#url_query_paramsBoolean, KeyValueCollection

A boolean is shorthand for mode: :deny_list (true) or mode: :off (false).

Returns:



97
98
99
# File 'lib/sentry/data_collection.rb', line 97

def url_query_params
  @url_query_params
end

#user_infoBoolean

Returns:



79
80
81
# File 'lib/sentry/data_collection.rb', line 79

def 
  @user_info
end

Class Method Details

.backfill(configuration) ⇒ Object

Builds data collection settings compatible with the legacy send_default_pii configuration.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/sentry/data_collection.rb', line 131

def self.backfill(configuration)
  data_collection = new
  data_collection.backfill_stack_frame_variables(configuration)
  return data_collection if configuration.send_default_pii

  # TODO-neel-data map to exact ruby behaviour for backwards compat behavior
  data_collection. = false
  data_collection.cookies.mode = :off
  data_collection.http_headers.request.mode = :deny_list
  data_collection.http_headers.request.terms = PII_HEADER_SNIPPETS
  data_collection.http_headers.response.mode = :deny_list
  data_collection.http_headers.response.terms = PII_HEADER_SNIPPETS
  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.frame_context_lines = configuration.context_lines
  data_collection
end

.default_filterObject



125
126
127
# File 'lib/sentry/data_collection.rb', line 125

def self.default_filter
  @default_filter ||= KeyValueCollection.new(mode: :deny_list, terms: nil)
end

.filter(values) ⇒ Object

Filters key-value data using the default sensitive denylist.



121
122
123
# File 'lib/sentry/data_collection.rb', line 121

def self.filter(values)
  default_filter.filter(values, cookie: false)
end

Instance Method Details

#backfill_stack_frame_variables(configuration) ⇒ Object

Copies the legacy stack frame variable configuration.



170
171
172
# File 'lib/sentry/data_collection.rb', line 170

def backfill_stack_frame_variables(configuration)
  self.stack_frame_variables = configuration.include_local_variables
end

#collect_incoming_http_body?Boolean

Returns whether incoming HTTP request bodies should be collected. nil implies all BODY_TYPES according to spec

Returns:



193
194
195
# File 'lib/sentry/data_collection.rb', line 193

def collect_incoming_http_body?
  http_bodies.nil? || http_bodies.include?(:incoming_request)
end

#collect_outgoing_http_body?Boolean

Returns whether outgoing HTTP request bodies should be collected. nil implies all BODY_TYPES according to spec

Returns:



199
200
201
# File 'lib/sentry/data_collection.rb', line 199

def collect_outgoing_http_body?
  http_bodies.nil? || http_bodies.include?(:outgoing_request)
end

#collect_stack_frame_variables?Boolean

Returns whether stack frame local variables should be captured.

Returns:



175
176
177
# File 'lib/sentry/data_collection.rb', line 175

def collect_stack_frame_variables?
  stack_frame_variables.mode != :off
end