mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-14 10:13:10 +02:00
f99337fb8a
When during determining a parent for a new span, we find out that there is a current span in the context, we are putting a remote span context into links as an ignored on demand. A problem with this approach is that the remote span context will end up in links of every descendant span. Another problem is that jaeger exporter currently treats all links as span contexts with a "child of" relationship and that likely confuses the jaeger visualization.
41 lines
946 B
Go
41 lines
946 B
Go
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() {
|
|
return lsctx, false, nil
|
|
}
|
|
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),
|
|
},
|
|
})
|
|
}
|