Skip to content

Commit 8c6a0a9

Browse files
committed
Reduce hash allocations
1 parent 0f6d57a commit 8c6a0a9

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

sentry-ruby/lib/sentry/log_event.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class LogEvent
1212
TYPE = "log"
1313

1414
DEFAULT_PARAMETERS = [].freeze
15-
DEFAULT_ATTRIBUTES = {}.freeze
1615

1716
PARAMETER_PREFIX = "sentry.message.parameter"
1817

@@ -29,7 +28,7 @@ def initialize(**options)
2928
@level = options.fetch(:level)
3029
@body = options[:body]
3130
@template = @body if is_template?
32-
@attributes = options[:attributes] || DEFAULT_ATTRIBUTES
31+
@attributes = options[:attributes] || {}
3332
@origin = options[:origin]
3433
@trace_id = nil
3534
@span_id = nil

sentry-ruby/lib/sentry/metric_event.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ module Sentry
66
class MetricEvent
77
include Sentry::Utils::TelemetryAttributes
88

9-
DEFAULT_ATTRIBUTES = {}.freeze
10-
119
attr_reader :name, :type, :value, :unit, :timestamp, :trace_id, :span_id, :attributes
1210
attr_writer :trace_id, :span_id, :attributes
1311

@@ -22,7 +20,7 @@ def initialize(
2220
@type = type
2321
@value = value
2422
@unit = unit
25-
@attributes = attributes || DEFAULT_ATTRIBUTES
23+
@attributes = attributes || {}
2624

2725
@timestamp = Sentry.utc_now
2826
@trace_id = nil

sentry-ruby/lib/sentry/scope.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def apply_to_telemetry(telemetry)
109109
"server.address" => configuration.server_name
110110
}.compact
111111

112-
telemetry.attributes = default_attributes.merge(telemetry.attributes)
112+
default_attributes.each { |k, v| telemetry.attributes[k] = v unless telemetry.attributes.key?(k) }
113113

114114
if configuration.send_default_pii && !user.empty?
115115
user_attributes = {
@@ -118,7 +118,7 @@ def apply_to_telemetry(telemetry)
118118
"user.email" => user[:email]
119119
}.compact
120120

121-
telemetry.attributes = user_attributes.merge(telemetry.attributes)
121+
user_attributes.each { |k, v| telemetry.attributes[k] = v unless telemetry.attributes.key?(k) }
122122
end
123123

124124
telemetry

0 commit comments

Comments
 (0)