This repository was archived by the owner on Feb 12, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -247,6 +247,10 @@ def get_culprit(frames)
247247 "#{ lastframe . filename } in #{ lastframe . function } at line #{ lastframe . lineno } " if lastframe
248248 end
249249
250+ def to_json_compatible
251+ JSON . parse ( JSON . generate ( to_hash ) )
252+ end
253+
250254 # For cross-language compat
251255 class << self
252256 alias captureException from_exception
Original file line number Diff line number Diff line change @@ -120,7 +120,9 @@ def capture_type(obj, options = {})
120120 yield evt if block_given?
121121 if configuration . async?
122122 begin
123- configuration . async . call ( evt )
123+ # We have to convert to a JSON-like hash, because background job
124+ # processors (esp ActiveJob) may not like weird types in the event hash
125+ configuration . async . call ( evt . to_json_compatible )
124126 rescue => ex
125127 Raven . logger . error ( "async event sending failed: #{ ex . message } " )
126128 send_event ( evt )
Original file line number Diff line number Diff line change @@ -331,6 +331,24 @@ def raven_context
331331 end
332332 end
333333
334+ describe '.to_json_compatible' do
335+ subject do
336+ Raven ::Event . new ( :extra => {
337+ 'my_custom_variable' => 'value' ,
338+ 'date' => Time . utc ( 0 ) ,
339+ 'anonymous_module' => Class . new
340+ } )
341+ end
342+
343+ it "should coerce non-JSON-compatible types" do
344+ json = subject . to_json_compatible
345+
346+ expect ( json [ "extra" ] [ 'my_custom_variable' ] ) . to eq ( 'value' )
347+ expect ( json [ "extra" ] [ 'date' ] ) . to be_a ( String )
348+ expect ( json [ "extra" ] [ 'anonymous_module' ] ) . not_to be_a ( Class )
349+ end
350+ end
351+
334352 describe '.capture_message' do
335353 let ( :message ) { 'This is a message' }
336354 let ( :hash ) { Raven ::Event . capture_message ( message ) . to_hash }
Original file line number Diff line number Diff line change 22require 'raven/instance'
33
44describe Raven ::Instance do
5- let ( :event ) { double ( "event" , :id => "event_id" ) }
5+ let ( :event ) { Raven :: Event . new ( :id => "event_id" ) }
66 let ( :options ) { double ( "options" ) }
77 let ( :context ) { nil }
88
6060 expect ( Raven ::Event ) . to receive ( :from_message ) . with ( message , options )
6161 expect ( subject ) . not_to receive ( :send_event ) . with ( event )
6262
63- expect ( subject . configuration . async ) . to receive ( :call ) . with ( event )
63+ expect ( subject . configuration . async ) . to receive ( :call ) . with ( event . to_json_compatible )
6464 subject . capture_type ( message , options )
6565 end
6666
100100 expect ( Raven ::Event ) . to receive ( :from_exception ) . with ( exception , options )
101101 expect ( subject ) . not_to receive ( :send_event ) . with ( event )
102102
103- expect ( subject . configuration . async ) . to receive ( :call ) . with ( event )
103+ expect ( subject . configuration . async ) . to receive ( :call ) . with ( event . to_json_compatible )
104104 subject . capture_type ( exception , options )
105105 end
106106
121121 it 'sends the result of Event.capture_exception via fallback' do
122122 expect ( Raven ::Event ) . to receive ( :from_exception ) . with ( exception , options )
123123
124- expect ( subject ) . to receive ( :send_event ) . with ( event )
124+ expect ( subject . configuration . async ) . to receive ( :call ) . with ( event . to_json_compatible )
125125 subject . capture_type ( exception , options )
126126 end
127127 end
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
33describe Raven do
4- let ( :event ) { double ( "event" , :id => "event_id" ) }
4+ let ( :event ) { Raven :: Event . new ( :id => "event_id" ) }
55 let ( :options ) { double ( "options" ) }
66
77 before do
3939 expect ( Raven ::Event ) . to receive ( :from_message ) . with ( message , options )
4040 expect ( Raven ) . not_to receive ( :send_event ) . with ( event )
4141
42- expect ( Raven . configuration . async ) . to receive ( :call ) . with ( event )
42+ expect ( Raven . configuration . async ) . to receive ( :call ) . with ( event . to_json_compatible )
4343 Raven . capture_message ( message , options )
4444 end
4545
7878 expect ( Raven ::Event ) . to receive ( :from_exception ) . with ( exception , options )
7979 expect ( Raven ) . not_to receive ( :send_event ) . with ( event )
8080
81- expect ( Raven . configuration . async ) . to receive ( :call ) . with ( event )
81+ expect ( Raven . configuration . async ) . to receive ( :call ) . with ( event . to_json_compatible )
8282 Raven . capture_exception ( exception , options )
8383 end
8484
You can’t perform that action at this time.
0 commit comments