github.com/lulzWill/go-agent@v2.1.2+incompatible/errors.go (about)

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