xray

package
v1.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2024 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableTracing

func DisableTracing()

DisableTracing disables xray tracing

func EnableTracing

func EnableTracing()

EnableTracing re-enables xray tracing

func GetXRayHeader

func GetXRayHeader(req *http.Request, headerName ...string) *header.Header

GetXRayHeader gets header from http.request, if headerName is not specified, defaults to x-amzn-trace-id

func GetXRayHttpRequestName

func GetXRayHttpRequestName(req *http.Request, segNamer ...xray.SegmentNamer) string

GetXRayHttpRequestName returns the segment name based on http request method and path, or if segmentNamer is defined, gets the name from http request host

func Init

func Init(daemonAddr string, serviceVersion string) error

Init will configure xray daemon address and service version

func SetXRayServiceOff

func SetXRayServiceOff()

SetXRayServiceOff turns off xray service for new objects, so that wrappers and code supporting xray will not start using xray for tracing when it is init, connect or open, existing objects are not affected by this function action

func SetXRayServiceOn

func SetXRayServiceOn()

SetXRayServiceOn turns on xray service for new objects, so that wrappers and code supporting xray will start using xray for tracing, the service is set to on during its init, open, or connect etc actions, existing objects are not affected by this function action

func XRayServiceOn

func XRayServiceOn() bool

XRayServiceOn returns whether xray tracing service is on or off

Types

type XRayParentSegment

type XRayParentSegment struct {
	SegmentID string
	TraceID   string
}

type XSegment

type XSegment struct {
	Ctx context.Context
	Seg *xray.Segment
	// contains filtered or unexported fields
}

XSegment struct provides wrapper function for xray segment, subsegment, context, and related actions

always use NewSegment() to create XSegment object ptr

func NewSegment

func NewSegment(serviceNameOrUrl string, parentSegment ...*XRayParentSegment) *XSegment

NewSegment begins a new segment for a named service or url, the context.Background() is used as the base context when creating a new segment

NOTE = ALWAYS CALL CLOSE() to End Segment After Tracing of Segment is Complete

func NewSegmentFromHeader

func NewSegmentFromHeader(req *http.Request, traceHeaderName ...string) *XSegment

NewSegmentFromHeader begins a new segment for a named service or url based on http request, the http.Request Context is used as the base context when creating a new segment

NOTE = ALWAYS CALL CLOSE() to End Segment After Tracing of Segment is Complete

func NewSegmentNullable

func NewSegmentNullable(serviceNameOrUrl string, parentSegment ...*XRayParentSegment) *XSegment

NewSegmentNullable returns a new segment for the named service or url, if _xrayServiceOn = true, otherwise, nil is returned for *XSegment.

func NewSubSegmentFromContext added in v1.3.5

func NewSubSegmentFromContext(ctx context.Context, serviceNameOrUrl string) *XSegment

NewSubSegmentFromContext begins a new subsegment under the parent segment context, context can not be empty, and must contains parent segment info

func (*XSegment) Capture

func (x *XSegment) Capture(traceName string, executeFunc func() error, traceData ...*XTraceData)

Capture wraps xray.Capture, by beginning and closing a subsegment with traceName, and synchronously executes the provided executeFunc which contains source application's logic

traceName = descriptive name for the tracing session being tracked executeFunc = custom logic to execute within capture tracing context (context is segment context) traceData = optional additional data to add to the trace (meta, annotation, error)

func (*XSegment) CaptureAsync

func (x *XSegment) CaptureAsync(traceName string, executeFunc func() error, traceData ...*XTraceData)

CaptureAsync wraps xray.CaptureAsync, by beginning and closing a subsegment with traceName, and Asynchronously executes the provided executeFunc which contains source application's logic note = use CaptureAsync when tracing goroutine (rather than Capture) note = do not manually call Capture within goroutine to ensure segment is flushed properly

traceName = descriptive name for the tracing session being tracked executeFunc = custom logic to execute within capture tracing context (context is segment context) traceData = optional additional data to add to the trace (meta, annotation, error)

func (*XSegment) Close

func (x *XSegment) Close()

Close will close a segment (or subsegment), always close subsegments first before closing its parent segment

func (*XSegment) NewSubSegment

func (x *XSegment) NewSubSegment(subSegmentName string) *XSegment

NewSubSegment begins a new subsegment under the parent segment context, the subSegmentName defines a descriptive name of this sub segment for tracing, subsegment.Close(nil) should be called before its parent segment Close is called

NOTE = ALWAYS CALL CLOSE() to End Segment After Tracing of Segment is Complete

func (*XSegment) Ready

func (x *XSegment) Ready() bool

Ready checks if segment is ready for operations

func (*XSegment) SetParentSegment

func (x *XSegment) SetParentSegment(parentID string, traceID string)

SetParentSegment sets segment's ParentID and TraceID as indicated by input parameters

type XTraceData

type XTraceData struct {
	Meta        map[string]interface{}
	Annotations map[string]interface{}
	Errors      map[string]error
}

XTraceData contains maps of data to add during trace activity

func (*XTraceData) AddAnnotation

func (t *XTraceData) AddAnnotation(key string, data interface{})

AddAnnotation adds xray annotation to trace, each trace limits to 50 annotations, annotation = key value pair indexed for use with filter expression

func (*XTraceData) AddError

func (t *XTraceData) AddError(key string, err error)

AddError adds xray error to trace, Error = client errors (4xx other than 429) Fault = server faults (5xx) Throttle = throttle errors (429 too many requests)

func (*XTraceData) AddMeta

func (t *XTraceData) AddMeta(key string, data interface{})

AddMeta adds xray metadata to trace, metadata = key value pair with value of any type, including objects or lists, not indexed,

used to record data that need to be stored in the trace, but don't need to be indexed for searching

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL