Skip to content

Conversation

giortzisg
Copy link
Contributor

@giortzisg giortzisg commented Sep 24, 2025

Description

Create the new transport that accepts envelopes and not events. For now only the implementation for the new transport is added, without deprecating the old one. The PR also includes some misc changes:

  • creating an envelope convertible interface, to accept a generic type of events/logs/transactions, etc..
  • moving the dsn internally under the protocol folder and re exporting everything on the top level to avoid cyclic imports when using the new transport.

Issues


Note

Introduce envelope-first Sync/Async HTTP transports, centralize DSN and envelope types under internal/protocol, and adapt SDK to use them with minimal API surface changes.

  • Transport (new):
    • Add internal/http transports: AsyncTransport and SyncTransport that send protocol.Envelopes, with queueing, flush/close, rate limiting, proxy/TLS config, headers, and keep-alive handling.
  • Protocol (new):
    • Add internal/protocol: Dsn, Envelope (+ items, header), SdkInfo, and interfaces (EnvelopeConvertible, TelemetryTransport).
    • Provide DSN parsing, request headers, API URL, JSON marshal/unmarshal.
  • SDK integration/refactor:
    • Wrap and re-export Dsn and DsnParseError in top-level sentry; NewDsn delegates to protocol; RequestHeaders() uses SDK version; minor typo fix in comment.
    • Add Event.ToEnvelope/ToEnvelopeWithTime; include DSC trace info and attachments; fallback JSON marshal path preserved.
    • Update DynamicSamplingContext and transport.go to use DSN getters (GetPublicKey, etc.) and scheme constants from protocol in NewRequest.
  • Tests:
    • Add comprehensive tests for protocol DSN/envelope, new transports (queueing, flush, rate limits, errors, keep-alive, proxies/TLS, concurrency, goroutine leaks), and wrapper behavior; expand request and event tests.

Written by Cursor Bugbot for commit 1ed184b. This will update automatically on new commits. Configure here.

Copy link

linear bot commented Sep 24, 2025

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 85.00000% with 93 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.65%. Comparing base (2dc3b97) to head (871ade0).

Files with missing lines Patch % Lines
internal/http/transport.go 86.23% 33 Missing and 12 partials ⚠️
internal/protocol/envelope.go 63.73% 22 Missing and 11 partials ⚠️
interfaces.go 82.75% 7 Missing and 3 partials ⚠️
internal/protocol/dsn.go 97.69% 2 Missing and 1 partial ⚠️
transport.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1094      +/-   ##
==========================================
- Coverage   86.99%   86.65%   -0.34%     
==========================================
  Files          55       59       +4     
  Lines        6076     6559     +483     
==========================================
+ Hits         5286     5684     +398     
- Misses        645      705      +60     
- Partials      145      170      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 85 to 87
return &tls.Config{
RootCAs: options.CaCerts,
}
Copy link

@semgrep-code-getsentry semgrep-code-getsentry bot Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MinVersion is missing from this TLS configuration. By default, as of Go 1.22, TLS 1.2 is currently used as the minimum. General purpose web applications should default to TLS 1.3 with all other protocols disabled. Only where it is known that a web server must support legacy clients with unsupported an insecure browsers (such as Internet Explorer 10), it may be necessary to enable TLS 1.0 to provide support. Add `MinVersion: tls.VersionTLS13' to the TLS configuration to bump the minimum version to TLS 1.3.

🧼 Fixed in commit 871ade0 🧼

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we address this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since go uses tls1.2 we should be good to this as the min version. We already inherit the min version of the runtime anyways.

@giortzisg giortzisg force-pushed the feat/transport-envelope branch from 3ce9dee to 4228142 Compare September 29, 2025 14:02
@giortzisg giortzisg marked this pull request as ready for review September 29, 2025 14:27
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we'd also abstract the older event types as envelope items, but I'll leave it upto you if you want to do that now or separately later

Copy link
Member

@lcian lcian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some mostly minor comments, looks good overall. Haven't looked at the tests yet.

func (t *SyncTransport) Close() {}

func (t *SyncTransport) SendEvent(event protocol.EnvelopeConvertible) {
if envelope, err := event.ToEnvelope(t.dsn); err == nil && envelope != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this errors, we should log it. We're not logging it right now. Same for other uses of this function.

}

func getSentryRequestFromEnvelope(ctx context.Context, dsn *protocol.Dsn, envelope *protocol.Envelope) (r *http.Request, err error) {
defer func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

case protocol.EnvelopeItemTypeAttachment:
continue
default:
return ratelimit.CategoryAll
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory an envelope can contain multiple items, here we're only considering the first we find a match for.

Copy link
Member

@lcian lcian Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'm thinking this should live in internal/ratelimit/category.go, if it's possible with the imports


dsn, err := protocol.NewDsn(options.Dsn)
if err != nil {
debuglog.Printf("failed to create transport: invalid dsn: %v\n", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
debuglog.Printf("failed to create transport: invalid dsn: %v\n", err)
debuglog.Printf("transport is disabled: invalid dsn: %v\n", err)

if response.StatusCode >= 400 && response.StatusCode <= 599 {
b, err := io.ReadAll(response.Body)
if err != nil {
debuglog.Printf("Error while reading response code: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
debuglog.Printf("Error while reading response code: %v", err)
debuglog.Printf("Error while reading response body: %v", err)

}

if response.StatusCode >= 500 {
debuglog.Printf("Server error %d - will retry", response.StatusCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will retry

Chat, is this real? I believe we just fail to send and that's it.

func (t *AsyncTransport) sendEnvelopeHTTP(envelope *protocol.Envelope) bool {
category := categoryFromEnvelope(envelope)
if t.isRateLimited(category) {
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we consider being rate limited an error, see above where we do
atomic.AddInt64(&t.errorCount, 1)
if this fun returns false.
Is this what we want?

I guess this stuff will be replaced with client reports anyways so it's also okay to leave it as is for now.

Comment on lines +26 to +27
// SendEvent sends an event to Sentry. Returns immediately with
// backpressure error if the queue is full.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false, it cannot error

// This means that SDK information can be carried for minidumps, session data and other submissions.
Sdk *SdkInfo `json:"sdk,omitempty"`

// Trace contains trace context information for distributed tracing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Trace contains trace context information for distributed tracing
// Trace contains the [Dynamic Sampling Context](https://develop.sentry.dev/sdk/telemetry/traces/dynamic-sampling-context/)

return len(data), nil
}

// MarshalJSON converts the EnvelopeHeader to JSON and ensures it's a single line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensures it's a single line

does it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create new transport that accepts envelopes
4 participants