英文:
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
我们尝试了不同的方法将字符串转换为字节数组,但都没有成功。
有人有什么想法吗?
提前感谢,祝好!
英文:
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
得分: 1
我们找到了答案:
- set(trace_id.string, attributes["traceID"])
运行得很好
英文:
We found the answer:
- set(trace_id.string,attributes["traceID"])
Works just fine
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论