sentry-ruby 4.1.3 → 4.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. metadata +21 -56
  4. data/.craft.yml +0 -19
  5. data/.gitignore +0 -11
  6. data/.rspec +0 -3
  7. data/.travis.yml +0 -6
  8. data/CHANGELOG.md +0 -113
  9. data/CODE_OF_CONDUCT.md +0 -74
  10. data/Gemfile +0 -16
  11. data/Rakefile +0 -8
  12. data/bin/console +0 -14
  13. data/bin/setup +0 -8
  14. data/lib/sentry-ruby.rb +0 -145
  15. data/lib/sentry/background_worker.rb +0 -37
  16. data/lib/sentry/backtrace.rb +0 -126
  17. data/lib/sentry/benchmarks/benchmark_transport.rb +0 -14
  18. data/lib/sentry/breadcrumb.rb +0 -25
  19. data/lib/sentry/breadcrumb/sentry_logger.rb +0 -87
  20. data/lib/sentry/breadcrumb_buffer.rb +0 -47
  21. data/lib/sentry/client.rb +0 -96
  22. data/lib/sentry/configuration.rb +0 -396
  23. data/lib/sentry/core_ext/object/deep_dup.rb +0 -57
  24. data/lib/sentry/core_ext/object/duplicable.rb +0 -153
  25. data/lib/sentry/dsn.rb +0 -48
  26. data/lib/sentry/event.rb +0 -171
  27. data/lib/sentry/hub.rb +0 -137
  28. data/lib/sentry/integrable.rb +0 -24
  29. data/lib/sentry/interface.rb +0 -22
  30. data/lib/sentry/interfaces/exception.rb +0 -11
  31. data/lib/sentry/interfaces/request.rb +0 -114
  32. data/lib/sentry/interfaces/single_exception.rb +0 -14
  33. data/lib/sentry/interfaces/stacktrace.rb +0 -90
  34. data/lib/sentry/linecache.rb +0 -44
  35. data/lib/sentry/logger.rb +0 -20
  36. data/lib/sentry/rack.rb +0 -4
  37. data/lib/sentry/rack/capture_exceptions.rb +0 -62
  38. data/lib/sentry/rack/deprecations.rb +0 -19
  39. data/lib/sentry/rake.rb +0 -17
  40. data/lib/sentry/scope.rb +0 -214
  41. data/lib/sentry/span.rb +0 -132
  42. data/lib/sentry/transaction.rb +0 -157
  43. data/lib/sentry/transaction_event.rb +0 -29
  44. data/lib/sentry/transport.rb +0 -88
  45. data/lib/sentry/transport/configuration.rb +0 -21
  46. data/lib/sentry/transport/dummy_transport.rb +0 -14
  47. data/lib/sentry/transport/http_transport.rb +0 -62
  48. data/lib/sentry/utils/exception_cause_chain.rb +0 -20
  49. data/lib/sentry/utils/real_ip.rb +0 -70
  50. data/lib/sentry/utils/request_id.rb +0 -16
  51. data/lib/sentry/version.rb +0 -3
  52. data/sentry-ruby.gemspec +0 -27
