2020-02-04 18:55:03 +02:00
|
|
|
package parent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/api/core"
|
|
|
|
"go.opentelemetry.io/otel/api/key"
|
|
|
|
"go.opentelemetry.io/otel/api/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanContext, bool, []trace.Link) {
|
|
|
|
lsctx := trace.SpanFromContext(ctx).SpanContext()
|
|
|
|
rsctx := trace.RemoteSpanContextFromContext(ctx)
|
|
|
|
|
|
|
|
if ignoreContext {
|
|
|
|
links := addLinkIfValid(nil, lsctx, "current")
|
|
|
|
links = addLinkIfValid(links, rsctx, "remote")
|
|
|
|
|
|
|
|
return core.EmptySpanContext(), false, links
|
|
|
|
}
|
|
|
|
if lsctx.IsValid() {
|
2020-02-14 19:21:39 +02:00
|
|
|
return lsctx, false, nil
|
2020-02-04 18:55:03 +02:00
|
|
|
}
|
|
|
|
if rsctx.IsValid() {
|
|
|
|
return rsctx, true, nil
|
|
|
|
}
|
|
|
|
return core.EmptySpanContext(), false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func addLinkIfValid(links []trace.Link, sc core.SpanContext, kind string) []trace.Link {
|
|
|
|
if !sc.IsValid() {
|
|
|
|
return links
|
|
|
|
}
|
|
|
|
return append(links, trace.Link{
|
|
|
|
SpanContext: sc,
|
|
|
|
Attributes: []core.KeyValue{
|
|
|
|
key.String("ignored-on-demand", kind),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|