Set TraceId from String Attribute Value in Open Telemetry // Cast String to Byte Array

huangapple go评论74阅读模式
英文:

Set TraceId from String Attribute Value in Open Telemetry // Cast String to Byte Array

问题

我们正在尝试使用OpenTelemetry Transform Processor [1]设置TraceID。

有一种方法可以像这样使用硬编码的值 [2] 设置TraceID(示例显示的是SpanID,但TraceID也适用)。

traces:
    set(span_id, SpanID(0x0000000000000000))

我们想将其设置为存储在属性中的值。我们尝试了以下方式:

traces:
    set(trace_id, attributes["traceID"])

其中attributes["traceID"]是一个字符串0x00000000000000000000000000000000

这种方法行不通,但如果我们尝试

traces:
    set(trace_id,TraceID(attributes["traceID"]))

收集器甚至无法启动,因为我们试图提供一个字符串,而期望的是一个字节切片

collector server run finished with error: invalid configuration: processor "transform" has invalid configuration: invalid argument at position 1 invalid argument for slice parameter at position 0, must be a byte slice literal

我们尝试了不同的方法将字符串转换为字节数组,但都没有成功。

有人有什么想法吗?

提前感谢,祝好!

[1] https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/fbb8ff9658b3bac7892dea6c7d49f40afe154bd8/processor/transformprocessor

[2] https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl#update-a-spans-id

英文:

we are trying to set a TraceID with a the OpenTelemetry Transform Processor [1].

There is a way to set the TraceID with a hard coded value [2] like this (the example shows a SpanID, but TraceID works too).

traces:
    set(span_id, SpanID(0x0000000000000000))

We want to set it to a value we have stored in an attribute. We tried

traces:
    set(trace_id, attributes["traceID"])

where attributes["traceID"] is a String 0x00000000000000000000000000000000.

This won't work, but if we try

traces:
    set(trace_id,TraceID(attributes["traceID"]))

the collector won't even start, since we are trying to give a String, where a Byte Slice is expected

collector server run finished with error: invalid configuration: processor "transform" has invalid configuration: invalid argument at position 1 invalid argument for slice parameter at position 0, must be a byte slice literal

We tried different approaches to cast the String to a Byte Array but none did work.

Does anyone have an idea?

Thanks in advance, kind regards!

[1] https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/fbb8ff9658b3bac7892dea6c7d49f40afe154bd8/processor/transformprocessor

[2] https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl#update-a-spans-id

答案1

得分: 1

我们找到了答案:

  • set(trace_id.string, attributes["traceID"])

运行得很好 Set TraceId from String Attribute Value in Open Telemetry // Cast String to Byte Array

英文:

We found the answer:

- set(trace_id.string,attributes["traceID"])

Works just fine Set TraceId from String Attribute Value in Open Telemetry // Cast String to Byte Array

huangapple
  • 本文由 发表于 2022年11月22日 23:03:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/74534750.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定