Skip to content

Event ingestion: Mechanism.Type is missing #896

@ioxenus

Description

@ioxenus

In Sentry's docs on event payloads - exception mechanism it says that the "type" attribute is required.

However, sentry-go v0.29.1 sometimes sends an event that has mechanism included, but the type is omitted.

Reproduction:

mkdir issue350
cd issue350
go mod init issue350
go get github.com/getsentry/sentry-go@v0.29.1
touch test.txt
chmod 407 test.txt

main.go:

package main

import (
	"os"
	"time"

	sentry "github.com/getsentry/sentry-go"
)

func main() {
	sentry.Init(sentry.ClientOptions{
		Dsn:              "https://foo@bar.baz/1",
		Debug:            true,
	})

	defer func() {
		if err := recover(); err != nil {
			sentry.CurrentHub().Recover(err)
			sentry.Flush(time.Second * 5)
		}
	}()

	if err := os.WriteFile("test.txt", []byte("foobar"), 0666); err != nil {
		panic(err)
	}
}

It yields such a JSON payload:

"exception": [
    {
        "type": "syscall.Errno",
        "value": "permission denied",
        "mechanism":{
            "exception_id": 0, 
            "is_exception_group": true
        }
    },
    {
        "type":"*fs.PathError",
        "value":"open test.txt: permission denied",
        "stacktrace": ...
        ...
    }
]

Maybe it'd be better to remove json:"type,omitempty" from Mechanism.Type?

————

I solved that myself by adding such a BeforeSend to sentry.ClientOptions:

sentry_err := sentry.Init(sentry.ClientOptions{
	Dsn: "https://foo@bar.baz/1",
	Debug: true,

	BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
		for _, x := range event.Exception {
			if x.Mechanism != nil && x.Mechanism.Type == "" {
				x.Mechanism.Type = "foobar"
			}
		}
		return event
	},
})

(can also be done with sentry.ConfigureScope and scope.AddEventProcessor)

Metadata

Metadata

Assignees

Labels

BugIssue type
No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions