@@ -134,6 +134,17 @@ func categoryFromEnvelope(envelope *protocol.Envelope) ratelimit.Category {
134134 return ratelimit .CategoryAll
135135}
136136
137+ // SyncTransport is a blocking implementation of Transport.
138+ //
139+ // Clients using this transport will send requests to Sentry sequentially and
140+ // block until a response is returned.
141+ //
142+ // The blocking behavior is useful in a limited set of use cases. For example,
143+ // use it when deploying code to a Function as a Service ("Serverless")
144+ // platform, where any work happening in a background goroutine is not
145+ // guaranteed to execute.
146+ //
147+ // For most cases, prefer AsyncTransport.
137148type SyncTransport struct {
138149 dsn * protocol.Dsn
139150 client * http.Client
@@ -153,7 +164,7 @@ func NewSyncTransport(options TransportOptions) *SyncTransport {
153164
154165 dsn , err := protocol .NewDsn (options .Dsn )
155166 if err != nil {
156- debuglog .Printf ("failed to create transport : invalid dsn: %v\n " , err )
167+ debuglog .Printf ("Transport is disabled : invalid dsn: %v\n " , err )
157168 return transport
158169 }
159170 transport .dsn = dsn
@@ -186,8 +197,19 @@ func (t *SyncTransport) SendEnvelope(envelope *protocol.Envelope) error {
186197func (t * SyncTransport ) Close () {}
187198
188199func (t * SyncTransport ) SendEvent (event protocol.EnvelopeConvertible ) {
189- if envelope , err := event .ToEnvelope (t .dsn ); err == nil && envelope != nil {
190- _ = t .SendEnvelope (envelope )
200+ envelope , err := event .ToEnvelope (t .dsn )
201+ if err != nil {
202+ debuglog .Printf ("Failed to convert to envelope: %v" , err )
203+ return
204+ }
205+
206+ if envelope == nil {
207+ debuglog .Printf ("Error: event with empty envelope" )
208+ return
209+ }
210+
211+ if err := t .SendEnvelope (envelope ); err != nil {
212+ debuglog .Printf ("Error sending the envelope: %v" , err )
191213 }
192214}
193215
@@ -197,6 +219,11 @@ func (t *SyncTransport) IsRateLimited(category ratelimit.Category) bool {
197219
198220func (t * SyncTransport ) SendEnvelopeWithContext (ctx context.Context , envelope * protocol.Envelope ) error {
199221 if t .dsn == nil {
222+ debuglog .Printf ("Dropping envelope: invalid dsn" )
223+ return nil
224+ }
225+ if envelope == nil {
226+ debuglog .Printf ("Error: provided empty envelope" )
200227 return nil
201228 }
202229
@@ -218,7 +245,7 @@ func (t *SyncTransport) SendEnvelopeWithContext(ctx context.Context, envelope *p
218245 if response .StatusCode >= 400 && response .StatusCode <= 599 {
219246 b , err := io .ReadAll (response .Body )
220247 if err != nil {
221- debuglog .Printf ("Error while reading response code : %v" , err )
248+ debuglog .Printf ("Error while reading response body : %v" , err )
222249 }
223250 debuglog .Printf ("Sending %s failed with the following error: %s" , envelope .Header .EventID , string (b ))
224251 }
@@ -253,6 +280,11 @@ func (t *SyncTransport) disabled(c ratelimit.Category) bool {
253280 return disabled
254281}
255282
283+ // AsyncTransport is the default, non-blocking, implementation of Transport.
284+ //
285+ // Clients using this transport will enqueue requests in a queue and return to
286+ // the caller before any network communication has happened. Requests are sent
287+ // to Sentry sequentially from a background goroutine.
256288type AsyncTransport struct {
257289 dsn * protocol.Dsn
258290 client * http.Client
@@ -292,7 +324,7 @@ func NewAsyncTransport(options TransportOptions) *AsyncTransport {
292324
293325 dsn , err := protocol .NewDsn (options .Dsn )
294326 if err != nil {
295- debuglog .Printf ("%v \n " , err )
327+ debuglog .Printf ("Transport is disabled: invalid dsn: %v " , err )
296328 return transport
297329 }
298330 transport .dsn = dsn
@@ -351,8 +383,19 @@ func (t *AsyncTransport) SendEnvelope(envelope *protocol.Envelope) error {
351383}
352384
353385func (t * AsyncTransport ) SendEvent (event protocol.EnvelopeConvertible ) {
354- if envelope , err := event .ToEnvelope (t .dsn ); err == nil && envelope != nil {
355- _ = t .SendEnvelope (envelope )
386+ envelope , err := event .ToEnvelope (t .dsn )
387+ if err != nil {
388+ debuglog .Printf ("Failed to convert to envelope: %v" , err )
389+ return
390+ }
391+
392+ if envelope == nil {
393+ debuglog .Printf ("Error: event with empty envelope" )
394+ return
395+ }
396+
397+ if err := t .SendEnvelope (envelope ); err != nil {
398+ debuglog .Printf ("Error sending the envelope: %v" , err )
356399 }
357400}
358401
@@ -486,7 +529,7 @@ func (t *AsyncTransport) handleResponse(response *http.Response) bool {
486529 }
487530
488531 if response .StatusCode >= 500 {
489- debuglog .Printf ("Server error %d - will retry " , response .StatusCode )
532+ debuglog .Printf ("Server error %d" , response .StatusCode )
490533 return false
491534 }
492535
0 commit comments