trace

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package trace provides tracing instrumentation tailored for k6 browser needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopSpan

type NoopSpan struct {
	trace.Span
}

NoopSpan represents a noop span.

func (NoopSpan) AddEvent

func (NoopSpan) AddEvent(string, ...trace.EventOption)

AddEvent is noop.

func (NoopSpan) End

func (NoopSpan) End(...trace.SpanEndOption)

End is noop.

func (NoopSpan) IsRecording

func (NoopSpan) IsRecording() bool

IsRecording returns false.

func (NoopSpan) RecordError

func (NoopSpan) RecordError(error, ...trace.EventOption)

RecordError is noop.

func (NoopSpan) SetAttributes

func (NoopSpan) SetAttributes(...attribute.KeyValue)

SetAttributes is noop.

func (NoopSpan) SetError

func (NoopSpan) SetError(bool)

SetError is noop.

func (NoopSpan) SetName

func (NoopSpan) SetName(string)

SetName is noop.

func (NoopSpan) SetStatus

func (NoopSpan) SetStatus(codes.Code, string)

SetStatus 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

type Tracer struct {
	trace.Tracer
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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