aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/go.opencensus.io/trace/exemplar.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.opencensus.io/trace/exemplar.go')
-rw-r--r--vendor/go.opencensus.io/trace/exemplar.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/go.opencensus.io/trace/exemplar.go b/vendor/go.opencensus.io/trace/exemplar.go
new file mode 100644
index 0000000..416d805
--- /dev/null
+++ b/vendor/go.opencensus.io/trace/exemplar.go
@@ -0,0 +1,43 @@
1// Copyright 2018, OpenCensus Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package trace
16
17import (
18 "context"
19 "encoding/hex"
20
21 "go.opencensus.io/exemplar"
22)
23
24func init() {
25 exemplar.RegisterAttachmentExtractor(attachSpanContext)
26}
27
28func attachSpanContext(ctx context.Context, a exemplar.Attachments) exemplar.Attachments {
29 span := FromContext(ctx)
30 if span == nil {
31 return a
32 }
33 sc := span.SpanContext()
34 if !sc.IsSampled() {
35 return a
36 }
37 if a == nil {
38 a = make(exemplar.Attachments)
39 }
40 a[exemplar.KeyTraceID] = hex.EncodeToString(sc.TraceID[:])
41 a[exemplar.KeySpanID] = hex.EncodeToString(sc.SpanID[:])
42 return a
43}