Skip to content

Commit fe51aa2

Browse files
committed
chore: amend debug output and func comments
1 parent 674cf34 commit fe51aa2

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

internal/http/transport.go

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
137148
type 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 {
186197
func (t *SyncTransport) Close() {}
187198

188199
func (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

198220
func (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.
256288
type 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

353385
func (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

internal/protocol/envelope.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type EnvelopeHeader struct {
3232
// This means that SDK information can be carried for minidumps, session data and other submissions.
3333
Sdk *SdkInfo `json:"sdk,omitempty"`
3434

35-
// Trace contains trace context information for distributed tracing
35+
// Trace contains the [Dynamic Sampling Context](https://develop.sentry.dev/sdk/telemetry/traces/dynamic-sampling-context/)
3636
Trace map[string]string `json:"trace,omitempty"`
3737
}
3838

@@ -165,7 +165,7 @@ func (e *Envelope) Size() (int, error) {
165165
return len(data), nil
166166
}
167167

168-
// MarshalJSON converts the EnvelopeHeader to JSON and ensures it's a single line.
168+
// MarshalJSON converts the EnvelopeHeader to JSON.
169169
func (h *EnvelopeHeader) MarshalJSON() ([]byte, error) {
170170
type header EnvelopeHeader
171171
return json.Marshal((*header)(h))

internal/protocol/interfaces.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ type TelemetryTransport interface {
2323
// backpressure error if the queue is full.
2424
SendEnvelope(envelope *Envelope) error
2525

26-
// SendEvent sends an event to Sentry. Returns immediately with
27-
// backpressure error if the queue is full.
26+
// SendEvent sends an event to Sentry.
2827
SendEvent(event EnvelopeConvertible)
2928

3029
// IsRateLimited checks if a specific category is currently rate limited

0 commit comments

Comments
 (0)