tracing

package
v0.0.0-...-29e7bc9 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package tracing implements a k6 JS module for instrumenting k6 scripts with tracing context information.

Index

Constants

View Source
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"
)
View Source
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

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

func NewAlwaysOnSampler() *AlwaysOnSampler

NewAlwaysOnSampler returns a new AlwaysSampledSampler.

func (AlwaysOnSampler) ShouldSample

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 NewClient

func NewClient(vu modules.VU, opts options) (*Client, error)

NewClient instantiates a new tracing Client

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.

func (*Client) Configure

func (c *Client) Configure(opts options) error

Configure configures the tracing client with the given options.

func (*Client) Del

func (c *Client) Del(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Del instruments the http module's delete method.

func (*Client) Get

func (c *Client) Get(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Get instruments the http module's get method.

func (*Client) Head

func (c *Client) Head(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Head instruments the http module's head method.

func (*Client) Options

func (c *Client) Options(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Options instruments the http module's options method.

func (*Client) Patch

func (c *Client) Patch(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Patch instruments the http module's patch method.

func (*Client) Post

func (c *Client) Post(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Post instruments the http module's post method.

func (*Client) Put

func (c *Client) Put(url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Put instruments the http module's put method.

func (*Client) Request

func (c *Client) Request(method string, url goja.Value, args ...goja.Value) (*httpmodule.Response, error)

Request instruments the http module's request 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

func NewJaegerPropagator(s Sampler) *JaegerPropagator

NewJaegerPropagator returns a new JaegerPropagator with the given sampler.

func (*JaegerPropagator) Propagate

func (p *JaegerPropagator) Propagate(traceID string) (http.Header, error)

Propagate returns a header with a random trace ID in the Jaeger format

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

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

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

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

type Propagator interface {
	Propagate(traceID string) (http.Header, error)
}

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 New

func New() *RootModule

New returns a pointer to a new RootModule instance

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

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 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

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.

func (*W3CPropagator) Propagate

func (p *W3CPropagator) Propagate(traceID string) (http.Header, error)

Propagate returns a header with a random trace ID in the W3C format

Jump to

Keyboard shortcuts

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