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 ¶
- type AgentConfig
- type AgentInfo
- type LLMObsMetric
- type LLMObsSpan
- type MockResponseFunc
- type Option
- type Payloads
- type Span
- type SpanLink
- type TestTracer
- func (tt *TestTracer) SentPayloads() Payloads
- func (tt *TestTracer) StartError() error
- func (tt *TestTracer) Stop()
- func (tt *TestTracer) WaitFor(t testing.TB, timeout time.Duration, cond WaitCondition) *Payloads
- func (tt *TestTracer) WaitForLLMObsMetrics(t *testing.T, count int) []LLMObsMetric
- func (tt *TestTracer) WaitForLLMObsSpans(t *testing.T, count int) []LLMObsSpan
- func (tt *TestTracer) WaitForSpans(t *testing.T, count int) []Span
- type WaitCondition
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 LLMObsMetric ¶ added in v2.3.0
type LLMObsMetric = llmobstransport.LLMObsMetric
LLMObsMetric is an alias for the LLMObs metric type.
type LLMObsSpan ¶ added in v2.3.0
type LLMObsSpan = llmobstransport.LLMObsSpanEvent
LLMObsSpan is an alias for the LLMObs span event type.
type MockResponseFunc ¶ added in v2.3.0
MockResponseFunc is a function to return mock responses.
type Option ¶
type Option func(*config)
Option configures the TestTracer.
func WithAgentInfoResponse ¶
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 WithMockResponses ¶ added in v2.3.0
func WithMockResponses(mr MockResponseFunc) Option
WithMockResponses allows setting a custom request handler for mocking HTTP responses. If the provided function returns nil, it fallbacks to the default behavior of returning empty 200 responses.
func WithRequestDelay ¶ added in v2.3.0
WithRequestDelay introduces a fake delay in all requests.
func WithRequireNoTracerStartError ¶ added in v2.3.1
WithRequireNoTracerStartError allows to customize the behavior for the Start function. By default, it calls require.NoError on the error returned by tracer.Start, but that can be changed by using this option with false as argument.
func WithTracerStartOpts ¶
func WithTracerStartOpts(opts ...tracer.StartOption) Option
WithTracerStartOpts allows to set tracer.StartOption on the tracer.
type Payloads ¶ added in v2.3.0
type Payloads struct {
Spans []Span
LLMSpans []LLMObsSpan
LLMMetrics []LLMObsMetric
// contains filtered or unexported fields
}
Payloads contains all captured payloads organized by type.
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 ¶
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 {
// contains filtered or unexported fields
}
TestTracer is an inspectable tracer useful for tests.
func Start ¶
func Start(t testing.TB, 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) SentPayloads ¶ added in v2.3.0
func (tt *TestTracer) SentPayloads() Payloads
SentPayloads returns a thread-safe copy of all captured payloads.
func (*TestTracer) StartError ¶ added in v2.3.1
func (tt *TestTracer) StartError() error
StartError returns the error from tracer.Start.
func (*TestTracer) Stop ¶
func (tt *TestTracer) Stop()
Stop stops the tracer. It should be called after the test finishes.
func (*TestTracer) WaitFor ¶ added in v2.3.0
func (tt *TestTracer) WaitFor(t testing.TB, timeout time.Duration, cond WaitCondition) *Payloads
WaitFor waits for a condition to be met within the specified timeout. The condition function receives the current payloads and should return true when the wait should stop. It fails the test if the condition is not met within the timeout.
func (*TestTracer) WaitForLLMObsMetrics ¶ added in v2.3.0
func (tt *TestTracer) WaitForLLMObsMetrics(t *testing.T, count int) []LLMObsMetric
WaitForLLMObsMetrics waits for the specified number of LLMObs metrics to be captured. It returns the captured LLMObs metrics or fails the test if the timeout is reached.
func (*TestTracer) WaitForLLMObsSpans ¶ added in v2.3.0
func (tt *TestTracer) WaitForLLMObsSpans(t *testing.T, count int) []LLMObsSpan
WaitForLLMObsSpans waits for the specified number of LLMObs spans to be captured. It returns the captured LLMObs spans or fails the test if the timeout is reached.
func (*TestTracer) WaitForSpans ¶
func (tt *TestTracer) WaitForSpans(t *testing.T, count int) []Span
WaitForSpans waits for the specified number of spans to be captured. It returns the captured spans or fails the test if the timeout is reached.
type WaitCondition ¶ added in v2.3.0
WaitCondition is a function that checks if the wait condition is met. It receives the current payloads and returns true if waiting should stop.