sentry-ruby 7.2.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/gemfiles/ruby-2.7_rack-2_redis-4.gemfile.lock +13 -13
  3. data/gemfiles/ruby-2.7_rack-3.1_redis-4.gemfile.lock +13 -13
  4. data/gemfiles/ruby-2.7_rack-3_redis-4.gemfile.lock +13 -13
  5. data/gemfiles/ruby-3.0_rack-2_redis-4.gemfile.lock +14 -14
  6. data/gemfiles/ruby-3.0_rack-3.1_redis-4.gemfile.lock +14 -14
  7. data/gemfiles/ruby-3.0_rack-3_redis-4.gemfile.lock +14 -14
  8. data/gemfiles/ruby-3.1_rack-2_redis-4.gemfile.lock +28 -28
  9. data/gemfiles/ruby-3.1_rack-3.1_redis-4.gemfile.lock +28 -28
  10. data/gemfiles/ruby-3.1_rack-3_redis-4.gemfile.lock +28 -28
  11. data/gemfiles/ruby-3.2_rack-0_redis-5.gemfile.lock +28 -28
  12. data/gemfiles/ruby-3.2_rack-2_redis-4.gemfile.lock +30 -30
  13. data/gemfiles/ruby-3.2_rack-2_redis-5.gemfile.lock +30 -30
  14. data/gemfiles/ruby-3.2_rack-3.1_redis-4.gemfile.lock +30 -30
  15. data/gemfiles/ruby-3.2_rack-3_redis-4.gemfile.lock +30 -30
  16. data/gemfiles/ruby-3.2_rack-3_redis-5.gemfile.lock +30 -30
  17. data/gemfiles/ruby-3.3_rack-2_redis-4.gemfile.lock +32 -33
  18. data/gemfiles/ruby-3.3_rack-3.1_redis-4.gemfile.lock +32 -33
  19. data/gemfiles/ruby-3.3_rack-3.1_redis-5.3.gemfile.lock +32 -33
  20. data/gemfiles/ruby-3.3_rack-3_redis-4.gemfile.lock +32 -33
  21. data/gemfiles/ruby-3.4_rack-2_redis-4.gemfile.lock +32 -33
  22. data/gemfiles/ruby-3.4_rack-3.1_redis-4.gemfile.lock +32 -33
  23. data/gemfiles/ruby-3.4_rack-3.1_redis-5.3.gemfile.lock +32 -33
  24. data/gemfiles/ruby-3.4_rack-3_redis-4.gemfile.lock +32 -33
  25. data/gemfiles/ruby-4.0_rack-2_redis-4.gemfile.lock +32 -33
  26. data/gemfiles/ruby-4.0_rack-3.1_redis-4.gemfile.lock +32 -33
  27. data/gemfiles/ruby-4.0_rack-3_redis-4.gemfile.lock +32 -33
  28. data/gemfiles/ruby-jruby-9.4.14.0_rack-2_redis-4.gemfile.lock +32 -32
  29. data/gemfiles/ruby-jruby-9.4.14.0_rack-3.1_redis-4.gemfile.lock +32 -32
  30. data/gemfiles/ruby-jruby-9.4.14.0_rack-3_redis-4.gemfile.lock +32 -32
  31. data/lib/sentry/configuration.rb +2 -26
  32. data/lib/sentry/debug_structured_logger.rb +18 -21
  33. data/lib/sentry/job_extensions/extension.rb +348 -0
  34. data/lib/sentry/propagation_context.rb +2 -0
  35. data/lib/sentry/redis.rb +7 -1
  36. data/lib/sentry/rufus_scheduler.rb +10 -5
  37. data/lib/sentry/scope.rb +39 -1
  38. data/lib/sentry/session_flusher.rb +5 -2
  39. data/lib/sentry/span.rb +25 -2
  40. data/lib/sentry/structured_logger.rb +16 -13
  41. data/lib/sentry/transport/debug_transport.rb +70 -19
  42. data/lib/sentry/utils/latency.rb +18 -0
  43. data/lib/sentry/utils/ring_buffer.rb +38 -0
  44. data/lib/sentry/version.rb +1 -1
  45. data/lib/sentry-ruby.rb +12 -0
  46. metadata +9 -6
@@ -3,9 +3,71 @@
3
3
  require "json"
4
4
  require "fileutils"
5
5
  require "pathname"
6
+ require "tempfile"
6
7
  require "delegate"
7
8
 
8
9
  module Sentry
