使用Golang Opentelemetry(Otel)覆盖跨度的启动时间和终点
我正在对在进行跟踪之前收集的数据生成跟踪。这意味着跨度创建时间与实际开始时间不匹配。
我过去已经能够使用 opentracing 来做到这一点:
span := tracer.StartSpan(
name,
opentracing.StartTime(startTime),
)
我一直无法在 golang otel 库中找到等效项。我的印象是应该有可能 基于规范中的引用:
开始时间戳,默认为当前时间。仅当跨度创建时间已经过去时才应设置此参数。如果在 Span 逻辑启动时调用 API,API 用户不得显式设置此参数。
“默认”一词意味着应该可以在创建跨度后更改此时间戳。
我尝试过使用 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
}
},
// ...
}
I am producing traces for data that was collected before I am doing the tracing. This means that the span creation time does not match up with the real start time.
I have been able to do this in the past using opentracing
:
span := tracer.StartSpan(
name,
opentracing.StartTime(startTime),
)
I have been unable to find an equivalent in the golang otel libraries. I get the impression that it should be possible based on this quote from the spec:
Start timestamp, default to current time. This argument SHOULD only be set when span creation time has already passed. If API is called at a moment of a Span logical start, API user MUST NOT explicitly set this argument.
The word "default" implies that it should be possible to change this timestamp after span creation.
I have tried using span.SetAttributes
:
span.SetAttributes(attribute.Int64("StartTime", 0))
But this (unsurprisingly) sets an attribute:
{
// ...
"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
}
},
// ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
withtimestamp
。You need to use
WithTimestamp
.