Documentation ¶
Overview ¶
Package tracing implements a k6 JS module for instrumenting k6 scripts with tracing context information.
Index ¶
- Constants
- type AlwaysOnSampler
- type Client
- func (c *Client) AsyncRequest(method string, url goja.Value, args ...goja.Value) (*goja.Promise, error)
- func (c *Client) Configure(opts options) error
- func (c *Client) Del(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Get(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Head(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Options(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Patch(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Post(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Put(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- func (c *Client) Request(method string, url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
- type HTTPAsyncRequestFunc
- type HTTPRequestFunc
- type JaegerPropagator
- type ModuleInstance
- type ProbabilisticSampler
- type Propagator
- type RootModule
- type Sampler
- type TraceID
- type W3CPropagator
Constants ¶
const ( // W3CPropagatorName is the name of the W3C trace context propagator W3CPropagatorName = "w3c" // W3CHeaderName is the name of the W3C trace context header W3CHeaderName = "traceparent" // W3CVersion is the version of the supported W3C trace context header. // The current specification assumes the version is set to 00. W3CVersion = "00" // W3CUnsampledTraceFlag is the trace-flag value for an unsampled trace. W3CUnsampledTraceFlag = "00" // W3CSampledTraceFlag is the trace-flag value for a sampled trace. W3CSampledTraceFlag = "01" )
const ( // JaegerPropagatorName is the name of the Jaeger trace context propagator JaegerPropagatorName = "jaeger" // JaegerHeaderName is the name of the Jaeger trace context header JaegerHeaderName = "uber-trace-id" // JaegerRootSpanID is the universal span ID of the root span. // Its value is zero, which is described in the Jaeger documentation as: // "0 value is valid and means “root span” (when not ignored)" JaegerRootSpanID = "0" // JaegerSampledTraceFlag is the trace-flag value for an unsampled trace. JaegerSampledTraceFlag = "0" // JaegerUnsampledTraceFlag is the trace-flag value for a sampled trace. JaegerUnsampledTraceFlag = "1" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlwaysOnSampler ¶ added in v0.44.0
type AlwaysOnSampler struct{}
AlwaysOnSampler implements the Sampler interface and allows to bypass sampling decisions by returning true for all Sampled() calls.
This is useful in cases where the user either does not provide the sampling option, or set it to 100% as it will avoid any call to the random number generator.
func NewAlwaysOnSampler ¶ added in v0.44.0
func NewAlwaysOnSampler() *AlwaysOnSampler
NewAlwaysOnSampler returns a new AlwaysSampledSampler.
func (AlwaysOnSampler) ShouldSample ¶ added in v0.44.0
func (AlwaysOnSampler) ShouldSample() bool
ShouldSample always returns true.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a HTTP Client instrumenting the requests it performs with tracing information.
func (*Client) AsyncRequest ¶
func (c *Client) AsyncRequest(method string, url goja.Value, args ...goja.Value) (*goja.Promise, error)
AsyncRequest instruments the http module's asyncRequest function with tracing headers, and ensures the trace_id is emitted as part of the output's data points metadata.
type HTTPAsyncRequestFunc ¶
type HTTPAsyncRequestFunc func(method string, url goja.Value, args ...goja.Value) (*goja.Promise, error)
HTTPAsyncRequestFunc is a type alias representing the prototype of k6's http module's asyncRequest function
type HTTPRequestFunc ¶
type HTTPRequestFunc func(method string, url goja.Value, args ...goja.Value) (*httpmodule.Response, error)
HTTPRequestFunc is a type alias representing the prototype of k6's http module's request function
type JaegerPropagator ¶
type JaegerPropagator struct { // Sampler is used to determine whether or not a trace should be sampled. Sampler }
JaegerPropagator is a Propagator for the Jaeger trace context header
func NewJaegerPropagator ¶ added in v0.44.0
func NewJaegerPropagator(s Sampler) *JaegerPropagator
NewJaegerPropagator returns a new JaegerPropagator with the given sampler.
type ModuleInstance ¶
type ModuleInstance struct { // Client holds the module's default tracing client. *Client // contains filtered or unexported fields }
ModuleInstance represents an instance of the JS module.
func (*ModuleInstance) Exports ¶
func (mi *ModuleInstance) Exports() modules.Exports
Exports implements the modules.Instance interface and returns the exports of the JS module.
type ProbabilisticSampler ¶ added in v0.44.0
type ProbabilisticSampler struct {
// contains filtered or unexported fields
}
ProbabilisticSampler implements the ProbabilisticSampler interface and allows to take probabilistic sampling decisions based on a sampling rate.
func NewProbabilisticSampler ¶ added in v0.44.0
func NewProbabilisticSampler(samplingRate float64) *ProbabilisticSampler
NewProbabilisticSampler returns a new ProbablisticSampler with the provided sampling rate.
Note that the sampling rate is a percentage value within 0.0 <= samplingRate <= 1.0 bounds. If the provided sampling rate is outside of this range, it will be clamped to the closest bound.
func (ProbabilisticSampler) ShouldSample ¶ added in v0.44.0
func (ps ProbabilisticSampler) ShouldSample() bool
ShouldSample returns true if the trace should be sampled.
Its return value is probabilistic, based on the selected sampling rate S, there is S percent chance that the returned value is true.
type Propagator ¶
Propagator is an interface for trace context propagation
type RootModule ¶
type RootModule struct{}
RootModule is the global module instance that will create Client instances for each VU.
func (*RootModule) NewModuleInstance ¶
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance
NewModuleInstance implements the modules.Module interface and returns a new instance for each VU.
type Sampler ¶ added in v0.44.0
type Sampler interface { // ShouldSample returns true if the trace should be sampled // false otherwise. ShouldSample() bool }
Sampler is an interface defining a sampling strategy.
type TraceID ¶
type TraceID struct { // Prefix is the first 2 bytes of the trace-id, and is used to identify the // vendor of the trace-id. Prefix int16 // Code is the third byte of the trace-id, and is used to identify the // vendor's specific trace-id format. Code int8 // Time is the time at which the trace-id was generated. // // The time component is used as a source of randomness, and to ensure // uniqueness of the trace-id. // // When encoded, it should be in a format occupying the last 8 bytes of // the trace-id, and should ideally be encoded as nanoseconds. Time time.Time // contains filtered or unexported fields }
TraceID represents a trace-id as defined by the W3c specification, and used by w3c, b3 and jaeger propagators. See Considerations for trace-id field generation for more information.
func (TraceID) Encode ¶
Encode encodes the TraceID into a hex string.
The trace id is first encoded as a 16 bytes sequence, as follows: 1. Up to 2 bytes are encoded as the Prefix 2. The third byte is the Code. 3. Up to the following 8 bytes are UnixTimestampNano. 4. The remaining bytes are filled with random bytes.
The resulting 16 bytes sequence is then encoded as a hex string.
type W3CPropagator ¶
type W3CPropagator struct { // Sampler is used to determine whether or not a trace should be sampled. Sampler }
W3CPropagator is a Propagator for the W3C trace context header
func NewW3CPropagator ¶ added in v0.44.0
func NewW3CPropagator(s Sampler) *W3CPropagator
NewW3CPropagator returns a new W3CPropagator using the provided sampler to base its sampling decision upon.
Note that we allocate the propagator on the heap to ensure we conform to the Sampler interface, as the [Sampler.SetSamplingRate] method has a pointer receiver.