data/lib/sentry/scope.rb DELETED
@@ -1,214 +0,0 @@
1
- require "sentry/breadcrumb_buffer"
2
- require "etc"
3
-
4
- module Sentry
5
- class Scope
6
- ATTRIBUTES = [:transaction_names, :contexts, :extra, :tags, :user, :level, :breadcrumbs, :fingerprint, :event_processors, :rack_env, :span]
7
-
8
- attr_reader(*ATTRIBUTES)
9
-
10
- def initialize
11
- set_default_value
12
- end
13
-
14
- def clear
15
- set_default_value
16
- end
17
-
18
- def apply_to_event(event, hint = nil)
19
- event.tags = tags.merge(event.tags)
20
- event.user = user.merge(event.user)
21
- event.extra = extra.merge(event.extra)
22
- event.contexts = contexts.merge(event.contexts)
23
-
24
- if span
25
- event.contexts[:trace] = span.get_trace_context
26
- end
27
-
28
- event.fingerprint = fingerprint
29
- event.level = level
30
- event.transaction = transaction_names.last
31
- event.breadcrumbs = breadcrumbs
32
- event.rack_env = rack_env if rack_env
33
-
34
- unless @event_processors.empty?
35
- @event_processors.each do |processor_block|
36
- event = processor_block.call(event, hint)
37
- end
38
- end
39
-
40
- event
41
- end
42
-
43
- def add_breadcrumb(breadcrumb)
44
- breadcrumbs.record(breadcrumb)
45
- end
46
-
47
- def clear_breadcrumbs
48
- @breadcrumbs = BreadcrumbBuffer.new
49
- end
50
-
51
- def dup
52
- copy = super
53
- copy.breadcrumbs = breadcrumbs.dup
54
- copy.contexts = contexts.deep_dup
55
- copy.extra = extra.deep_dup
56
- copy.tags = tags.deep_dup
57
- copy.user = user.deep_dup
58
- copy.transaction_names = transaction_names.deep_dup
59
- copy.fingerprint = fingerprint.deep_dup
60
- copy.span = span.deep_dup
61
- copy
62
- end
63
-
64
- def update_from_scope(scope)
65
- self.breadcrumbs = scope.breadcrumbs
66
- self.contexts = scope.contexts
67
- self.extra = scope.extra
68
- self.tags = scope.tags
69
- self.user = scope.user
70
- self.transaction_names = scope.transaction_names
71
- self.fingerprint = scope.fingerprint
72
- self.span = scope.span
73
- end
74
-
75
- def update_from_options(
76
- contexts: nil,
77
- extra: nil,
78
- tags: nil,
79
- user: nil,
80
- level: nil,
81
- fingerprint: nil
82
- )
83
- self.contexts.merge!(contexts) if contexts
84
- self.extra.merge!(extra) if extra
85
- self.tags.merge!(tags) if tags
86
- self.user = user if user
87
- self.level = level if level
88
- self.fingerprint = fingerprint if fingerprint
89
- end
90
-
91
- def set_rack_env(env)
92
- env = env || {}
93
- @rack_env = env
94
- end
95
-
96
- def set_span(span)
97
- check_argument_type!(span, Span)
98
- @span = span
99
- end
100
-
101
- def set_user(user_hash)
102
- check_argument_type!(user_hash, Hash)
103
- @user = user_hash
104
- end
105
-
106
- def set_extras(extras_hash)
107
- check_argument_type!(extras_hash, Hash)
108
- @extra.merge!(extras_hash)
109
- end
110
-
111
- def set_extra(key, value)
112
- @extra.merge!(key => value)
113
- end
114
-
115
- def set_tags(tags_hash)
116
- check_argument_type!(tags_hash, Hash)
117
- @tags.merge!(tags_hash)
118
- end
119
-
120
- def set_tag(key, value)
121
- @tags.merge!(key => value)
122
- end
123
-
124
- def set_contexts(contexts_hash)
125
- check_argument_type!(contexts_hash, Hash)
126
- @contexts = contexts_hash
127
- end
128
-
129
- def set_context(key, value)
130
- @contexts.merge!(key => value)
131
- end
132
-
133
- def set_level(level)
134
- @level = level
135
- end
136
-
137
- def set_transaction_name(transaction_name)
138
- @transaction_names << transaction_name
139
- end
140
-
141
- def transaction_name
142
- @transaction_names.last
143
- end
144
-
145
- def get_transaction
146
- # transaction will always be the first in the span_recorder
147
- span.span_recorder.spans.first if span
148
- end
149
-
150
- def get_span
151
- span
152
- end
153
-
154
- def set_fingerprint(fingerprint)
155
- check_argument_type!(fingerprint, Array)
156
-
157
- @fingerprint = fingerprint
158
- end
159
-
160
- def add_event_processor(&block)
161
- @event_processors << block
162
- end
163
-
164
- protected
165
-
166
- # for duplicating scopes internally
167
- attr_writer(*ATTRIBUTES)
168
-
169
- private
170
-
171
- def check_argument_type!(argument, expected_type)
172
- unless argument.is_a?(expected_type)
173
- raise ArgumentError, "expect the argument to be a #{expected_type}, got #{argument.class} (#{argument})"
174
- end
175
- end
176
-
177
- def set_default_value
178
- @breadcrumbs = BreadcrumbBuffer.new
179
- @contexts = { :os => self.class.os_context, :runtime => self.class.runtime_context }
180
- @extra = {}
181
- @tags = {}
182
- @user = {}
183
- @level = :error
184
- @fingerprint = []
185
- @transaction_names = []
186
- @event_processors = []
187
- @rack_env = {}
188
- @span = nil
189
- end
190
-
191
- class << self
192
- def os_context
193
- @os_context ||=
194
- begin
195
- uname = Etc.uname
196
- {
197
- name: uname[:sysname] || RbConfig::CONFIG["host_os"],
198
- version: uname[:version],
199
- build: uname[:release],
200
- kernel_version: uname[:version]
201
- }
202
- end
203
- end
204
-
205
- def runtime_context
206
- @runtime_context ||= {
207
- name: RbConfig::CONFIG["ruby_install_name"],
208
- version: RUBY_DESCRIPTION || Sentry.sys_command("ruby -v")
209
- }
210
- end
211
- end
212
-
213
- end
214
- end
data/lib/sentry/span.rb DELETED
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
- require "securerandom"
3
-
4
- module Sentry
5
- class Span
6
- STATUS_MAP = {
7
- 400 => "invalid_argument",
8
- 401 => "unauthenticated",
9
- 403 => "permission_denied",
10
- 404 => "not_found",
11
- 409 => "already_exists",
12
- 429 => "resource_exhausted",
13
- 499 => "cancelled",
14
- 500 => "internal_error",
15
- 501 => "unimplemented",
16
- 503 => "unavailable",
17
- 504 => "deadline_exceeded"
18
- }
19
-
20
-
21
- attr_reader :trace_id, :span_id, :parent_span_id, :sampled, :start_timestamp, :timestamp, :description, :op, :status, :tags, :data
22
- attr_accessor :span_recorder
23
-
24
- def initialize(description: nil, op: nil, status: nil, trace_id: nil, parent_span_id: nil, sampled: nil, start_timestamp: nil, timestamp: nil)
25
- @trace_id = trace_id || SecureRandom.uuid.delete("-")
26
- @span_id = SecureRandom.hex(8)
27
- @parent_span_id = parent_span_id
28
- @sampled = sampled
29
- @start_timestamp = start_timestamp || Sentry.utc_now.to_f
30
- @timestamp = timestamp
31
- @description = description
32
- @op = op
33
- @status = status
34
- @data = {}
35
- @tags = {}
36
- end
37
-
38
- def finish
39
- # already finished
40
- return if @timestamp
41
-
42
- @timestamp = Sentry.utc_now.to_f
43
- self
44
- end
45
-
46
- def to_sentry_trace
47
- sampled_flag = ""
48
- sampled_flag = @sampled ? 1 : 0 unless @sampled.nil?
49
-
50
- "#{@trace_id}-#{@span_id}-#{sampled_flag}"
51
- end
52
-
53
- def to_hash
54
- {
55
- trace_id: @trace_id,
56
- span_id: @span_id,
57
- parent_span_id: @parent_span_id,
58
- start_timestamp: @start_timestamp,
59
- timestamp: @timestamp,
60
- description: @description,
61
- op: @op,
62
- status: @status,
63
- tags: @tags,
64
- data: @data
65
- }
66
- end
67
-
68
- def get_trace_context
69
- {
70
- trace_id: @trace_id,
71
- span_id: @span_id,
72
- description: @description,
73
- op: @op,
74
- status: @status
75
- }
76
- end
77
-
78
- def start_child(**options)
79
- options = options.dup.merge(trace_id: @trace_id, parent_span_id: @span_id, sampled: @sampled)
80
- Span.new(**options)
81
- end
82
-
83
- def with_child_span(**options, &block)
84
- child_span = start_child(**options)
85
-
86
- yield(child_span)
87
-
88
- child_span.finish
89
- end
90
-
91
- def deep_dup
92
- dup
93
- end
94
-
95
- def set_op(op)
96
- @op = op
97
- end
98
-
99
- def set_description(description)
100
- @description = description
101
- end
102
-
103
- def set_status(status)
104
- @status = status
105
- end
106
-
107
- def set_timestamp(timestamp)
108
- @timestamp = timestamp
109
- end
110
-
111
- def set_http_status(status_code)
112
- status_code = status_code.to_i
113
- set_data("status_code", status_code)
114
-
115
- status =
116
- if status_code >= 200 && status_code < 299
117
- "ok"
118
- else
119
- STATUS_MAP[status_code]
120
- end
121
- set_status(status)
122
- end
123
-
124
- def set_data(key, value)
125
- @data[key] = value
126
- end
127
-
128
- def set_tag(key, value)
129
- @tags[key] = value
130
- end
131
- end
132
- end
@@ -1,157 +0,0 @@
1
- module Sentry
2
- class Transaction < Span
3
- SENTRY_TRACE_REGEXP = Regexp.new(
4
- "^[ \t]*" + # whitespace
5
- "([0-9a-f]{32})?" + # trace_id
6
- "-?([0-9a-f]{16})?" + # span_id
7
- "-?([01])?" + # sampled
8
- "[ \t]*$" # whitespace
9
- )
10
- UNLABELD_NAME = "<unlabeled transaction>".freeze
11
- MESSAGE_PREFIX = "[Tracing]"
12
-
13
- attr_reader :name, :parent_sampled
14
-
15
- def initialize(name: nil, parent_sampled: nil, **options)
16
- super(**options)
17
-
18
- @name = name
19
- @parent_sampled = parent_sampled
20
- set_span_recorder
21
- end
22
-
23
- def set_span_recorder
24
- @span_recorder = SpanRecorder.new(1000)
25
- @span_recorder.add(self)
26
- end
27
-
28
- def self.from_sentry_trace(sentry_trace, **options)
29
- return unless sentry_trace
30
-
31
- match = SENTRY_TRACE_REGEXP.match(sentry_trace)
32
- trace_id, parent_span_id, sampled_flag = match[1..3]
33
-
34
- sampled = sampled_flag != "0"
35
-
36
- new(trace_id: trace_id, parent_span_id: parent_span_id, parent_sampled: sampled, **options)
37
- end
38
-
39
- def to_hash
40
- hash = super
41
- hash.merge!(name: @name, sampled: @sampled, parent_sampled: @parent_sampled)
42
- hash
43
- end
44
-
45
- def start_child(**options)
46
- child_span = super
47
- child_span.span_recorder = @span_recorder
48
-
49
- if @sampled
50
- @span_recorder.add(child_span)
51
- end
52
-
53
- child_span
54
- end
55
-
56
- def deep_dup
57
- copy = super
58
- copy.set_span_recorder
59
-
60
- @span_recorder.spans.each do |span|
61
- # span_recorder's first span is the current span, which should not be added to the copy's spans
62
- next if span == self
63
- copy.span_recorder.add(span.dup)
64
- end
65
-
66
- copy
67
- end
68
-
69
- def set_initial_sample_desicion(sampling_context = {})
70
- unless Sentry.configuration.tracing_enabled?
71
- @sampled = false
72
- return
73
- end
74
-
75
- return unless @sampled.nil?
76
-
77
- transaction_description = generate_transaction_description
78
-
79
- logger = Sentry.configuration.logger
80
- sample_rate = Sentry.configuration.traces_sample_rate
81
- traces_sampler = Sentry.configuration.traces_sampler
82
-
83
- if traces_sampler.is_a?(Proc)
84
- sampling_context = sampling_context.merge(
85
- parent_sampled: @parent_sampled,
86
- transaction_context: self.to_hash
87
- )
88
-
89
- sample_rate = traces_sampler.call(sampling_context)
90
- end
91
-
92
- unless [true, false].include?(sample_rate) || (sample_rate.is_a?(Float) && sample_rate >= 0.0 && sample_rate <= 1.0)
93
- @sampled = false
94
- logger.warn("#{MESSAGE_PREFIX} Discarding #{transaction_description} because of invalid sample_rate: #{sample_rate}")
95
- return
96
- end
97
-
98
- if sample_rate == 0.0 || sample_rate == false
99
- @sampled = false
100
- logger.debug("#{MESSAGE_PREFIX} Discarding #{transaction_description} because traces_sampler returned 0 or false")
101
- return
102
- end
103
-
104
- if sample_rate == true
105
- @sampled = true
106
- else
107
- @sampled = Random.rand < sample_rate
108
- end
109
-
110
- if @sampled
111
- logger.debug("#{MESSAGE_PREFIX} Starting #{transaction_description}")
112
- else
113
- logger.debug(
114
- "#{MESSAGE_PREFIX} Discarding #{transaction_description} because it's not included in the random sample (sampling rate = #{sample_rate})"
115
- )
116
- end
117
- end
118
-
119
- def finish(hub: nil)
120
- super() # Span#finish doesn't take arguments
121
-
122
- if @name.nil?
123
- @name = UNLABELD_NAME
124
- end
125
-
126
- return unless @sampled
127
-
128
- hub ||= Sentry.get_current_hub
129
- event = hub.current_client.event_from_transaction(self)
130
- hub.capture_event(event)
131
- end
132
-
133
- private
134
-
135
- def generate_transaction_description
136
- result = op.nil? ? "" : "<#{@op}> "
137
- result += "transaction"
138
- result += " <#{@name}>" if @name
139
- result
140
- end
141
-
142
- class SpanRecorder
143
- attr_reader :max_length, :spans
144
-
145
- def initialize(max_length)
146
- @max_length = max_length
147
- @spans = []
148
- end
149
-
150
- def add(span)
151
- if @spans.count < @max_length
152
- @spans << span
153
- end
154
- end
155
- end
156
- end
157
- end