在进行跟踪之前,我正在为收集的数据生成跟踪。这意味着跨度创建时间与实际开始时间不匹配。
我在过去使用opentracing就能做到这一点
span := tracer.StartSpan(
name,
opentracing.StartTime(startTime),
)我一直没能在戈朗大学的图书馆找到类似的东西。我觉得这应该是可能的基于这个从规范中引用的
启动时间戳,默认为当前时间。只有当span创建时间已过时,才应设置此参数。如果API是在跨逻辑启动时调用的,则API用户不能显式设置此参数。
“默认”一词意味着在span创建之后应该可以更改这个时间戳。
我试过使用span.SetAttributes
span.SetAttributes(attribute.Int64("StartTime", 0))但这(毫不奇怪)设置了一个属性:
{
// ...
"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
}
},
// ...
}发布于 2022-04-09 10:50:54
您需要使用WithTimestamp。
startTime := time.Now()
ctx, span := tracer.Start(ctx, "foo", trace.WithTimestamp(startTime))
// do your work
span.End(trace.WithTimestamp(time.Now()))https://stackoverflow.com/questions/71804884
复制相似问题