我正在尝试通过多个 https 调用生成 OTLP 日志。
为此,我使用这个功能来创建一个新的父母
import * as ot from "@opentelemetry/api";
function newParentSpan(tracer: ot.Tracer, headers: any, body: any): ot.SpanContext {
console.log("start new parentspan")
//Start new Span with given Tracer
let parentSpan = tracer.startSpan(headers.spanname as string)
ot.propagation.inject(ot.trace.setSpanContext(ot.context.active(), parentSpan.spanContext()), headers);
// Loop over all attributes within body
addBodyToAttributes(parentSpan, body);
console.log(ot.trace.getSpan(ot.trace.setSpanContext(ot.context.active(), parentSpan.spanContext())).isRecording());
//This returns false, when I expect it to be recording
return parentSpan.spanContext();
}
但是,当我使用 GetSpan() 方法时,我总是收到 NonRecordingSpan 当我尝试记录它时看起来像这样:
NonRecordingSpan {
_spanContext: {
traceId: 'b199ef0a87a915895a5e16d8bfc6a0c4',
spanId: 'c605d534f2b18cc5',
traceFlags: 1,
traceState: undefined
}
}
我认为这就是为什么我无法在以后的 https 调用中结束跨度。
我尝试使用标头而不是像这样使用 ot.propagation 来传递我的 spancontext:
let spancontext: ot.SpanContext = ({
traceId: headers.traceid,
spanId: headers.spanid,
traceFlags: headers.traceflags
})
但我的大多数方法都以相同的结果结束:NonRecoringSpan