将opentelemetry-api从0.5.0升级到0.8.0时,我遇到了这个问题。
考虑以下代码片段,
import io.opentelemetry.OpenTelemetry
import io.opentelemetry.context.Scope
import io.opentelemetry.trace._
object Main4 extends App {
val a: Tracer = OpenTelemetry.getTracer(getClass.getSimpleName)
val b: Span = a.spanBuilder("test").startSpan()
val c: Scope = a.withSpan(b)
try {
val d: Span = TracingContextUtils.getCurrentSpan
val e: SpanContext = d.getContext
val f: Span = DefaultSpan.getInvalid
val g: SpanContext = f.getContext
println(d)
println(e)
println(e.isValid)
println(e.getSpanId)
println(e.getTraceId)
println()
println()
println()
println(f)
println(g)
println(g.isValid)
println(g.getSpanId)
println(g.getTraceId)
println()
println()
println(d == f)
} finally {
c.close()
}
}
使用0.5.0,我得到的输出为: -
DefaultSpan
SpanContext{traceId=TraceId{traceId=f153124023eeab63d027ca493e05cbdf}, spanId=SpanId{spanId=fb8136024af9a4ae}, traceFlags=TraceFlags{sampled=false}, traceState=TraceState{entries=[]}, remote=false}
true
SpanId{spanId=fb8136024af9a4ae}
TraceId{traceId=f153124023eeab63d027ca493e05cbdf}
DefaultSpan
SpanContext{traceId=TraceId{traceId=00000000000000000000000000000000}, spanId=SpanId{spanId=0000000000000000}, traceFlags=TraceFlags{sampled=false}, traceState=TraceState{entries=[]}, remote=false}
false
SpanId{spanId=0000000000000000}
TraceId{traceId=00000000000000000000000000000000}
false
使用0.8.0,我得到的输出为: -
DefaultSpan
SpanContext{traceId=TraceId{traceId=00000000000000000000000000000000}, spanId=SpanId{spanId=0000000000000000}, traceFlags=TraceFlags{sampled=false}, traceState=TraceState{entries=[]}, remote=false}
false
SpanId{spanId=0000000000000000}
TraceId{traceId=00000000000000000000000000000000}
DefaultSpan
SpanContext{traceId=TraceId{traceId=00000000000000000000000000000000}, spanId=SpanId{spanId=0000000000000000}, traceFlags=TraceFlags{sampled=false}, traceState=TraceState{entries=[]}, remote=false}
false
SpanId{spanId=0000000000000000}
TraceId{traceId=00000000000000000000000000000000}
true
我认为对于0.8.0,我的代码中缺少一些东西,因为它没有按预期正常工作。
有人可以让我知道我需要对我的代码进行哪些更改,以便获得正确的Span而不是像0.5.0一样的无效Span吗?
注意:- 我正在使用:- scala -> 2.13.3,jvm -> 14,sbt -> 1.3.13