SpringCloud 创建并完成spans

2023-12-01 16:00 更新

您可以使用Tracer手动创建spans,如以下示例所示:

// Start a span. If there was a span present in this thread it will become
// the `newSpan`'s parent.
Span newSpan = this.tracer.nextSpan().name("calculateTax");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(newSpan.start())) {
	// ...
	// You can tag a span
	newSpan.tag("taxValue", taxValue);
	// ...
	// You can log an event on a span
	newSpan.annotate("taxCalculated");
}
finally {
	// Once done remember to finish the span. This will allow collecting
	// the span to send it to Zipkin
	newSpan.finish();
}

在前面的示例中,我们可以看到如何创建跨度的新实例。如果此线程中已经有一个跨度,它将成为新跨度的父级。

创建跨度后,请始终保持清洁。另外,请务必完成要发送到Zipkin的所有跨度。

如果您的跨度包含的名称大于50个字符,则该名称将被截断为50个字符。您的名字必须明确明确。知名人士会导致延迟问题,有时甚至会引发例外情况。

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号