yurishkuro / opentracing-tutorial

A collection of tutorials for the OpenTracing API
Apache License 2.0
1.57k stars 404 forks source link

go-lesson02: Unclear ChildOf() code #17

Closed eest closed 6 years ago

eest commented 6 years ago

The lesson text uses this code to show usage of ChildOf():

span = rootSpan.Tracer().StartSpan(
    "formatString",
    opentracing.ChildOf(span.Context()),
)

It is not obvious how that should be used. The = assignment suggests that "span" is already declared which means it should be used after the short assignment statement (:=) that already exists, like this:

span := rootSpan.Tracer().StartSpan("formatString")
span = rootSpan.Tracer().StartSpan(
    "formatString",
    opentracing.ChildOf(span.Context()),
)

I'm guessing this is not what is intended, and running the code it is clear a unique trace is still being created. I think that example should be updated to this:

span := rootSpan.Tracer().StartSpan(
    "formatString",
    opentracing.ChildOf(rootSpan.Context()),
)

That is, use := assignment and replace span.Context() with rootSpan.Context().

yurishkuro commented 6 years ago

thanks for reporting it