/usr/share/gocode/src/github.com/bugsnag/bugsnag-go/event.go is in golang-github-bugsnag-bugsnag-go-dev 1.0.5+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | package bugsnag
import (
"strings"
"github.com/bugsnag/bugsnag-go/errors"
)
// Context is the context of the error in Bugsnag.
// This can be passed to Notify, Recover or AutoNotify as rawData.
type Context struct {
String string
}
// User represents the searchable user-data on Bugsnag. The Id is also used
// to determine the number of users affected by a bug. This can be
// passed to Notify, Recover or AutoNotify as rawData.
type User struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
}
// ErrorClass overrides the error class in Bugsnag.
// This struct enables you to group errors as you like.
type ErrorClass struct {
Name string
}
// Sets the severity of the error on Bugsnag. These values can be
// passed to Notify, Recover or AutoNotify as rawData.
var (
SeverityError = severity{"error"}
SeverityWarning = severity{"warning"}
SeverityInfo = severity{"info"}
)
// The severity tag type, private so that people can only use Error,Warning,Info
type severity struct {
String string
}
// The form of stacktrace that Bugsnag expects
type stackFrame struct {
Method string `json:"method"`
File string `json:"file"`
LineNumber int `json:"lineNumber"`
InProject bool `json:"inProject,omitempty"`
}
// Event represents a payload of data that gets sent to Bugsnag.
// This is passed to each OnBeforeNotify hook.
type Event struct {
// The original error that caused this event, not sent to Bugsnag.
Error *errors.Error
// The rawData affecting this error, not sent to Bugsnag.
RawData []interface{}
// The error class to be sent to Bugsnag. This defaults to the type name of the Error, for
// example *error.String
ErrorClass string
// The error message to be sent to Bugsnag. This defaults to the return value of Error.Error()
Message string
// The stacktrrace of the error to be sent to Bugsnag.
Stacktrace []stackFrame
// The context to be sent to Bugsnag. This should be set to the part of the app that was running,
// e.g. for http requests, set it to the path.
Context string
// The severity of the error. Can be SeverityError, SeverityWarning or SeverityInfo.
Severity severity
// The grouping hash is used to override Bugsnag's grouping. Set this if you'd like all errors with
// the same grouping hash to group together in the dashboard.
GroupingHash string
// User data to send to Bugsnag. This is searchable on the dashboard.
User *User
// Other MetaData to send to Bugsnag. Appears as a set of tabbed tables in the dashboard.
MetaData MetaData
}
func newEvent(err *errors.Error, rawData []interface{}, notifier *Notifier) (*Event, *Configuration) {
config := notifier.Config
event := &Event{
Error: err,
RawData: append(notifier.RawData, rawData...),
ErrorClass: err.TypeName(),
Message: err.Error(),
Stacktrace: make([]stackFrame, len(err.StackFrames())),
Severity: SeverityWarning,
MetaData: make(MetaData),
}
for _, datum := range event.RawData {
switch datum := datum.(type) {
case severity:
event.Severity = datum
case Context:
event.Context = datum.String
case Configuration:
config = config.merge(&datum)
case MetaData:
event.MetaData.Update(datum)
case User:
event.User = &datum
case ErrorClass:
event.ErrorClass = datum.Name
}
}
for i, frame := range err.StackFrames() {
file := frame.File
inProject := config.isProjectPackage(frame.Package)
// remove $GOROOT and $GOHOME from other frames
if idx := strings.Index(file, frame.Package); idx > -1 {
file = file[idx:]
}
if inProject {
file = config.stripProjectPackages(file)
}
event.Stacktrace[i] = stackFrame{
Method: frame.Name,
File: file,
LineNumber: frame.LineNumber,
InProject: inProject,
}
}
return event, config
}
|