utils

package
v0.0.0-...-57ec133 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorType represents a 4XX status code
	ErrorType = "error"
	// FaultType represents a 5XX status code
	FaultType = "fault"
)
View Source
const (
	// XRayHeader represents an AWS X-Ray trace HTTP header key.
	XRayHeader = "X-Amzn-Trace-Id"
)

Variables

This section is empty.

Functions

func ContextFromHeaders

func ContextFromHeaders(r *http.Request) context.Context

ContextFromHeaders parses the root ID, parent ID, and whether the request was sampled based on the HTTP request X-Ray header and returns a new context containing the metadata.

func CurrentTimeSecond

func CurrentTimeSecond() float64

CurrentTimeSecond returns a float64 representation of the current Unix time with sub-second decimal accuracy.

func GetCauseFromHTTPStatus

func GetCauseFromHTTPStatus(status int) string

GetCauseFromHTTPStatus returns a string representing an error, fault, or no cause based on HTTP response status codes

func GetClientIP

func GetClientIP(req *http.Request) string

GetClientIP returns the IP address of a request from an X-Forwarded-For header or remote address

func GetContentLength

func GetContentLength(res *http.Response) (int, error)

GetContentLength returns the content length of a response if provided as a header.

func GetIDsFromContext

func GetIDsFromContext(ctx context.Context) (rootID, parentID, sampled string)

GetIDsFromContext returns the root ID, parent ID, and whether the request was sampled based on context metadata.

func GetenvOrDefault

func GetenvOrDefault(key string, def string) string

GetenvOrDefault returns an environment variable value if not empty, otherwise it returns the default value.

Types

type Sampler

type Sampler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Sampler represents a sampler instance, which keeps track of the number of traces per second to be sampled and fallback rate for additional sampling. Additionally, a sampler instance determines whether a given trace should be sampled based on 'fixedTarget' and 'fallbackRate' settings.

func NewSampler

func NewSampler(fixedTarget uint32, fallbackRate float64) *Sampler

NewSampler creates a new sampler with the specified configuration.

func (*Sampler) IsSampled

func (s *Sampler) IsSampled() bool

IsSampled determines whether a given trace should be sampled.

Jump to

Keyboard shortcuts

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