File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ def send_data(data)
6969 raise Sentry ::ExternalError , error_info
7070 end
7171 rescue SocketError , *HTTP_ERRORS => e
72+ on_error if respond_to? ( :on_error )
7273 raise Sentry ::ExternalError . new ( e &.message )
7374 end
7475
Original file line number Diff line number Diff line change @@ -7,16 +7,38 @@ module Sentry
77 # Designed to just report events to Spotlight in development.
88 class SpotlightTransport < HTTPTransport
99 DEFAULT_SIDECAR_URL = "http://localhost:8969/stream"
10+ MAX_FAILED_REQUESTS = 3
1011
1112 def initialize ( configuration )
1213 super
1314 @sidecar_url = configuration . spotlight . is_a? ( String ) ? configuration . spotlight : DEFAULT_SIDECAR_URL
15+ @failed = 0
16+ @logged = false
17+
18+ log_debug ( "[Spotlight] initialized for url #{ @sidecar_url } " )
1419 end
1520
1621 def endpoint
1722 "/stream"
1823 end
1924
25+ def send_data ( data )
26+ if @failed >= MAX_FAILED_REQUESTS
27+ unless @logged
28+ log_debug ( "[Spotlight] disabling because of too many request failures" )
29+ @logged = true
30+ end
31+
32+ return
33+ end
34+
35+ super
36+ end
37+
38+ def on_error
39+ @failed += 1
40+ end
41+
2042 # Similar to HTTPTransport connection, but does not support Proxy and SSL
2143 def conn
2244 sidecar = URI ( @sidecar_url )
Original file line number Diff line number Diff line change 1515 end
1616 end
1717
18+ let ( :client ) { Sentry ::Client . new ( configuration ) }
19+ let ( :event ) { client . event_from_message ( "foobarbaz" ) }
20+ let ( :data ) do
21+ subject . serialize_envelope ( subject . envelope_from_event ( event . to_hash ) ) . first
22+ end
23+
1824 subject { described_class . new ( configuration ) }
1925
26+ it 'logs a debug message during initialization' do
27+ string_io = StringIO . new
28+ configuration . logger = Logger . new ( string_io )
29+
30+ subject
31+
32+ expect ( string_io . string ) . to include ( 'sentry: [Spotlight] initialized for url http://localhost:8969/stream' )
33+ end
34+
2035 describe '#endpoint' do
2136 it 'returs correct endpoint' do
2237 expect ( subject . endpoint ) . to eq ( '/stream' )
3954 expect ( subject . conn . use_ssl? ) . to eq ( false )
4055 end
4156 end
57+
58+ describe '#send_data' do
59+ it 'fails a maximum of three times and logs disable once' do
60+ string_io = StringIO . new
61+ configuration . logger = Logger . new ( string_io )
62+
63+ allow ( ::Net ::HTTP ) . to receive ( :new ) . and_raise ( Errno ::ECONNREFUSED )
64+
65+ 3 . times do
66+ expect do
67+ subject . send_data ( data )
68+ end . to raise_error ( Sentry ::ExternalError )
69+ end
70+
71+ string_io . string = ""
72+ expect ( string_io . string ) . to eq ( "" )
73+
74+ 3 . times do
75+ expect do
76+ subject . send_data ( data )
77+ end . not_to raise_error
78+ end
79+
80+ expect ( string_io . string ) . to include ( 'sentry: [Spotlight] disabling because of too many request failures' )
81+ end
82+ end
4283end
You can’t perform that action at this time.
0 commit comments