10
+ class DebugLogFile
11
+ attr_reader :path
12
+
13
+ def initialize(path, prefix)
14
+ unless path
15
+ @temporary_file = Tempfile.new([prefix, ".log"])
16
+ @temporary_file.close
17
+ end
18
+
19
+ @path = Pathname(path || @temporary_file.path)
20
+ @offset = 0
21
+ @generation = nil
22
+ FileUtils.mkdir_p(@path.dirname) unless @path.dirname.exist?
23
+ end
24
+
25
+ def append(entry)
26
+ json = "#{JSON.dump(entry)}\n"
27
+ File.open(path, "a") do |file|
28
+ file.flock(File::LOCK_EX)
29
+ file.write(json)
30
+ end
31
+ end
32
+
33
+ def entries
34
+ return [] unless path.exist?
35
+
36
+ lines = File.open(path, "r") do |file|
37
+ file.flock(File::LOCK_SH)
38
+ current_generation = file.stat.ino
39
+ @offset = 0 if @generation != current_generation
40
+ @generation = current_generation
41
+ file.seek(@offset)
42
+ file.readlines
43
+ end
44
+
45
+ lines.select { |line| line.end_with?("\n") }.map { |line| JSON.parse(line) }
46
+ end
47
+
48
+ def clear
49
+ File.open(path, "a") do |file|
50
+ file.flock(File::LOCK_SH)
51
+ @offset = file.size
52
+ @generation = file.stat.ino
53
+ end
54
+ end
55
+
56
+ def start_run
57
+ return if @temporary_file
58
+
59
+ File.open(path, "a") do |file|
60
+ file.flock(File::LOCK_EX)
61
+ previous = Pathname("#{path}.1")
62
+ previous.rename("#{path}.2") if previous.exist?
63
+ path.rename("#{path}.1")
64
+ FileUtils.touch(path)
65
+ end
66
+ @offset = 0
67
+ @generation = nil
68
+ end
69
+ end
70
+
9
71
  # DebugTransport is a transport that logs events to a file for debugging purposes.
10
72
  #
11
73
  # It can optionally also send events to Sentry via HTTP transport if a real DSN
@@ -16,7 +78,8 @@ module Sentry
16
78
  attr_reader :log_file, :backend
17
79
 
18
80
  def initialize(configuration)
19
- @log_file = initialize_log_file(configuration)
81
+ @log = DebugLogFile.new(configuration.sdk_debug_transport_log_file, File.basename(DEFAULT_LOG_FILE_PATH, ".log"))
82
+ @log_file = @log.path
20
83
  @backend = initialize_backend(configuration)
21
84
 
22
85
  super(@backend)
@@ -41,39 +104,27 @@ module Sentry
41
104
  end
42
105
  }
43
106
 
44
- File.open(log_file, "a") { |file| file.write("#{JSON.dump(envelope_json)}\n") }
107
+ @log.append(envelope_json)
45
108
  end
46
109
 
47
110
  def logged_envelopes
48
- return [] unless File.exist?(log_file)
111
+ @log.entries
112
+ end
49
113
 
50
- File.readlines(log_file).select { |line| fully_written?(line) }.map do |line|
51
- JSON.parse(line)
52
- end
114
+ def start_run
115
+ @log.start_run
53
116
  end
54
117
 
55
118
  def clear
56
- File.write(log_file, "")
119
+ @log.clear
57
120
  log_debug("DebugTransport: Cleared events from #{log_file}")
58
121
  end
59
122
 
60
123
  private
61
124
 
62
- def fully_written?(line)
63
- line.end_with?("\n")
64
- end
65
-
66
125
  def initialize_backend(configuration)
67
126
  backend = configuration.dsn.local? ? DummyTransport : HTTPTransport
68
127
  backend.new(configuration)
69
128
  end
70
-
71
- def initialize_log_file(configuration)
72
- log_file = Pathname(configuration.sdk_debug_transport_log_file || DEFAULT_LOG_FILE_PATH)
73
-
74
- FileUtils.mkdir_p(log_file.dirname) unless log_file.dirname.exist?
75
-
76
- log_file
77
- end
78
129
  end
