{"action":"created","issue":{"url":"https://api.github.com/repos/getsentry/raven-go/issues/88","repository_url":"https://api.github.com/repos/getsentry/raven-go","labels_url":"https://api.github.com/repos/getsentry/raven-go/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/getsentry/raven-go/issues/88/comments","events_url":"https://api.github.com/repos/getsentry/raven-go/issues/88/events","html_url":"https://github.com/getsentry/raven-go/issues/88","id":163791149,"number":88,"title":"Do you support github.com/pkg/errors stacktrace ?","user":{"login":"pierrre","id":131535,"avatar_url":"https://avatars.githubusercontent.com/u/131535?v=3","gravatar_id":"","url":"https://api.github.com/users/pierrre","html_url":"https://github.com/pierrre","followers_url":"https://api.github.com/users/pierrre/followers","following_url":"https://api.github.com/users/pierrre/following{/other_user}","gists_url":"https://api.github.com/users/pierrre/gists{/gist_id}","starred_url":"https://api.github.com/users/pierrre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pierrre/subscriptions","organizations_url":"https://api.github.com/users/pierrre/orgs","repos_url":"https://api.github.com/users/pierrre/repos","events_url":"https://api.github.com/users/pierrre/events{/privacy}","received_events_url":"https://api.github.com/users/pierrre/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-05T07:52:34Z","updated_at":"2016-07-11T15:21:08Z","closed_at":null,"body":"In go, errors don't have a stacktrace.\r\nErrors reported with Sentry/raven-go show the stacktrace of the `Capture` call, instead of where the errors come from.\r\n\r\nThe `github.com/pkg/errors` package adds stack trace to Go errors. (you must wrap all errors with `errors.Wrap`)\r\nI don't think you currently support the stacktrace format of this package.\r\nDo you plan to support it?"},"comment":{"url":"https://api.github.com/repos/getsentry/raven-go/issues/comments/231767420","html_url":"https://github.com/getsentry/raven-go/issues/88#issuecomment-231767420","issue_url":"https://api.github.com/repos/getsentry/raven-go/issues/88","id":231767420,"user":{"login":"pierrre","id":131535,"avatar_url":"https://avatars.githubusercontent.com/u/131535?v=3","gravatar_id":"","url":"https://api.github.com/users/pierrre","html_url":"https://github.com/pierrre","followers_url":"https://api.github.com/users/pierrre/followers","following_url":"https://api.github.com/users/pierrre/following{/other_user}","gists_url":"https://api.github.com/users/pierrre/gists{/gist_id}","starred_url":"https://api.github.com/users/pierrre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pierrre/subscriptions","organizations_url":"https://api.github.com/users/pierrre/orgs","repos_url":"https://api.github.com/users/pierrre/repos","events_url":"https://api.github.com/users/pierrre/events{/privacy}","received_events_url":"https://api.github.com/users/pierrre/received_events","type":"User","site_admin":false},"created_at":"2016-07-11T15:21:08Z","updated_at":"2016-07-11T15:21:08Z","body":"Hello!\r\n\r\nHere is the code I plan to use.\r\nIt works as a replacement for github.com/getsentry/raven-go.CaptureError*.\r\n\r\nIf we want to integrate it to `raven-go` directly, I think we should:\r\n- write another package that exposes `getErrorStackTraceConverted()`\r\n- allow to register an \"error to stacktrace\" converter\r\n\r\nBy the way, I also fixed:\r\n- the \"skip\" issue https://github.com/getsentry/raven-go/issues/91\r\n- all `Capture*` methods now return an `error` or a `<- chan error` (to be consistent with `Client.Capture`)\r\n\r\n```go\r\n// Package ravenerrors adds support for github.com/pkg/errors's stacktrace to github.com/getsentry/raven-go.\r\n//\r\n// It works as a replacement for github.com/getsentry/raven-go.CaptureError*.\r\n// Stacktraces are extracted from the error if available and replace raven's default behavior.\r\npackage ravenerrors\r\n\r\nimport (\r\n\t\"runtime\"\r\n\r\n\t\"github.com/getsentry/raven-go\"\r\n\t\"github.com/pkg/errors\"\r\n)\r\n\r\n// Capture is a replacement for github.com/getsentry/raven-go.CaptureError.\r\nfunc Capture(err error, tags map[string]string, interfaces ...raven.Interface) (string, <-chan error) {\r\n\treturn captureError(raven.DefaultClient, err, tags, interfaces...)\r\n}\r\n\r\n// CaptureWithClient is a replacement for github.com/getsentry/raven-go.Client.CaptureError.\r\nfunc CaptureWithClient(client *raven.Client, err error, tags map[string]string, interfaces ...raven.Interface) (string, <-chan error) {\r\n\treturn captureError(client, err, tags, interfaces...)\r\n}\r\n\r\n// CaptureAndWait is a replacement for github.com/getsentry/raven-go.CaptureErrorAndWait.\r\nfunc CaptureAndWait(err error, tags map[string]string, interfaces ...raven.Interface) (string, error) {\r\n\teventID, errch := captureError(raven.DefaultClient, err, tags, interfaces...)\r\n\terr2 := <-errch\r\n\treturn eventID, err2\r\n}\r\n\r\n// CaptureAndWaitWithClient is a replacement for github.com/getsentry/raven-go.Client.CaptureErrorAndWait.\r\nfunc CaptureAndWaitWithClient(client *raven.Client, err error, tags map[string]string, interfaces ...raven.Interface) (string, error) {\r\n\teventID, errch := captureError(client, err, tags, interfaces...)\r\n\terr2 := <-errch\r\n\treturn eventID, err2\r\n}\r\n\r\nfunc captureError(client *raven.Client, err error, tags map[string]string, interfaces ...raven.Interface) (string, <-chan error) {\r\n\tst := getErrorStackTraceConverted(err, 3, client.IncludePaths())\r\n\tif st == nil {\r\n\t\tst = raven.NewStacktrace(2, 3, client.IncludePaths())\r\n\t}\r\n\tex := raven.NewException(err, st)\r\n\tpacket := raven.NewPacket(err.Error(), append(interfaces, ex)...)\r\n\treturn client.Capture(packet, tags)\r\n}\r\n\r\nfunc getErrorStackTraceConverted(err error, context int, appPackagePrefixes []string) *raven.Stacktrace {\r\n\tst := getErrorCauseStackTrace(err)\r\n\tif st == nil {\r\n\t\treturn nil\r\n\t}\r\n\treturn convertStackTrace(st, context, appPackagePrefixes)\r\n}\r\n\r\nfunc getErrorCauseStackTrace(err error) errors.StackTrace {\r\n\t// This code is inspired by github.com/pkg/errors.Cause().\r\n\tvar st errors.StackTrace\r\n\tfor err != nil {\r\n\t\ts := getErrorStackTrace(err)\r\n\t\tif s != nil {\r\n\t\t\tst = s\r\n\t\t}\r\n\t\terr = getErrorCause(err)\r\n\t}\r\n\treturn st\r\n}\r\n\r\nfunc getErrorStackTrace(err error) errors.StackTrace {\r\n\tster, ok := err.(interface {\r\n\t\tStackTrace() errors.StackTrace\r\n\t})\r\n\tif !ok {\r\n\t\treturn nil\r\n\t}\r\n\treturn ster.StackTrace()\r\n}\r\n\r\nfunc getErrorCause(err error) error {\r\n\tcer, ok := err.(interface {\r\n\t\tCause() error\r\n\t})\r\n\tif !ok {\r\n\t\treturn nil\r\n\t}\r\n\treturn cer.Cause()\r\n}\r\n\r\nfunc convertStackTrace(st errors.StackTrace, context int, appPackagePrefixes []string) *raven.Stacktrace {\r\n\t// This code is borrowed from github.com/getsentry/raven-go.NewStacktrace().\r\n\tvar frames []*raven.StacktraceFrame\r\n\tfor _, f := range st {\r\n\t\tframe := convertFrame(f, context, appPackagePrefixes)\r\n\t\tif frame != nil {\r\n\t\t\tframes = append(frames, frame)\r\n\t\t}\r\n\t}\r\n\tif len(frames) == 0 {\r\n\t\treturn nil\r\n\t}\r\n\tfor i, j := 0, len(frames)-1; i < j; i, j = i+1, j-1 {\r\n\t\tframes[i], frames[j] = frames[j], frames[i]\r\n\t}\r\n\treturn &raven.Stacktrace{Frames: frames}\r\n}\r\n\r\nfunc convertFrame(f errors.Frame, context int, appPackagePrefixes []string) *raven.StacktraceFrame {\r\n\t// This code is borrowed from github.com/pkg/errors.Frame.\r\n\tpc := uintptr(f) - 1\r\n\tfn := runtime.FuncForPC(pc)\r\n\tvar file string\r\n\tvar line int\r\n\tif fn != nil {\r\n\t\tfile, line = fn.FileLine(pc)\r\n\t} else {\r\n\t\tfile = \"unknown\"\r\n\t}\r\n\treturn raven.NewStacktraceFrame(pc, file, line, context, appPackagePrefixes)\r\n}\r\n```"}}
{"actor":{"display_login":"pierrre"}}