Documentation ¶
Overview ¶
Package trace provides tracing instrumentation tailored for k6 browser needs.
Index ¶
- type NoopSpan
- func (NoopSpan) AddEvent(string, ...trace.EventOption)
- func (NoopSpan) End(...trace.SpanEndOption)
- func (NoopSpan) IsRecording() bool
- func (NoopSpan) RecordError(error, ...trace.EventOption)
- func (NoopSpan) SetAttributes(...attribute.KeyValue)
- func (NoopSpan) SetError(bool)
- func (NoopSpan) SetName(string)
- func (NoopSpan) SetStatus(codes.Code, string)
- func (NoopSpan) SpanContext() trace.SpanContext
- func (NoopSpan) TracerProvider() trace.TracerProvider
- type Tracer
- func (t *Tracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func (t *Tracer) TraceAPICall(ctx context.Context, targetID string, spanName string, ...) (context.Context, trace.Span)
- func (t *Tracer) TraceEvent(ctx context.Context, targetID string, eventName string, spanID string, ...) (context.Context, trace.Span)
- func (t *Tracer) TraceNavigation(ctx context.Context, targetID string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NoopSpan ¶
NoopSpan represents a noop span.
func (NoopSpan) RecordError ¶
func (NoopSpan) RecordError(error, ...trace.EventOption)
RecordError is noop.
func (NoopSpan) SetAttributes ¶
SetAttributes is noop.
func (NoopSpan) SpanContext ¶
func (NoopSpan) SpanContext() trace.SpanContext
SpanContext returns a void span context.
func (NoopSpan) TracerProvider ¶
func (NoopSpan) TracerProvider() trace.TracerProvider
TracerProvider returns a noop tracer provider.
type Tracer ¶
Tracer represents a traces generator tailored to k6 browser needs. Specifically implements methods to generate spans for navigations, API calls and page events, accepting input parameters that allow correlating async operations, such as Web Vitals events, with the page to which they belong to.
func NewTracer ¶
func NewTracer(tp k6lib.TracerProvider, metadata map[string]string, options ...trace.TracerOption) *Tracer
NewTracer creates a new Tracer from the given TracerProvider.
func (*Tracer) Start ¶
func (t *Tracer) Start( ctx context.Context, spanName string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span)
Start overrides the underlying OTEL tracer method to include the tracer metadata.
func (*Tracer) TraceAPICall ¶
func (t *Tracer) TraceAPICall( ctx context.Context, targetID string, spanName string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span)
TraceAPICall adds a new span to the current liveSpan for the given targetID and returns it. It is the caller's responsibility to close the generated span. If there is not a liveSpan for the given targetID, the new span is created based on the given context, which means that it might be a root span or not depending if the context already wraps a span.
func (*Tracer) TraceEvent ¶
func (t *Tracer) TraceEvent( ctx context.Context, targetID string, eventName string, spanID string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span)
TraceEvent creates a new span representing the specified event and associates it with the current liveSpan for the given targetID only if the spanID matches with the liveSpan. It is the caller's responsibility to close the generated span.
If no liveSpan is found for the given targetID, the action is ignored and a noopSpan is returned. If the given spanID does not match the one for the current liveSpan associated with the targetID, it means the specified target has navigated, generating a new span for that navigation, therefore the event is not associated with that span, and instead a noopSpan is returned.
func (*Tracer) TraceNavigation ¶
func (t *Tracer) TraceNavigation( ctx context.Context, targetID string, opts ...trace.SpanStartOption, ) (context.Context, trace.Span)
TraceNavigation is only to be used when a frame has navigated. It records a new liveSpan for the given targetID which identifies the frame that has navigated. If there was already a liveSpan for the given targetID, it is closed before creating the new one, otherwise it's the caller's responsibility to close the generated span. Posterior calls to TraceEvent or TraceAPICall given the same targetID will try to associate new spans for these actions to the liveSpan created in this call.