Documentation
¶
Index ¶
- Constants
- func AddToSpan(span trace.TagSetter, events ...*Event)
- func Enabled() bool
- func Format(stack StackTrace) string
- func GetSpanValue(events ...*Event) any
- type Event
- type EventCategory
- func (z *EventCategory) DecodeMsg(dc *msgp.Reader) (err error)
- func (z EventCategory) EncodeMsg(en *msgp.Writer) (err error)
- func (z EventCategory) MarshalMsg(b []byte) (o []byte, err error)
- func (z EventCategory) Msgsize() (s int)
- func (z *EventCategory) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Options
- type RawStackTrace
- func (z *RawStackTrace) DecodeMsg(dc *msgp.Reader) (err error)
- func (z RawStackTrace) EncodeMsg(en *msgp.Writer) (err error)
- func (z RawStackTrace) MarshalMsg(b []byte) (o []byte, err error)
- func (z RawStackTrace) Msgsize() (s int)
- func (r RawStackTrace) Symbolicate() StackTrace
- func (r RawStackTrace) SymbolicateWithRedaction() StackTrace
- func (z *RawStackTrace) UnmarshalMsg(bts []byte) (o []byte, err error)
- type StackFrame
- type StackTrace
- type UnwindOption
Constants ¶
const SpanKey = "_dd.stack"
Variables ¶
This section is empty.
Functions ¶
func AddToSpan ¶
AddToSpan adds the event to the given span's root span as a tag if stacktrace collection is enabled
func Format ¶ added in v2.4.0
func Format(stack StackTrace) string
Format converts a StackTrace to a string representation
func GetSpanValue ¶
GetSpanValue returns the value to be set as a tag on a span for the given stacktrace events
Types ¶
type Event ¶
type Event struct {
// Category is a well-known type of the event, not optional
Category EventCategory `msg:"-"`
// Type is a value event category specific, optional
Type string `msg:"type,omitempty"`
// Language is the language of the code that generated the event (set to "go" anyway here)
Language string `msg:"language,omitempty"`
// ID is the id of the event, optional for exceptions but mandatory for vulnerabilities and exploits to correlate with more data
ID string `msg:"id,omitempty"`
// Message is a generic message for the event
Message string `msg:"message,omitempty"`
// Frames is the stack trace of the event
Frames StackTrace `msg:"frames"`
}
Event is the toplevel structure to contain a stacktrace and the additional information needed to correlate it with other data
func NewEvent ¶
func NewEvent(eventCat EventCategory, options ...Options) *Event
NewEvent creates a new stacktrace event with the given category, type and message
func (*Event) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type EventCategory ¶
type EventCategory string
const ( // ExceptionEvent is the event type for exception events ExceptionEvent EventCategory = "exception" // VulnerabilityEvent is the event type for vulnerability events VulnerabilityEvent EventCategory = "vulnerability" // ExploitEvent is the event type for exploit events ExploitEvent EventCategory = "exploit" )
func (*EventCategory) DecodeMsg ¶
func (z *EventCategory) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (EventCategory) EncodeMsg ¶
func (z EventCategory) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (EventCategory) MarshalMsg ¶
func (z EventCategory) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (EventCategory) Msgsize ¶
func (z EventCategory) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*EventCategory) UnmarshalMsg ¶
func (z *EventCategory) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type Options ¶
type Options func(*Event)
Options is a function type to set optional parameters for the event
func WithMessage ¶
WithMessage sets the message of the event
type RawStackTrace ¶ added in v2.4.0
type RawStackTrace struct {
PCs []uintptr `msg:"-"`
}
RawStackTrace represents captured program counters without symbolication. This allows for fast capture with deferred processing - symbolication, skipping, and redaction can be performed later when needed.
func CaptureRaw ¶ added in v2.4.0
func CaptureRaw(skip int) RawStackTrace
CaptureRaw captures only program counters without symbolication. This is significantly faster than full capture as it avoids runtime.CallersFrames and symbol parsing. The skip parameter determines how many frames to skip from the top of the stack (similar to runtime.Callers).
func (*RawStackTrace) DecodeMsg ¶ added in v2.4.0
func (z *RawStackTrace) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (RawStackTrace) EncodeMsg ¶ added in v2.4.0
func (z RawStackTrace) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (RawStackTrace) MarshalMsg ¶ added in v2.4.0
func (z RawStackTrace) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (RawStackTrace) Msgsize ¶ added in v2.4.0
func (z RawStackTrace) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (RawStackTrace) Symbolicate ¶ added in v2.4.0
func (r RawStackTrace) Symbolicate() StackTrace
Symbolicate converts raw PCs to a full StackTrace with symbolication, applying the default skipping and redaction rules (skips internal frames, no customer code redaction).
func (RawStackTrace) SymbolicateWithRedaction ¶ added in v2.4.0
func (r RawStackTrace) SymbolicateWithRedaction() StackTrace
SymbolicateWithRedaction converts raw PCs to a StackTrace with customer code redaction (for telemetry logging). This keeps internal Datadog frames but redacts customer code for security.
func (*RawStackTrace) UnmarshalMsg ¶ added in v2.4.0
func (z *RawStackTrace) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type StackFrame ¶
type StackFrame struct {
Text string `msg:"text,omitempty"` // Text version of the stackframe as a string
File string `msg:"file,omitempty"` // File name where the code line is
Namespace string `msg:"namespace,omitempty"` // Namespace is the fully qualified name of the package where the code is
ClassName string `msg:"class_name,omitempty"` // ClassName is the fully qualified name of the class where the line of code is
Function string `msg:"function,omitempty"` // Function is the fully qualified name of the function where the line of code is
Index uint32 `msg:"id"` // Index of the frame (0 = top of the stack)
Line uint32 `msg:"line,omitempty"` // Line number in the context of the file where the code is
Column uint32 `msg:"column,omitempty"` // Column where the code ran is
}
StackFrame represents a single frame in the stack trace
func (*StackFrame) DecodeMsg ¶
func (z *StackFrame) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*StackFrame) EncodeMsg ¶
func (z *StackFrame) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*StackFrame) MarshalMsg ¶
func (z *StackFrame) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*StackFrame) Msgsize ¶
func (z *StackFrame) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*StackFrame) UnmarshalMsg ¶
func (z *StackFrame) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type StackTrace ¶
type StackTrace []StackFrame
StackTrace is intended to be sent over the span tag `_dd.stack`, the first frame is the current frame
func Capture ¶
func Capture() StackTrace
Capture create a new stack trace from the current call stack
func CaptureWithRedaction ¶ added in v2.4.0
func CaptureWithRedaction(skip int) StackTrace
CaptureWithRedaction creates a stack trace with customer code redaction but keeps internal Datadog frames This is designed for telemetry logging where we want to see internal frames for debugging but need to redact customer code for security
func SkipAndCapture ¶
func SkipAndCapture(skip int) StackTrace
SkipAndCapture creates a new stack trace from the current call stack, skipping the first `skip` frames
func SkipAndCaptureWithInternalFrames ¶ added in v2.5.0
func SkipAndCaptureWithInternalFrames(depth int, skip int) StackTrace
SkipAndCaptureWithInternalFrames creates a new stack trace from the current call stack without filtering internal frames. This is useful for tracer span error stacktraces where we want to capture all frames.
func (*StackTrace) DecodeMsg ¶
func (z *StackTrace) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (StackTrace) EncodeMsg ¶
func (z StackTrace) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (StackTrace) MarshalMsg ¶
func (z StackTrace) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (StackTrace) Msgsize ¶
func (z StackTrace) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*StackTrace) UnmarshalMsg ¶
func (z *StackTrace) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type UnwindOption ¶ added in v2.4.0
type UnwindOption func(*unwindConfig)
UnwindOption is a functional option for configuring stack unwinding
func WithInternalFrames ¶ added in v2.4.0
func WithInternalFrames(include bool) UnwindOption
WithInternalFrames controls whether to include internal Datadog frames
func WithMaxDepth ¶ added in v2.4.0
func WithMaxDepth(depth int) UnwindOption
WithMaxDepth sets the maximum number of frames to capture
func WithRedaction ¶ added in v2.4.0
func WithRedaction() UnwindOption
WithRedaction enables or disables customer code redaction
func WithSkipFrames ¶ added in v2.4.0
func WithSkipFrames(skip int) UnwindOption
WithSkipFrames sets the number of frames to skip from the top of the stack
func WithoutRedaction ¶ added in v2.4.0
func WithoutRedaction() UnwindOption
WithoutRedaction disables customer code redaction