Golang: Sentry/Raven and ApexLog

We are using apex/log for structured logging and have implemented a handler for forwarding error level messages to Sentry.

Sentry isn’t doing a good job at disambiguating errors, instead grouping unrelated messages together. Has anyone got this working properly.

Here’s our handler:

// HandleLog implements log.sentryHandler.
func (h *sentryHandler) HandleLog(e *log.Entry) error {
	switch e.Level {
	case log.FatalLevel, log.ErrorLevel:
		fields := map[string]string{}
		for k, v := range e.Fields {
			fields[k] = fmt.Sprintf("%+v", v)
		}
		ex, _ := os.Executable()
		fields["bin"] = path.Base(ex)
		if e.Level == log.FatalLevel {
			raven.CaptureErrorAndWait(fmt.Errorf("%s", e.Message), fields)
		} else if e.Level == log.ErrorLevel {
			raven.CaptureError(fmt.Errorf("%s", e.Message), fields)
		}
	default:
		// Nothing.
	}
	return h.other.HandleLog(e)
}

I think the problem here is that the log entry doesn’t contain the original error, which is breaking some assumptions within CaptureError.

I’ve solved this for ourselves by manually constructing a raven.Packet and setting the Fingerprint field based on our knowledge of the log fields associated with an error.