errors.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package newrelic
  2. // StackTracer can be implemented by errors to provide a stack trace when using
  3. // Transaction.NoticeError.
  4. type StackTracer interface {
  5. StackTrace() []uintptr
  6. }
  7. // ErrorClasser can be implemented by errors to provide a custom class when
  8. // using Transaction.NoticeError.
  9. type ErrorClasser interface {
  10. ErrorClass() string
  11. }
  12. // ErrorAttributer can be implemented by errors to provide extra context when
  13. // using Transaction.NoticeError.
  14. type ErrorAttributer interface {
  15. ErrorAttributes() map[string]interface{}
  16. }
  17. // Error is an error that implements ErrorClasser and ErrorAttributer. It can
  18. // be used with Transaction.NoticeError to control exactly how errors are
  19. // recorded. Example use:
  20. //
  21. // txn.NoticeError(newrelic.Error{
  22. // Message: "error message: something went very wrong",
  23. // Class: "errors are aggregated by class",
  24. // Attributes: map[string]interface{}{
  25. // "important_number": 97232,
  26. // "relevant_string": "zap",
  27. // },
  28. // })
  29. type Error struct {
  30. // Message is the error message which will be returned by the Error()
  31. // method.
  32. Message string
  33. // Class indicates how the error may be aggregated.
  34. Class string
  35. // Attributes are attached to traced errors and error events for
  36. // additional context. These attributes are validated just like those
  37. // added to `Transaction.AddAttribute`.
  38. Attributes map[string]interface{}
  39. }
  40. func (e Error) Error() string { return e.Message }
  41. // ErrorClass implements the ErrorClasser interface.
  42. func (e Error) ErrorClass() string { return e.Class }
  43. // ErrorAttributes implements the ErrorAttributes interface.
  44. func (e Error) ErrorAttributes() map[string]interface{} { return e.Attributes }