我正在对进行跟踪之前收集的数据生成跟踪。这意味着跨度创建时间与实际开始时间不匹配。
我过去可以使用以下方法来做到这一点opentracing
:
span := tracer.StartSpan(
name,
opentracing.StartTime(startTime),
)
Run Code Online (Sandbox Code Playgroud)
我在 golang otel 图书馆中找不到同等的东西。我的印象是,根据规范中的引用,这应该是可能的:
开始时间戳,默认为当前时间。仅当跨度创建时间已经过去时才应设置此参数。如果在 Span 逻辑启动时调用 API,则 API 用户不得显式设置此参数。
“默认”一词意味着应该可以在创建跨度后更改此时间戳。
我尝试过使用span.SetAttributes
:
span.SetAttributes(attribute.Int64("StartTime", 0))
Run Code Online (Sandbox Code Playgroud)
但这(毫不奇怪)设置了一个属性:
{
// ...
"StartTime": "2022-04-09T12:28:57.271375+10:00",
"EndTime": "2022-04-09T12:28:57.271417375+10:00",
"Attributes": [
{
"Key": "StartTime",
"Value": {
"Type": "INT64",
"Value": 0
}
},
// ...
}
Run Code Online (Sandbox Code Playgroud)