コード例 #1
0
ファイル: hb.go プロジェクト: carriercomm/empire
// NewReport generates a new honeybadger report from an error.
func NewReport(err error) *Report {
	r := &Report{
		Notifier: &Notifier{
			Name:     "Honeybadger (Go)",
			Url:      "https://github.com/remind101/pkg/reporter/hb",
			Version:  "0.1",
			Language: "Go",
		},
		Error: &Error{
			Class:     util.ClassName(err),
			Message:   err.Error(),
			Backtrace: make([]*BacktraceLine, 0),
			Source:    make(map[string]interface{}),
		},
		Request: &Request{
			Params:  make(map[string]interface{}),
			Session: make(map[string]interface{}),
			CgiData: make(map[string]interface{}),
			Context: make(map[string]interface{}),
		},
		Server: &Server{
			ProjectRoot: make(map[string]interface{}),
		},
	}

	if e, ok := err.(*reporter.Error); ok {
		r.Error.Class = util.ClassName(e.Err)

		for _, l := range e.Backtrace {
			r.Error.Backtrace = append(r.Error.Backtrace, &BacktraceLine{
				Method: util.FunctionName(l.PC),
				File:   l.File,
				Number: fmt.Sprintf("%d", l.Line),
			})
		}

		if e.Request != nil {
			r.Request.Url = e.Request.URL.String()

			for header, values := range e.Request.Header {
				if _, ok := IgnoredHeaders[header]; ok {
					continue
				}

				h := strings.Replace(strings.ToUpper(header), "-", "_", -1)
				r.Request.CgiData["HTTP_"+h] = values
			}

			r.Request.CgiData["REQUEST_METHOD"] = e.Request.Method
		}

		for key, value := range e.Context {
			r.Request.Context[key] = value
		}
	}

	return r
}
コード例 #2
0
ファイル: nr.go プロジェクト: emmetog/conveyor
func (r *Reporter) Report(ctx context.Context, err error) error {
	if tx, ok := newrelic.FromContext(ctx); ok {
		var (
			exceptionType   string
			errorMessage    string
			stackTrace      []string
			stackFrameDelim string
		)

		errorMessage = err.Error()
		stackFrameDelim = "\n"
		stackTrace = make([]string, 0)

		if e, ok := err.(*reporter.Error); ok {
			exceptionType = util.ClassName(e.Err)

			for _, l := range e.Backtrace {
				stackTrace = append(stackTrace, fmt.Sprintf("%s:%d %s", l.File, l.Line, util.FunctionName(l.PC)))
			}

		}

		return tx.ReportError(exceptionType, errorMessage, strings.Join(stackTrace, stackFrameDelim), stackFrameDelim)
	}
	return nil
}