Help us shape the future of Go! Take the 2026 Go Developer Survey

telemetrytest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package telemetrytest 提供写入内存的遥测管道,供各包测试断言 span、指标与日志;与 net/http/httptest 同类。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpanAttribute

func GetSpanAttribute(span sdktrace.ReadOnlySpan, key string) string

GetSpanAttribute 读取 span 属性的文本形式。

func GetSpanValue

func GetSpanValue(span sdktrace.ReadOnlySpan, key string) (attribute.Value, bool)

GetSpanValue 读取 span 属性的原始值及存在标记。

Types

type Pipeline

type Pipeline struct {
	Telemetry *telemetry.Telemetry
	// TracerProvider 供测试自己开 span,例如模拟提交输入的请求。
	TracerProvider *sdktrace.TracerProvider
	// contains filtered or unexported fields
}

Pipeline 是写入内存的遥测管道:span 结束时记录,指标在断言时收集,日志以 Debug 级别的 JSON 行写入内存。

func NewPipeline

func NewPipeline(t testing.TB) *Pipeline

NewPipeline 创建开启内容采集的内存遥测管道。

func NewPipelineWithoutContent

func NewPipelineWithoutContent(t testing.TB) *Pipeline

NewPipelineWithoutContent 创建关闭内容采集的内存遥测管道。

func (*Pipeline) GetEndedSpans

func (p *Pipeline) GetEndedSpans() []sdktrace.ReadOnlySpan

GetEndedSpans 按结束顺序返回已结束的 span。

func (*Pipeline) GetHistogramBounds

func (p *Pipeline) GetHistogramBounds(t testing.TB, name string) []float64

GetHistogramBounds 读取指定直方图的分桶。

func (*Pipeline) GetHistogramCount

func (p *Pipeline) GetHistogramCount(t testing.TB, name string, attrs ...attribute.KeyValue) uint64

GetHistogramCount 汇总指定直方图的记录次数。

func (*Pipeline) GetLogRecords

func (p *Pipeline) GetLogRecords(t testing.TB, msg string) []map[string]any

GetLogRecords 解析内存日志并筛选消息。

func (*Pipeline) GetLogText

func (p *Pipeline) GetLogText() string

GetLogText 返回全部内存日志原文。

func (*Pipeline) GetMetricAttributeKeys

func (p *Pipeline) GetMetricAttributeKeys(t testing.TB, name string) []string

GetMetricAttributeKeys 收集指定指标的全部属性键。

func (*Pipeline) GetMetricSum

func (p *Pipeline) GetMetricSum(t testing.TB, name string, attrs ...attribute.KeyValue) float64

GetMetricSum 收集并汇总指定指标的数据点。

func (*Pipeline) WaitEndedSpans

func (p *Pipeline) WaitEndedSpans(t testing.TB, name string, count int) []sdktrace.ReadOnlySpan

WaitEndedSpans 等待指定名称的结束 span 达到要求数量。

func (*Pipeline) WaitLogRecords

func (p *Pipeline) WaitLogRecords(t testing.TB, msg string, count int) []map[string]any

WaitLogRecords 等待指定消息的日志达到要求数量。

Jump to

Keyboard shortcuts

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