英文:
Migration issue with opentelemetry-api from 0.5.0 to 0.8.0
问题
我在升级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
英文:
I am facing this issue when upgrading opentelemetry-api from 0.5.0 to 0.8.0.
Consider the following code snippet,
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()
}
}
With 0.5.0, I am getting the output as: -
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
with 0.8.0, I am getting the output as: -
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
I think with 0.8.0 there is something missing in my code due to which it is not being correctly working as expected.
Can someone let me know what changes I need to do with my code so as to obtain the proper Span and not invalid Span as I am getting with 0.5.0?
Note:- I am using:- scala -> 2.13.3, jvm -> 14, sbt -> 1.3.13
答案1
得分: 2
在0.8.0版本中,API在没有安装SDK的情况下不再生成跨度(spans)。主要出于性能原因做出了这个更改,这样当没有安装SDK时,API本身的运行开销会降低。
如果您想要有效的跨度(spans),只需将SDK添加到您的类路径中,您将会得到它们。
英文:
In 0.8.0, the API no longer generates spans in the absence of an installed SDK. This was done primarily for performance reasons, so that the API itself will operate at lower overhead when there is no SDK installed.
If you want valid spans, just add the SDK to your classpath, and you will get them back.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论