testtracer

package
v2.3.0-dev Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testtracer provides a wrapper over the ddtrace/tracer package with a mocked transport that allows to inspect traces while keeping the rest of the tracer logic the same.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentConfig

type AgentConfig struct {
	StatsdPort int `json:"statsd_port"`
}

AgentConfig defines the agent config.

type AgentInfo

type AgentInfo struct {
	Endpoints          []string    `json:"endpoints"`
	ClientDropP0s      bool        `json:"client_drop_p0s"`
	FeatureFlags       []string    `json:"feature_flags"`
	PeerTags           []string    `json:"peer_tags"`
	SpanMetaStruct     bool        `json:"span_meta_structs"`
	ObfuscationVersion int         `json:"obfuscation_version"`
	Config             AgentConfig `json:"config"`
}

AgentInfo defines the response from the agent /info endpoint.

type Option

type Option func(*config)

func WithAgentInfoResponse

func WithAgentInfoResponse(response AgentInfo) Option

WithAgentInfoResponse sets a custom /info agent response. It can be used to enable/disable certain features from the tracer that depend on whether the agent supports them or not.

func WithTracerStartOpts

func WithTracerStartOpts(opts ...tracer.StartOption) Option

WithTracerStartOpts allows to set tracer.StartOption on the tracer.

type Span

type Span struct {
	Name       string             `json:"name"`
	Service    string             `json:"service"`
	Resource   string             `json:"resource"`
	Type       string             `json:"type"`
	Start      int64              `json:"start"`
	Duration   int64              `json:"duration"`
	Meta       map[string]string  `json:"meta"`
	MetaStruct map[string]any     `json:"meta_struct"`
	Metrics    map[string]float64 `json:"metrics"`
	SpanID     uint64             `json:"span_id"`
	TraceID    uint64             `json:"trace_id"`
	ParentID   uint64             `json:"parent_id"`
	Error      int32              `json:"error"`
	SpanLinks  []SpanLink         `json:"span_links"`
}

Span defines a span with the same format as it is sent to the agent.

type SpanLink struct {
	TraceID     uint64            `json:"trace_id"`
	TraceIDHigh uint64            `json:"trace_id_high"`
	SpanID      uint64            `json:"span_id"`
	Attributes  map[string]string `json:"attributes"`
	Tracestate  string            `json:"tracestate"`
	Flags       uint32            `json:"flags"`
}

SpanLink defines a span link with the same format as it is sent to the agent.

type TestTracer

type TestTracer struct {
	Spans <-chan Span
	// contains filtered or unexported fields
}

TestTracer is an inspectable tracer useful for tests.

func Start

func Start(t *testing.T, opts ...Option) *TestTracer

Start calls tracer.Start with a mocked transport and provides a new TestTracer that allows to inspect the spans produced by this application.

func (*TestTracer) Stop

func (tt *TestTracer) Stop()

Stop stops the tracer. It should be called after the test finishes.

func (*TestTracer) WaitForSpans

func (tt *TestTracer) WaitForSpans(t *testing.T, count int) []Span

WaitForSpans returns when receiving a number of Span equal to count. It fails the test if it did not receive that number of spans after 5 seconds.

Jump to

Keyboard shortcuts

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