Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sentry-ruby/lib/sentry/breadcrumb.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'oj'

module Sentry
class Breadcrumb
DATA_SERIALIZATION_ERROR_MESSAGE = "[data were removed due to serialization issues]"
Expand Down Expand Up @@ -54,7 +56,7 @@ def message=(message)

def serialized_data
begin
::JSON.parse(::JSON.generate(@data))
Oj.load(Oj.dump(@data, mode: :compat), mode: :compat)
rescue Exception => e
Sentry.logger.debug(LOGGER_PROGNAME) do
<<~MSG
Expand Down
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "sentry/transport"
require 'oj'

module Sentry
class Client
Expand Down Expand Up @@ -201,7 +202,7 @@ def dispatch_async_event(async_block, event, hint)
end

if async_block.arity == 2
hint = JSON.parse(JSON.generate(hint))
hint = Oj.load(Oj.dump(hint, mode: :compat), mode: :compat)
async_block.call(event_hash, hint)
else
async_block.call(event_hash)
Expand Down
6 changes: 4 additions & 2 deletions sentry-ruby/lib/sentry/envelope.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'oj'

module Sentry
# @api private
class Envelope
Expand All @@ -19,7 +21,7 @@ def type
end

def to_s
[JSON.generate(@headers), JSON.generate(@payload)].join("\n")
[Oj.dump(@headers, mode: :compat), Oj.dump(@payload, mode: :compat)].join("\n")
end

def serialize
Expand All @@ -40,7 +42,7 @@ def serialize

def size_breakdown
payload.map do |key, value|
"#{key}: #{JSON.generate(value).bytesize}"
"#{key}: #{Oj.dump(value, mode: :compat).bytesize}"
end.join(", ")
end

Expand Down
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'sentry/utils/real_ip'
require 'sentry/utils/request_id'
require 'sentry/utils/custom_inspection'
require 'oj'

module Sentry
# This is an abstract class that defines the shared attributes of an event.
Expand Down Expand Up @@ -152,7 +153,7 @@ def to_hash

# @return [Hash]
def to_json_compatible
JSON.parse(JSON.generate(to_hash))
Oj.load(Oj.dump(to_hash, mode: :compat), mode: :compat)
end

private
Expand Down
3 changes: 2 additions & 1 deletion sentry-ruby/lib/sentry/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "json"
require "base64"
require "sentry/envelope"
require 'oj'

module Sentry
class Transport
Expand Down Expand Up @@ -82,7 +83,7 @@ def serialize_envelope(envelope)
serialized_items << item
end

data = [JSON.generate(envelope.headers), *serialized_results].join("\n") unless serialized_results.empty?
data = [Oj.dump(envelope.headers, mode: :compat), *serialized_results].join("\n") unless serialized_results.empty?

[data, serialized_items]
end
Expand Down
1 change: 1 addition & 0 deletions sentry-ruby/sentry-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "concurrent-ruby", '~> 1.0', '>= 1.0.2'
spec.add_dependency "oj"
end
Loading