79
130
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+
5
+ module Sentry
6
+ module Utils
7
+ module Latency
8
+ module_function
9
+
10
+ def milliseconds_since(time)
11
+ return unless time
12
+
13
+ time = Time.parse(time) if time.is_a?(String)
14
+ (Time.now.to_f - time.to_f) * 1000.0
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sentry/core_ext/object/deep_dup"
4
+
5
+ module Sentry
6
+ module Utils
7
+ class RingBuffer
8
+ attr_reader :values
9
+
10
+ def initialize(capacity)
11
+ raise ArgumentError, "capacity must be positive" unless capacity.positive?
12
+
13
+ @capacity = capacity
14
+ @values = {}
15
+ end
16
+
17
+ def set(key, value)
18
+ @values.delete(key)
19
+ @values[key] = value
20
+ @values.shift if @values.size > @capacity
21
+ end
22
+
23
+ def clear
24
+ @values.clear
25
+ end
26
+
27
+ def empty?
28
+ @values.empty?
29
+ end
30
+
31
+ def dup
32
+ copy = self.class.new(@capacity)
33
+ copy.values.merge!(@values)
34
+ copy
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "7.2.0"
4
+ VERSION = "7.3.0"
5
5
  end
data/lib/sentry-ruby.rb CHANGED
@@ -12,6 +12,7 @@ require "sentry/utils/encoding_helper"
12
12
  require "sentry/utils/logging_helper"
13
13
  require "sentry/utils/callback_helper"
14
14
  require "sentry/utils/sample_rand"
15
+ require "sentry/utils/latency"
15
16
  require "sentry/configuration"
16
17
  require "sentry/structured_logger"
17
18
  require "sentry/debug_structured_logger"
@@ -31,6 +32,7 @@ require "sentry/cron/fugit_schedule"
31
32
  require "sentry/cron/slug"
32
33
  require "sentry/vernier/profiler"
33
34
  require "sentry/metrics"
35
+ require "sentry/job_extensions/extension"
34
36
 
35
37
  [
36
38
  "sentry/rake",
@@ -223,6 +225,16 @@ module Sentry
223
225
  get_current_scope.set_context(*args)
224
226
  end
225
227
 
228
+ # Records a feature flag evaluation on the current scope and active span.
229
+ # Only boolean results are recorded.
230
+ # @param name [String, Symbol] the flag name
231
+ # @param result [Boolean] the evaluation result
232
+ # @return [void]
233
+ def add_feature_flag(name, result)
234
+ return unless initialized?
235
+ get_current_scope.add_feature_flag(name, result)
236
+ end
237
+
226
238
  # @!method set_attributes
227
239
  # Updates the current scope's attributes by merging with the old value.
228
240
  # @param attributes_hash [Hash]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0
4
+ version: 7.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
@@ -150,6 +150,7 @@ files:
150
150
  - lib/sentry/interfaces/stacktrace.rb
151
151
  - lib/sentry/interfaces/stacktrace_builder.rb
152
152
  - lib/sentry/interfaces/threads.rb
153
+ - lib/sentry/job_extensions/extension.rb
153
154
  - lib/sentry/linecache.rb
154
155
  - lib/sentry/log_event.rb
155
156
  - lib/sentry/log_event_buffer.rb
@@ -195,9 +196,11 @@ files:
195
196
  - lib/sentry/utils/exception_cause_chain.rb
196
197
  - lib/sentry/utils/filename_cache.rb
197
198
  - lib/sentry/utils/http_tracing.rb
199
+ - lib/sentry/utils/latency.rb
198
200
  - lib/sentry/utils/logging_helper.rb
199
201
  - lib/sentry/utils/real_ip.rb
200
202
  - lib/sentry/utils/request_id.rb
203
+ - lib/sentry/utils/ring_buffer.rb
201
204
  - lib/sentry/utils/sample_rand.rb
202
205
  - lib/sentry/utils/telemetry_attributes.rb
203
206
  - lib/sentry/utils/uuid.rb
@@ -206,15 +209,15 @@ files:
206
209
  - lib/sentry/version.rb
207
210
  - sentry-ruby-core.gemspec
208
211
  - sentry-ruby.gemspec
209
- homepage: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-ruby
212
+ homepage: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-ruby
210
213
  licenses:
211
214
  - MIT
212
215
  metadata:
213
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-ruby
214
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-ruby
215
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.2.0/CHANGELOG.md
216
+ homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-ruby
217
+ source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-ruby
218
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.3.0/CHANGELOG.md
216
219
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
217
- documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/7.2.0
220
+ documentation_uri: http://www.rubydoc.info/gems/sentry-ruby/7.3.0
218
221
  rdoc_options: []
219
222
  require_paths:
220
223
  - lib