腾讯mini项目【指标监控服务重构】- 2023-07-15

07-15

今日已办

OpenTelemetry-SDK

开始入门

Trace

TraceProvider
// TracerProvider 是它提供的 Tracers 中所有 Span 的收集目的地,它代表了一个独特的遥测收集管道。该管道的定义方式(即如何收集、处理这些 Span 以及将其导出到何处)取决于其实现
type TracerProvider interface {
   
	// 根据名称、选项返回唯一Tracer
	// TracerOption
	// WithInstrumentationVersion sets the instrumentation version.
	// WithInstrumentationAttributes sets the instrumentation attributes.
	// WithSchemaURL sets the schema URL for the Tracer.
	Tracer(name string, options ...TracerOption) Tracer
}

// This is short for GetTracerProvider().Tracer(name, opts...)
func Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
   
	return GetTracerProvider().Tracer(name, opts...)
}

// GetTracerProvider returns the registered global trace provider.
func GetTracerProvider() trace.TracerProvider {
   
	return global.TracerProvider()
}

// SetTracerProvider registers `tp` as the global trace provider.
func SetTracerProvider(tp trace.TracerProvider) {
   
	global.SetTracerProvider(tp)
}
Tracer
// Tracer is the creator of Spans.
type Tracer interface {
   
	// Start
	// 1.创建span和包含该span的context
	// 2.如果ctx包含span,则新span为子span,否则为根span;可以通过WithNewRoot()覆盖使得该span为根span
	// 3.WithAttributes() 提供所有已知的 Span 属性,采样器只能访问创建 Span 时提供的属性
	// 4.任何创建的 Span 也必须结束
	// SpanStartOption
	// WithLinks adds links to a Span.
	// WithNewRoot specifies that the Span should be treated as a root Span.
	// WithSpanKind sets the SpanKind of a Span.
	Start(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span)
}
Span
// Span is the individual component of a trace.
// 表示追踪的单个命名和定时操作的工作流。Tracer用于创建Span
type Span interface {
   
	// End completes the Span.
    // WithStackTrace sets the flag to capture the error with stack trace (e.g. true, false).
	End(options ...SpanEndOption)

	// AddEvent adds an event with the provided name and options.
	AddEvent(name string, options ...EventOption)

	// IsRecording returns the recording state of the Span.
	// true : span is active & events can be recorded
	IsRecording() bool

	// RecordError will record err as an exception span event for this span. 
	RecordError(err error, options ...EventOption)

	// SpanContext returns the SpanContext of the Span. 即时结束也可以获取
	SpanContext() SpanContext

	// SetStatus sets the status of the Span in the form of a code and a
	// description, provided the status hasn't already been set to a higher
	// value before (OK > Error > Unset). 错误才有描述
	SetStatus(code codes.Code, description string)

	// SetName sets the Span name.
	SetName(name string)

	// SetAttributes sets kv as attributes of the Span. overwritten
	SetAttributes(kv ...attribute.KeyValue)

	// TracerProvider returns a TracerProvider that can be used to generate
	// additional Spans on the same telemet
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奥库甘道夫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值