xray

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

Daemon is background daemon for sending segments. This struct stores segments and sends segment to AWS X-Ray in each checkpoint timing.

func NewDaemon

func NewDaemon(size int, interval time.Duration, fn func([]*Segment) error) *Daemon

NewDaemon creates new Daemon. size is number of segments to send AWS API in single checkpoint. interval is the time of checkpoint interval. fn is function called in each checkpoint, to sends segments to AWS API.

func (*Daemon) Add

func (d *Daemon) Add(segments ...*Segment)

Add adds segment data into daemon.

func (*Daemon) Flush

func (d *Daemon) Flush()

Flush gets segments from the internal spool and execute flushSegments function.

func (*Daemon) Run

func (d *Daemon) Run()

Run sets timer to flush data in each checkpoint as a background daemon.

func (*Daemon) Stop

func (d *Daemon) Stop()

Stop stops daemon.

type Decision

type Decision struct {
	Trace  bool    // Whether to trace the request.
	Policy string  // Name of the sampling policy.
	Weight float64 // Sample weight to be used in statistical calculations.
}

Decision is the value returned by a call to a SamplingPolicy's Sample method.

type SamplingPolicy

type SamplingPolicy interface {
	// Sample returns a Decision.
	// If Trace is false in the returned Decision, then the Decision should be
	// the zero value.
	Sample() Decision
	CanSample() bool
}

SamplingPolicy is policy to determine which data can send to AWS API or not, with rate limit function.

func NewLimitedSampler

func NewLimitedSampler(fraction, maxqps float64) (SamplingPolicy, error)

NewLimitedSampler returns a sampling policy that randomly samples a given fraction of requests. It also enforces a limit on the number of traces per second. It tries to trace every request with a trace header, but will not exceed the qps limit to do it.

type Segment

type Segment struct {
	Trace bool

	// Required
	TraceID   string
	ID        string
	Name      string
	StartTime time.Time
	EndTime   time.Time

	// Optional
	User           string
	ParentID       string
	Error          string
	Annotations    map[string]interface{}
	Request        *http.Request
	ResponseStatus int
	ContentLength  int

	// subsegments
	SQLQuery string
	// contains filtered or unexported fields
}

Segment is span data for AWS X-Ray.

func NewEmptySegment

func NewEmptySegment() *Segment

NewEmptySegment creates dummy segment. This data is created by sampling policy and does not send to AWS API.

func NewSegment

func NewSegment(name string) *Segment

NewSegment creates new segment with given name.

func NewSegmentFromRequest

func NewSegmentFromRequest(r *http.Request) *Segment

NewSegmentFromRequest creates new segment from *http.Request.

func (*Segment) Finish

func (s *Segment) Finish()

Finish ends segment timer and add segment into daemon's spool.

func (*Segment) Init

func (s *Segment) Init()

Init initializes segment data.

func (*Segment) NewChild

func (s *Segment) NewChild(name string) *Segment

NewChild creates child segment data from the Segment.

func (*Segment) ToJSON

func (s *Segment) ToJSON() ([]byte, error)

ToJSON converts to json byte data for AWS X-Ray API.

type SegmentHTTP

type SegmentHTTP struct {
	*SegmentRequest  `json:"request,omitempty"`
	*SegmentResponse `json:"response,omitempty"`
}

SegmentHTTP is segment data for http.

type SegmentRequest

type SegmentRequest struct {
	URL           string `json:"url,omitempty"`
	Method        string `json:"method,omitempty"`
	UserAgent     string `json:"user_agent,omitempty"`
	ClientIP      string `json:"client_ip,omitempty"`
	XForwardedFor bool   `json:"x_forwarded_for,omitempty"`
}

SegmentRequest is segment data for http request.

func NewSegmentRequest

func NewSegmentRequest(r *http.Request) *SegmentRequest

NewSegmentRequest creates SegmentRequest data from *http.Request.

type SegmentResponse

type SegmentResponse struct {
	Status        int `json:"status,omitempty"`
	ContentLength int `json:"content_length,omitempty"`
}

SegmentResponse is segment data for http response.

func NewSegmentResponse

func NewSegmentResponse(status, length int) *SegmentResponse

NewSegmentResponse creates SegmentResponse data from http status code and content length.

type SegmentRoot

type SegmentRoot struct {
	// Required
	TraceID   string  `json:"trace_id,omitempty"`
	ID        string  `json:"id,omitempty"`
	Name      string  `json:"name,omitempty"`
	StartTime float64 `json:"start_time,omitempty"`
	EndTime   float64 `json:"end_time,omitempty"`

	// Optional
	User         string                 `json:"user,omitempty"`
	ParentID     string                 `json:"parent_id,omitempty"`
	Error        string                 `json:"error,omitempty"`
	Annotations  map[string]interface{} `json:"annotations,omitempty"`
	*SegmentHTTP `json:"http,omitempty"`

	// subsegments
	SubSegments []*SegmentRoot `json:"subsegments,omitempty"`
	*SegmentSQL `json:"sql,omitempty"`
}

SegmentRoot is root segment data for converting JSON as a X-Ray's specification.

type SegmentSQL

type SegmentSQL struct {
	SanitizedQuery string `json:"sanitized_query,omitempty"`
}

SegmentSQL is segment data for sql.

type XRay

type XRay struct {
	// contains filtered or unexported fields
}

XRay has XRay client.

func New

func New(conf config.Config) (*XRay, error)

New returns initialized *Kinesis.

func (*XRay) AddSegment

func (svc *XRay) AddSegment(segments ...*Segment)

AddSegment adds the segment dat into background daemon.

func (*XRay) Errorf

func (svc *XRay) Errorf(format string, v ...interface{})

Errorf logging error information.

func (*XRay) Infof

func (svc *XRay) Infof(format string, v ...interface{})

Infof logging information.

func (*XRay) NewSegment

func (svc *XRay) NewSegment(name string) *Segment

NewSegment creates new Segment data with given name.

func (*XRay) NewSegmentFromRequest

func (svc *XRay) NewSegmentFromRequest(r *http.Request) *Segment

NewSegmentFromRequest creates new Segment data from *http.Request.

func (*XRay) PutTraceSegments

func (svc *XRay) PutTraceSegments(segments []*Segment) error

PutTraceSegments executes PutTraceSegments operation.

func (*XRay) RunDaemon

func (svc *XRay) RunDaemon(size int, interval time.Duration)

RunDaemon creates and runs background daemon.

func (*XRay) SetLogger

func (svc *XRay) SetLogger(logger log.Logger)

SetLogger sets logger.

func (*XRay) SetSamplingPolicy

func (svc *XRay) SetSamplingPolicy(fraction, qps float64) error

SetSamplingPolicy sets sampling policy.

Jump to

Keyboard shortcuts

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