Debian Codegraph @

exporter/exporterhelper/internal/queuebatch/batch_context.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package queuebatch // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal/queuebatch"
5
6 import (
7 "context"
8
9 "go.opentelemetry.io/otel/trace"
10 )
11
12 type traceContextKeyType int
13
14 const batchSpanLinksKey traceContextKeyType = iota
15
16 // LinksFromContext returns a list of trace links registered in the context.
17 func LinksFromContext(ctx context.Context) []trace.Link {
18 if ctx == nil {
19 return []trace.Link{}
20 }
21 if links, ok := ctx.Value(batchSpanLinksKey).([]trace.Link); ok {
22 return links
23 }
24 return []trace.Link{}
25 }
26
27 func parentsFromContext(ctx context.Context) []trace.Link {
28 if spanCtx := trace.SpanContextFromContext(ctx); spanCtx.IsValid() {
29 return []trace.Link{{SpanContext: spanCtx}}
30 }
31 return LinksFromContext(ctx)
32 }
33
34 func contextWithMergedLinks(mergedCtx, ctx1, ctx2 context.Context) context.Context {
35 return context.WithValue(
36 mergedCtx,
37 batchSpanLinksKey,
38 append(parentsFromContext(ctx1), parentsFromContext(ctx2)...))
39 }