diff --git a/sentry-ruby/lib/sentry/check_in_event.rb b/sentry-ruby/lib/sentry/check_in_event.rb index 91ae17dc3..758b2432c 100644 --- a/sentry-ruby/lib/sentry/check_in_event.rb +++ b/sentry-ruby/lib/sentry/check_in_event.rb @@ -2,6 +2,7 @@ require "securerandom" require "sentry/cron/monitor_config" +require "sentry/utils/uuid" module Sentry class CheckInEvent < Event @@ -43,7 +44,7 @@ def initialize( self.status = status self.duration = duration self.monitor_config = monitor_config - self.check_in_id = check_in_id || SecureRandom.uuid.delete("-") + self.check_in_id = check_in_id || Utils.uuid end # @return [Hash] diff --git a/sentry-ruby/lib/sentry/event.rb b/sentry-ruby/lib/sentry/event.rb index 154452599..d9ad89d44 100644 --- a/sentry-ruby/lib/sentry/event.rb +++ b/sentry-ruby/lib/sentry/event.rb @@ -7,6 +7,7 @@ require "sentry/utils/real_ip" require "sentry/utils/request_id" require "sentry/utils/custom_inspection" +require "sentry/utils/uuid" module Sentry # This is an abstract class that defines the shared attributes of an event. @@ -50,7 +51,7 @@ class Event # @param message [String, nil] def initialize(configuration:, integration_meta: nil, message: nil) # Set some simple default values - @event_id = SecureRandom.uuid.delete("-") + @event_id = Utils.uuid @timestamp = Sentry.utc_now.iso8601 @platform = :ruby @type = self.class::TYPE diff --git a/sentry-ruby/lib/sentry/profiler.rb b/sentry-ruby/lib/sentry/profiler.rb index d81e46024..b1fbaf39b 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -2,6 +2,7 @@ require "securerandom" require_relative "profiler/helpers" +require "sentry/utils/uuid" module Sentry class Profiler @@ -17,7 +18,7 @@ class Profiler attr_reader :sampled, :started, :event_id def initialize(configuration) - @event_id = SecureRandom.uuid.delete("-") + @event_id = Utils.uuid @started = false @sampled = nil diff --git a/sentry-ruby/lib/sentry/propagation_context.rb b/sentry-ruby/lib/sentry/propagation_context.rb index 4112689ff..9fb847dbc 100644 --- a/sentry-ruby/lib/sentry/propagation_context.rb +++ b/sentry-ruby/lib/sentry/propagation_context.rb @@ -2,6 +2,7 @@ require "securerandom" require "sentry/baggage" +require "sentry/utils/uuid" module Sentry class PropagationContext @@ -66,8 +67,8 @@ def initialize(scope, env = nil) end end - @trace_id ||= SecureRandom.uuid.delete("-") - @span_id = SecureRandom.uuid.delete("-").slice(0, 16) + @trace_id ||= Utils.uuid + @span_id = Utils.uuid.slice(0, 16) end # Extract the trace_id, parent_span_id and parent_sampled values from a sentry-trace header. diff --git a/sentry-ruby/lib/sentry/span.rb b/sentry-ruby/lib/sentry/span.rb index 256d8bd2f..3d13805a5 100644 --- a/sentry-ruby/lib/sentry/span.rb +++ b/sentry-ruby/lib/sentry/span.rb @@ -2,6 +2,7 @@ require "securerandom" require "sentry/metrics/local_aggregator" +require "sentry/utils/uuid" module Sentry class Span @@ -127,8 +128,8 @@ def initialize( timestamp: nil, origin: nil ) - @trace_id = trace_id || SecureRandom.uuid.delete("-") - @span_id = span_id || SecureRandom.uuid.delete("-").slice(0, 16) + @trace_id = trace_id || Utils.uuid + @span_id = span_id || Utils.uuid.slice(0, 16) @parent_span_id = parent_span_id @sampled = sampled @start_timestamp = start_timestamp || Sentry.utc_now.to_f diff --git a/sentry-ruby/lib/sentry/utils/uuid.rb b/sentry-ruby/lib/sentry/utils/uuid.rb new file mode 100644 index 000000000..cfd23d7d2 --- /dev/null +++ b/sentry-ruby/lib/sentry/utils/uuid.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require "securerandom" + +module Sentry + module Utils + DELIMITER = "-" + + def self.uuid + SecureRandom.uuid.delete(DELIMITER) + end + end +end diff --git a/sentry-ruby/lib/sentry/vernier/profiler.rb b/sentry-ruby/lib/sentry/vernier/profiler.rb index 2818ae8d5..77f42a36a 100644 --- a/sentry-ruby/lib/sentry/vernier/profiler.rb +++ b/sentry-ruby/lib/sentry/vernier/profiler.rb @@ -3,6 +3,7 @@ require "securerandom" require_relative "../profiler/helpers" require_relative "output" +require "sentry/utils/uuid" module Sentry module Vernier @@ -12,7 +13,7 @@ class Profiler attr_reader :started, :event_id, :result def initialize(configuration) - @event_id = SecureRandom.uuid.delete("-") + @event_id = Utils.uuid @started = false @sampled = nil