Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Event.Attachments #771

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestCaptureMessageEmptyString(t *testing.T) {
}
got := transport.lastEvent
opts := cmp.Options{
cmpopts.IgnoreFields(Event{}, "sdkMetaData", "attachments"),
cmpopts.IgnoreFields(Event{}, "sdkMetaData"),
cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Exception: e.Exception,
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestCaptureEvent(t *testing.T) {
},
}
got := transport.lastEvent
opts := cmp.Options{cmpopts.IgnoreFields(Event{}, "Release", "sdkMetaData", "attachments")}
opts := cmp.Options{cmpopts.IgnoreFields(Event{}, "Release", "sdkMetaData")}
if diff := cmp.Diff(want, got, opts); diff != "" {
t.Errorf("Event mismatch (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -315,7 +315,7 @@ func TestCaptureEventNil(t *testing.T) {
}
got := transport.lastEvent
opts := cmp.Options{
cmpopts.IgnoreFields(Event{}, "sdkMetaData", "attachments"),
cmpopts.IgnoreFields(Event{}, "sdkMetaData"),
cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Exception: e.Exception,
Expand Down Expand Up @@ -763,7 +763,7 @@ func TestRecover(t *testing.T) {
}
got := events[0]
opts := cmp.Options{
cmpopts.IgnoreFields(Event{}, "sdkMetaData", "attachments"),
cmpopts.IgnoreFields(Event{}, "sdkMetaData"),
cmp.Transformer("SimplifiedEvent", func(e *Event) *Event {
return &Event{
Message: e.Message,
Expand Down
2 changes: 1 addition & 1 deletion fasthttp/sentryfasthttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestIntegration(t *testing.T) {
sentry.Event{},
"Contexts", "EventID", "Extra", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Tags", "Timestamp",
"sdkMetaData", "attachments",
"sdkMetaData",
),
cmpopts.IgnoreMapEntries(func(k string, v string) bool {
// fasthttp changed Content-Length behavior in
Expand Down
4 changes: 2 additions & 2 deletions gin/sentrygin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func TestIntegration(t *testing.T) {
sentry.Event{},
"Contexts", "EventID", "Extra", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Tags", "Timestamp",
"sdkMetaData", "attachments",
"sdkMetaData",
),
cmpopts.IgnoreFields(
sentry.Request{},
Expand All @@ -387,7 +387,7 @@ func TestIntegration(t *testing.T) {
sentry.Event{},
"Contexts", "EventID", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Timestamp",
"sdkMetaData", "StartTime", "Spans", "attachments",
"sdkMetaData", "StartTime", "Spans",
),
cmpopts.IgnoreFields(
sentry.Request{},
Expand Down
2 changes: 1 addition & 1 deletion http/sentryhttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestIntegration(t *testing.T) {
sentry.Event{},
"Contexts", "EventID", "Extra", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Tags", "Timestamp",
"sdkMetaData", "attachments",
"sdkMetaData",
),
cmpopts.IgnoreFields(
sentry.Request{},
Expand Down
2 changes: 1 addition & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ type Event struct {
Request *Request `json:"request,omitempty"`
Exception []Exception `json:"exception,omitempty"`
DebugMeta *DebugMeta `json:"debug_meta,omitempty"`
Attachments []*Attachment `json:"-"`

// The fields below are only relevant for transactions.

Expand All @@ -333,7 +334,6 @@ type Event struct {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion logrus/logrusentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func Test_entryToEvent(t *testing.T) {
got := h.entryToEvent(tt.entry)
opts := cmp.Options{
cmpopts.IgnoreFields(sentry.Event{},
"sdkMetaData", "attachments",
"sdkMetaData",
),
}
if d := cmp.Diff(tt.want, got, opts); d != "" {
Expand Down
2 changes: 1 addition & 1 deletion scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint) *Event {
}

if len(scope.attachments) > 0 {
event.attachments = append(event.attachments, scope.attachments...)
event.Attachments = append(event.Attachments, scope.attachments...)
}

if len(scope.tags) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func fillScopeWithData(scope *Scope) *Scope {

func fillEventWithData(event *Event) *Event {
event.Breadcrumbs = []*Breadcrumb{{Timestamp: testNow, Message: "eventBreadcrumbMessage"}}
event.attachments = []*Attachment{
event.Attachments = []*Attachment{
{
Filename: "event-attachment.txt",
Payload: []byte("Event attachment contents."),
Expand Down Expand Up @@ -573,7 +573,7 @@ func TestApplyToEventWithCorrectScopeAndEvent(t *testing.T) {
processedEvent := scope.ApplyToEvent(event, nil)

assertEqual(t, len(processedEvent.Breadcrumbs), 2, "should merge breadcrumbs")
assertEqual(t, len(processedEvent.attachments), 2, "should merge attachments")
assertEqual(t, len(processedEvent.Attachments), 2, "should merge attachments")
assertEqual(t, len(processedEvent.Tags), 2, "should merge tags")
assertEqual(t, len(processedEvent.Contexts), 3, "should merge contexts")
assertEqual(t, event.Contexts[sharedContextsKey], event.Contexts[sharedContextsKey], "should not override event context")
Expand All @@ -591,7 +591,7 @@ func TestApplyToEventUsingEmptyScope(t *testing.T) {
processedEvent := scope.ApplyToEvent(event, nil)

assertEqual(t, len(processedEvent.Breadcrumbs), 1, "should use event breadcrumbs")
assertEqual(t, len(processedEvent.attachments), 1, "should use event attachments")
assertEqual(t, len(processedEvent.Attachments), 1, "should use event attachments")
assertEqual(t, len(processedEvent.Tags), 1, "should use event tags")
assertEqual(t, len(processedEvent.Contexts), 2, "should use event contexts")
assertEqual(t, len(processedEvent.Extra), 1, "should use event extra")
Expand All @@ -608,7 +608,7 @@ func TestApplyToEventUsingEmptyEvent(t *testing.T) {
processedEvent := scope.ApplyToEvent(event, nil)

assertEqual(t, len(processedEvent.Breadcrumbs), 1, "should use scope breadcrumbs")
assertEqual(t, len(processedEvent.attachments), 1, "should use scope attachments")
assertEqual(t, len(processedEvent.Attachments), 1, "should use scope attachments")
assertEqual(t, len(processedEvent.Tags), 1, "should use scope tags")
assertEqual(t, len(processedEvent.Contexts), 2, "should use scope contexts")
assertEqual(t, len(processedEvent.Extra), 1, "should use scope extra")
Expand Down
6 changes: 3 additions & 3 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestStartSpan(t *testing.T) {
cmpopts.IgnoreFields(Event{},
"Contexts", "EventID", "Level", "Platform",
"Release", "Sdk", "ServerName", "Modules",
"sdkMetaData", "attachments",
"sdkMetaData",
),
cmpopts.EquateEmpty(),
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestStartChild(t *testing.T) {
cmpopts.IgnoreFields(Event{},
"EventID", "Level", "Platform", "Modules",
"Release", "Sdk", "ServerName", "Timestamp", "StartTime",
"sdkMetaData", "attachments",
"sdkMetaData",
),
cmpopts.IgnoreMapEntries(func(k string, v interface{}) bool {
return k != "trace"
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestStartTransaction(t *testing.T) {
cmpopts.IgnoreFields(Event{},
"Contexts", "EventID", "Level", "Platform",
"Release", "Sdk", "ServerName", "Modules",
"sdkMetaData", "attachments",
"sdkMetaData",
),
cmpopts.EquateEmpty(),
}
Expand Down
2 changes: 1 addition & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func envelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body json.RawMes
}

// Attachments
for _, attachment := range event.attachments {
for _, attachment := range event.Attachments {
if err := encodeAttachment(enc, &b, attachment); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestEnvelopeFromTransactionBody(t *testing.T) {

func TestEnvelopeFromEventWithAttachments(t *testing.T) {
event := newTestEvent(eventType)
event.attachments = []*Attachment{
event.Attachments = []*Attachment{
// Empty content-type and payload
{
Filename: "empty.txt",
Expand Down