From ef37ed1a0ad8b5482cc3f913890fcf55897b9908 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 08:32:16 +0000 Subject: [PATCH] bump github.com/getsentry/sentry-go from 0.22.0 to 0.23.0 Bumps [github.com/getsentry/sentry-go](https://github.com/getsentry/sentry-go) from 0.22.0 to 0.23.0. - [Release notes](https://github.com/getsentry/sentry-go/releases) - [Changelog](https://github.com/getsentry/sentry-go/blob/master/CHANGELOG.md) - [Commits](https://github.com/getsentry/sentry-go/compare/v0.22.0...v0.23.0) --- updated-dependencies: - dependency-name: github.com/getsentry/sentry-go dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../getsentry/sentry-go/CHANGELOG.md | 58 +++++++++ .../getsentry/sentry-go/check_in.go | 117 ++++++++++++++++++ .../github.com/getsentry/sentry-go/client.go | 37 ++++++ .../sentry-go/dynamic_sampling_context.go | 6 + vendor/github.com/getsentry/sentry-go/hub.go | 12 ++ .../getsentry/sentry-go/interfaces.go | 42 +++++++ .../github.com/getsentry/sentry-go/scope.go | 24 ++++ .../github.com/getsentry/sentry-go/sentry.go | 8 +- .../github.com/getsentry/sentry-go/tracing.go | 87 ++++++------- .../getsentry/sentry-go/transport.go | 43 ++++++- vendor/modules.txt | 2 +- 13 files changed, 386 insertions(+), 56 deletions(-) create mode 100644 vendor/github.com/getsentry/sentry-go/check_in.go diff --git a/go.mod b/go.mod index e8b7674b..4607a213 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/alphagov/router go 1.20 require ( - github.com/getsentry/sentry-go v0.22.0 + github.com/getsentry/sentry-go v0.23.0 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 diff --git a/go.sum b/go.sum index db8103df..6f44c516 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654 h1:XOPLOMn/zT4jIgxfxSsoXPxkrzz0FaCHwp33x5POJ+Q= -github.com/getsentry/sentry-go v0.22.0 h1:XNX9zKbv7baSEI65l+H1GEJgSeIC1c7EN5kluWaP6dM= -github.com/getsentry/sentry-go v0.22.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE= +github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= diff --git a/vendor/github.com/getsentry/sentry-go/CHANGELOG.md b/vendor/github.com/getsentry/sentry-go/CHANGELOG.md index a645cc23..662d5871 100644 --- a/vendor/github.com/getsentry/sentry-go/CHANGELOG.md +++ b/vendor/github.com/getsentry/sentry-go/CHANGELOG.md @@ -1,5 +1,63 @@ # Changelog +## 0.23.0 + +The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.23.0. + +### Features +- Initial support for [Cron Monitoring](https://docs.sentry.io/product/crons/) ([#661](https://github.com/getsentry/sentry-go/pull/661)) + + This is how the basic usage of the feature looks like: + + ```go + // 🟡 Notify Sentry your job is running: + checkinId := sentry.CaptureCheckIn( + &sentry.CheckIn{ + MonitorSlug: "", + Status: sentry.CheckInStatusInProgress, + }, + nil, + ) + + // Execute your scheduled task here... + + // 🟢 Notify Sentry your job has completed successfully: + sentry.CaptureCheckIn( + &sentry.CheckIn{ + ID: *checkinId, + MonitorSlug: "", + Status: sentry.CheckInStatusOK, + }, + nil, + ) + ``` + + A full example of using Crons Monitoring is available [here](https://github.com/getsentry/sentry-go/blob/dde4d360660838f3c2e0ced8205bc8f7a8d312d9/_examples/crons/main.go). + + More documentation on configuring and using Crons [can be found here](https://docs.sentry.io/platforms/go/crons/). + +- Add support for [Event Attachments](https://docs.sentry.io/platforms/go/enriching-events/attachments/) ([#670](https://github.com/getsentry/sentry-go/pull/670)) + + It's now possible to add file/binary payloads to Sentry events: + + ```go + sentry.ConfigureScope(func(scope *sentry.Scope) { + scope.AddAttachment(&Attachment{ + Filename: "report.html", + ContentType: "text/html", + Payload: []byte("

Look, HTML

"), + }) + }) + ``` + + The attachment will then be accessible on the Issue Details page. + +- Add sampling decision to trace envelope header ([#666](https://github.com/getsentry/sentry-go/pull/666)) +- Expose SpanFromContext function ([#672](https://github.com/getsentry/sentry-go/pull/672)) + +### Bug fixes +- Make `Span.Finish` a no-op when the span is already finished ([#660](https://github.com/getsentry/sentry-go/pull/660)) + ## 0.22.0 The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.22.0. diff --git a/vendor/github.com/getsentry/sentry-go/check_in.go b/vendor/github.com/getsentry/sentry-go/check_in.go new file mode 100644 index 00000000..d41ba3d2 --- /dev/null +++ b/vendor/github.com/getsentry/sentry-go/check_in.go @@ -0,0 +1,117 @@ +package sentry + +import "time" + +type CheckInStatus string + +const ( + CheckInStatusInProgress CheckInStatus = "in_progress" + CheckInStatusOK CheckInStatus = "ok" + CheckInStatusError CheckInStatus = "error" +) + +type checkInScheduleType string + +const ( + checkInScheduleTypeCrontab checkInScheduleType = "crontab" + checkInScheduleTypeInterval checkInScheduleType = "interval" +) + +type MonitorSchedule interface { + // scheduleType is a private method that must be implemented for monitor schedule + // implementation. It should never be called. This method is made for having + // specific private implementation of MonitorSchedule interface. + scheduleType() checkInScheduleType +} + +type crontabSchedule struct { + Type string `json:"type"` + Value string `json:"value"` +} + +func (c crontabSchedule) scheduleType() checkInScheduleType { + return checkInScheduleTypeCrontab +} + +// CrontabSchedule defines the MonitorSchedule with a cron format. +// Example: "8 * * * *". +func CrontabSchedule(scheduleString string) MonitorSchedule { + return crontabSchedule{ + Type: string(checkInScheduleTypeCrontab), + Value: scheduleString, + } +} + +type intervalSchedule struct { + Type string `json:"type"` + Value int64 `json:"value"` + Unit string `json:"unit"` +} + +func (i intervalSchedule) scheduleType() checkInScheduleType { + return checkInScheduleTypeInterval +} + +type MonitorScheduleUnit string + +const ( + MonitorScheduleUnitMinute MonitorScheduleUnit = "minute" + MonitorScheduleUnitHour MonitorScheduleUnit = "hour" + MonitorScheduleUnitDay MonitorScheduleUnit = "day" + MonitorScheduleUnitWeek MonitorScheduleUnit = "week" + MonitorScheduleUnitMonth MonitorScheduleUnit = "month" + MonitorScheduleUnitYear MonitorScheduleUnit = "year" +) + +// IntervalSchedule defines the MonitorSchedule with an interval format. +// +// Example: +// +// IntervalSchedule(1, sentry.MonitorScheduleUnitDay) +func IntervalSchedule(value int64, unit MonitorScheduleUnit) MonitorSchedule { + return intervalSchedule{ + Type: string(checkInScheduleTypeInterval), + Value: value, + Unit: string(unit), + } +} + +type MonitorConfig struct { //nolint: maligned // prefer readability over optimal memory layout + Schedule MonitorSchedule `json:"schedule,omitempty"` + // The allowed margin of minutes after the expected check-in time that + // the monitor will not be considered missed for. + CheckInMargin int64 `json:"checkin_margin,omitempty"` + // The allowed duration in minutes that the monitor may be `in_progress` + // for before being considered failed due to timeout. + MaxRuntime int64 `json:"max_runtime,omitempty"` + // A tz database string representing the timezone which the monitor's execution schedule is in. + // See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + Timezone string `json:"timezone,omitempty"` +} + +type CheckIn struct { //nolint: maligned // prefer readability over optimal memory layout + // Check-In ID (unique and client generated) + ID EventID `json:"check_in_id"` + // The distinct slug of the monitor. + MonitorSlug string `json:"monitor_slug"` + // The status of the check-in. + Status CheckInStatus `json:"status"` + // The duration of the check-in. Will only take effect if the status is ok or error. + Duration time.Duration `json:"duration,omitempty"` +} + +// serializedCheckIn is used by checkInMarshalJSON method on Event struct. +// See https://develop.sentry.dev/sdk/check-ins/ +type serializedCheckIn struct { //nolint: maligned + // Check-In ID (unique and client generated). + CheckInID string `json:"check_in_id"` + // The distinct slug of the monitor. + MonitorSlug string `json:"monitor_slug"` + // The status of the check-in. + Status CheckInStatus `json:"status"` + // The duration of the check-in in seconds. Will only take effect if the status is ok or error. + Duration float64 `json:"duration,omitempty"` + Release string `json:"release,omitempty"` + Environment string `json:"environment,omitempty"` + MonitorConfig *MonitorConfig `json:"monitor_config,omitempty"` +} diff --git a/vendor/github.com/getsentry/sentry-go/client.go b/vendor/github.com/getsentry/sentry-go/client.go index 41458d30..6a93fc14 100644 --- a/vendor/github.com/getsentry/sentry-go/client.go +++ b/vendor/github.com/getsentry/sentry-go/client.go @@ -413,6 +413,16 @@ func (client *Client) CaptureException(exception error, hint *EventHint, scope E return client.CaptureEvent(event, hint, scope) } +// CaptureCheckIn captures a check in. +func (client *Client) CaptureCheckIn(checkIn *CheckIn, monitorConfig *MonitorConfig, scope EventModifier) *EventID { + event := client.EventFromCheckIn(checkIn, monitorConfig) + if event != nil && event.CheckIn != nil { + client.CaptureEvent(event, nil, scope) + return &event.CheckIn.ID + } + return nil +} + // CaptureEvent captures an event on the currently active client if any. // // The event must already be assembled. Typically code would instead use @@ -524,6 +534,33 @@ func (client *Client) EventFromException(exception error, level Level) *Event { return event } +// EventFromCheckIn creates a new Sentry event from the given `check_in` instance. +func (client *Client) EventFromCheckIn(checkIn *CheckIn, monitorConfig *MonitorConfig) *Event { + if checkIn == nil { + return nil + } + + event := NewEvent() + event.Type = checkInType + + var checkInID EventID + if checkIn.ID == "" { + checkInID = EventID(uuid()) + } else { + checkInID = checkIn.ID + } + + event.CheckIn = &CheckIn{ + ID: checkInID, + MonitorSlug: checkIn.MonitorSlug, + Status: checkIn.Status, + Duration: checkIn.Duration, + } + event.MonitorConfig = monitorConfig + + return event +} + // reverse reverses the slice a in place. func reverse(a []Exception) { for i := len(a)/2 - 1; i >= 0; i-- { diff --git a/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go b/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go index 15b37e31..36507260 100644 --- a/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go +++ b/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go @@ -82,6 +82,12 @@ func DynamicSamplingContextFromTransaction(span *Span) DynamicSamplingContext { entries["user_segment"] = userSegment } + if span.Sampled.Bool() { + entries["sampled"] = "true" + } else { + entries["sampled"] = "false" + } + return DynamicSamplingContext{ Entries: entries, Frozen: true, diff --git a/vendor/github.com/getsentry/sentry-go/hub.go b/vendor/github.com/getsentry/sentry-go/hub.go index ee252be4..6af1d5af 100644 --- a/vendor/github.com/getsentry/sentry-go/hub.go +++ b/vendor/github.com/getsentry/sentry-go/hub.go @@ -267,6 +267,18 @@ func (hub *Hub) CaptureException(exception error) *EventID { return eventID } +// CaptureCheckIn calls the method of the same name on currently bound Client instance +// passing it a top-level Scope. +// Returns CheckInID if the check-in was captured successfully, or nil otherwise. +func (hub *Hub) CaptureCheckIn(checkIn *CheckIn, monitorConfig *MonitorConfig) *EventID { + client, scope := hub.Client(), hub.Scope() + if client == nil { + return nil + } + + return client.CaptureCheckIn(checkIn, monitorConfig, scope) +} + // AddBreadcrumb records a new breadcrumb. // // The total number of breadcrumbs that can be recorded are limited by the diff --git a/vendor/github.com/getsentry/sentry-go/interfaces.go b/vendor/github.com/getsentry/sentry-go/interfaces.go index 4a75ec27..49779288 100644 --- a/vendor/github.com/getsentry/sentry-go/interfaces.go +++ b/vendor/github.com/getsentry/sentry-go/interfaces.go @@ -22,6 +22,9 @@ const eventType = "event" const profileType = "profile" +// checkInType is the type of a check in event. +const checkInType = "check_in" + // Level marks the severity of the event. type Level string @@ -105,6 +108,14 @@ func (b *Breadcrumb) MarshalJSON() ([]byte, error) { return json.Marshal((*breadcrumb)(b)) } +// Attachment allows associating files with your events to aid in investigation. +// An event may contain one or more attachments. +type Attachment struct { + Filename string + ContentType string + Payload []byte +} + // User describes the user associated with an Event. If this is used, at least // an ID or an IP address should be provided. type User struct { @@ -315,9 +326,15 @@ type Event struct { Spans []*Span `json:"spans,omitempty"` TransactionInfo *TransactionInfo `json:"transaction_info,omitempty"` + // The fields below are only relevant for crons/check ins + + CheckIn *CheckIn `json:"check_in,omitempty"` + MonitorConfig *MonitorConfig `json:"monitor_config,omitempty"` + // The fields below are not part of the final JSON payload. sdkMetaData SDKMetaData + attachments []*Attachment } // SetException appends the unwrapped errors to the event's exception list. @@ -375,6 +392,8 @@ func (e *Event) MarshalJSON() ([]byte, error) { // and a few type tricks. if e.Type == transactionType { return e.transactionMarshalJSON() + } else if e.Type == checkInType { + return e.checkInMarshalJSON() } return e.defaultMarshalJSON() } @@ -449,6 +468,29 @@ func (e *Event) transactionMarshalJSON() ([]byte, error) { return json.Marshal(x) } +func (e *Event) checkInMarshalJSON() ([]byte, error) { + checkIn := serializedCheckIn{ + CheckInID: string(e.CheckIn.ID), + MonitorSlug: e.CheckIn.MonitorSlug, + Status: e.CheckIn.Status, + Duration: e.CheckIn.Duration.Seconds(), + Release: e.Release, + Environment: e.Environment, + MonitorConfig: nil, + } + + if e.MonitorConfig != nil { + checkIn.MonitorConfig = &MonitorConfig{ + Schedule: e.MonitorConfig.Schedule, + CheckInMargin: e.MonitorConfig.CheckInMargin, + MaxRuntime: e.MonitorConfig.MaxRuntime, + Timezone: e.MonitorConfig.Timezone, + } + } + + return json.Marshal(checkIn) +} + // NewEvent creates a new Event. func NewEvent() *Event { event := Event{ diff --git a/vendor/github.com/getsentry/sentry-go/scope.go b/vendor/github.com/getsentry/sentry-go/scope.go index 52cb7619..2f961bad 100644 --- a/vendor/github.com/getsentry/sentry-go/scope.go +++ b/vendor/github.com/getsentry/sentry-go/scope.go @@ -25,6 +25,7 @@ import ( type Scope struct { mu sync.RWMutex breadcrumbs []*Breadcrumb + attachments []*Attachment user User tags map[string]string contexts map[string]Context @@ -48,6 +49,7 @@ type Scope struct { func NewScope() *Scope { scope := Scope{ breadcrumbs: make([]*Breadcrumb, 0), + attachments: make([]*Attachment, 0), tags: make(map[string]string), contexts: make(map[string]Context), extra: make(map[string]interface{}), @@ -81,6 +83,22 @@ func (scope *Scope) ClearBreadcrumbs() { scope.breadcrumbs = []*Breadcrumb{} } +// AddAttachment adds new attachment to the current scope. +func (scope *Scope) AddAttachment(attachment *Attachment) { + scope.mu.Lock() + defer scope.mu.Unlock() + + scope.attachments = append(scope.attachments, attachment) +} + +// ClearAttachments clears all attachments from the current scope. +func (scope *Scope) ClearAttachments() { + scope.mu.Lock() + defer scope.mu.Unlock() + + scope.attachments = []*Attachment{} +} + // SetUser sets the user for the current scope. func (scope *Scope) SetUser(user User) { scope.mu.Lock() @@ -283,6 +301,8 @@ func (scope *Scope) Clone() *Scope { clone.user = scope.user clone.breadcrumbs = make([]*Breadcrumb, len(scope.breadcrumbs)) copy(clone.breadcrumbs, scope.breadcrumbs) + clone.attachments = make([]*Attachment, len(scope.attachments)) + copy(clone.attachments, scope.attachments) for key, value := range scope.tags { clone.tags[key] = value } @@ -323,6 +343,10 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event { event.Breadcrumbs = append(event.Breadcrumbs, scope.breadcrumbs...) } + if len(scope.attachments) > 0 { + event.attachments = append(event.attachments, scope.attachments...) + } + if len(scope.tags) > 0 { if event.Tags == nil { event.Tags = make(map[string]string, len(scope.tags)) diff --git a/vendor/github.com/getsentry/sentry-go/sentry.go b/vendor/github.com/getsentry/sentry-go/sentry.go index fe8940b9..f5b3a6d1 100644 --- a/vendor/github.com/getsentry/sentry-go/sentry.go +++ b/vendor/github.com/getsentry/sentry-go/sentry.go @@ -9,7 +9,7 @@ import ( const Version = SDKVersion // Version is the version of the SDK. -const SDKVersion = "0.22.0" +const SDKVersion = "0.23.0" // The identifier of the SDK. const SDKIdentifier = "sentry.go" @@ -54,6 +54,12 @@ func CaptureException(exception error) *EventID { return hub.CaptureException(exception) } +// CaptureCheckIn captures a (cron) monitor check-in. +func CaptureCheckIn(checkIn *CheckIn, monitorConfig *MonitorConfig) *EventID { + hub := CurrentHub() + return hub.CaptureCheckIn(checkIn, monitorConfig) +} + // CaptureEvent captures an event on the currently active client if any. // // The event must already be assembled. Typically code would instead use diff --git a/vendor/github.com/getsentry/sentry-go/tracing.go b/vendor/github.com/getsentry/sentry-go/tracing.go index 8466bacc..38b810c0 100644 --- a/vendor/github.com/getsentry/sentry-go/tracing.go +++ b/vendor/github.com/getsentry/sentry-go/tracing.go @@ -60,6 +60,8 @@ type Span struct { //nolint: maligned // prefer readability over optimal memory contexts map[string]Context // profiler instance if attached, nil otherwise. profiler transactionProfiler + // a Once instance to make sure that Finish() is only called once. + finishOnce sync.Once } // TraceParentContext describes the context of a (remote) parent span. @@ -196,35 +198,11 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp // Finish sets the span's end time, unless already set. If the span is the root // of a span tree, Finish sends the span tree to Sentry as a transaction. +// +// The logic is executed at most once per span, so that (incorrectly) calling it twice +// never double sends to Sentry. func (s *Span) Finish() { - // TODO(tracing): maybe make Finish run at most once, such that - // (incorrectly) calling it twice never double sends to Sentry. - - // For the timing to be correct, the profiler must be stopped before s.EndTime. - var profile *profileInfo - if s.profiler != nil { - profile = s.profiler.Finish(s) - } - - if s.EndTime.IsZero() { - s.EndTime = monotonicTimeSince(s.StartTime) - } - - if !s.Sampled.Bool() { - return - } - event := s.toEvent() - if event == nil { - return - } - - event.sdkMetaData.transactionProfile = profile - - // TODO(tracing): add breadcrumbs - // (see https://github.com/getsentry/sentry-python/blob/f6f3525f8812f609/sentry_sdk/tracing.py#L372) - - hub := hubFromContext(s.ctx) - hub.CaptureEvent(event) + s.finishOnce.Do(s.doFinish) } // Context returns the context containing the span. @@ -353,6 +331,35 @@ func (s *Span) SetDynamicSamplingContext(dsc DynamicSamplingContext) { } } +// doFinish runs the actual Span.Finish() logic. +func (s *Span) doFinish() { + // For the timing to be correct, the profiler must be stopped before s.EndTime. + var profile *profileInfo + if s.profiler != nil { + profile = s.profiler.Finish(s) + } + + if s.EndTime.IsZero() { + s.EndTime = monotonicTimeSince(s.StartTime) + } + + if !s.Sampled.Bool() { + return + } + event := s.toEvent() + if event == nil { + return + } + + event.sdkMetaData.transactionProfile = profile + + // TODO(tracing): add breadcrumbs + // (see https://github.com/getsentry/sentry-python/blob/f6f3525f8812f609/sentry_sdk/tracing.py#L372) + + hub := hubFromContext(s.ctx) + hub.CaptureEvent(event) +} + // sentryTracePattern matches either // // TRACE_ID - SPAN_ID @@ -949,27 +956,9 @@ func TransactionFromContext(ctx context.Context) *Span { return nil } -// spanFromContext returns the last span stored in the context or a dummy -// non-nil span. -// -// TODO(tracing): consider exporting this. Without this, users cannot retrieve a -// span from a context since spanContextKey is not exported. -// -// This can be added retroactively, and in the meantime think better whether it -// should return nil (like GetHubFromContext), always non-nil (like -// HubFromContext), or both: two exported functions. -// -// Note the equivalence: -// -// SpanFromContext(ctx).StartChild(...) === StartSpan(ctx, ...) -// -// So we don't aim spanFromContext at creating spans, but mutating existing -// spans that you'd have no access otherwise (because it was created in code you -// do not control, for example SDK auto-instrumentation). -// -// For now we provide TransactionFromContext, which solves the more common case -// of setting tags, etc, on the current transaction. -func spanFromContext(ctx context.Context) *Span { +// SpanFromContext returns the last span stored in the context, or nil if no span +// is set on the context. +func SpanFromContext(ctx context.Context) *Span { if span, ok := ctx.Value(spanContextKey{}).(*Span); ok { return span } diff --git a/vendor/github.com/getsentry/sentry-go/transport.go b/vendor/github.com/getsentry/sentry-go/transport.go index d8bdf2a7..b1be4421 100644 --- a/vendor/github.com/getsentry/sentry-go/transport.go +++ b/vendor/github.com/getsentry/sentry-go/transport.go @@ -94,6 +94,38 @@ func getRequestBodyFromEvent(event *Event) []byte { return nil } +func encodeAttachment(enc *json.Encoder, b io.Writer, attachment *Attachment) error { + // Attachment header + err := enc.Encode(struct { + Type string `json:"type"` + Length int `json:"length"` + Filename string `json:"filename"` + ContentType string `json:"content_type,omitempty"` + }{ + Type: "attachment", + Length: len(attachment.Payload), + Filename: attachment.Filename, + ContentType: attachment.ContentType, + }) + if err != nil { + return err + } + + // Attachment payload + if _, err = b.Write(attachment.Payload); err != nil { + return err + } + + // "Envelopes should be terminated with a trailing newline." + // + // [1]: https://develop.sentry.dev/sdk/envelopes/#envelopes + if _, err := b.Write([]byte("\n")); err != nil { + return err + } + + return nil +} + func encodeEnvelopeItem(enc *json.Encoder, itemType string, body json.RawMessage) error { // Item header err := enc.Encode(struct { @@ -143,8 +175,8 @@ func envelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body json.RawMes return nil, err } - if event.Type == transactionType { - err = encodeEnvelopeItem(enc, transactionType, body) + if event.Type == transactionType || event.Type == checkInType { + err = encodeEnvelopeItem(enc, event.Type, body) } else { err = encodeEnvelopeItem(enc, eventType, body) } @@ -152,6 +184,13 @@ func envelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body json.RawMes return nil, err } + // Attachments + for _, attachment := range event.attachments { + if err := encodeAttachment(enc, &b, attachment); err != nil { + return nil, err + } + } + // Profile data if event.sdkMetaData.transactionProfile != nil { body, err = json.Marshal(event.sdkMetaData.transactionProfile) diff --git a/vendor/modules.txt b/vendor/modules.txt index 8ac0d81e..03dedede 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -7,7 +7,7 @@ github.com/cespare/xxhash/v2 # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/getsentry/sentry-go v0.22.0 +# github.com/getsentry/sentry-go v0.23.0 ## explicit; go 1.18 github.com/getsentry/sentry-go github.com/getsentry/sentry-go/internal/debug