/
errors.go
59 lines (49 loc) · 1.89 KB
/
errors.go
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
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package newrelic
// stackTracer can be implemented by errors to provide a stack trace when using
// Transaction.NoticeError.
type stackTracer interface {
StackTrace() []uintptr
}
// errorClasser can be implemented by errors to provide a custom class when
// using Transaction.NoticeError.
type errorClasser interface {
ErrorClass() string
}
// errorAttributer can be implemented by errors to provide extra context when
// using Transaction.NoticeError.
type errorAttributer interface {
ErrorAttributes() map[string]interface{}
}
// Error is an error designed for use with Transaction.NoticeError. It allows
// direct control over the recorded error's message, class, stacktrace, and
// attributes.
type Error struct {
// Message is the error message which will be returned by the Error()
// method.
Message string
// Class indicates how the error may be aggregated.
Class string
// Attributes are attached to traced errors and error events for
// additional context. These attributes are validated just like those
// added to Transaction.AddAttribute.
Attributes map[string]interface{}
// Stack is the stack trace. Assign this field using NewStackTrace,
// or leave it nil to indicate that Transaction.NoticeError should
// generate one.
Stack []uintptr
}
// NewStackTrace generates a stack trace for the newrelic.Error struct's Stack
// field.
func NewStackTrace() []uintptr {
st := getStackTrace()
return []uintptr(st)
}
func (e Error) Error() string { return e.Message }
// ErrorClass returns the error's class.
func (e Error) ErrorClass() string { return e.Class }
// ErrorAttributes returns the error's extra attributes.
func (e Error) ErrorAttributes() map[string]interface{} { return e.Attributes }
// StackTrace returns the error's stack.
func (e Error) StackTrace() []uintptr { return e.Stack }