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

Event ingestion: Mechanism.Type is missing #896

Closed
ioxenus opened this issue Oct 27, 2024 · 3 comments · Fixed by #897
Closed

Event ingestion: Mechanism.Type is missing #896

ioxenus opened this issue Oct 27, 2024 · 3 comments · Fixed by #897
Assignees

Comments

@ioxenus
Copy link

ioxenus commented Oct 27, 2024

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/[email protected]
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://[email protected]/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://[email protected]/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)

@ribice
Copy link
Collaborator

ribice commented Oct 27, 2024

You are right, this Type is never set. Currently IsExceptionGroup, ExceptionID and ParentID are used in Mechanism. I'll see what can we set for Type.

@ribice
Copy link
Collaborator

ribice commented Oct 27, 2024

@cleptric I inspected other SDKs for this - for example in the javascript one it either sets this type as generic, angular, cloudflare.

The easiest way to resolve it would be to set it to generic, or copy the same Type from Exception (which may serve no purpose, but might be better than generic?).

@cleptric
Copy link
Member

Just using generic is fine.

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

Successfully merging a pull request may close this issue.

4 participants