blob: 8402d087c29fd22ab88a6f17f28eec8f06b79869 [file] [log] [blame]
Prince Pereirac1c21d62021-04-22 08:38:15 +00001// Copyright (c) 2017 Uber Technologies, Inc.
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 jaeger
16
17import (
18 "github.com/opentracing/opentracing-go"
19)
20
21// TODO this file should not be needed after TChannel PR.
22
23type formatKey int
24
25// SpanContextFormat is a constant used as OpenTracing Format.
26// Requires *SpanContext as carrier.
27// This format is intended for interop with TChannel or other Zipkin-like tracers.
28const SpanContextFormat formatKey = iota
29
30type jaegerTraceContextPropagator struct {
31 tracer *Tracer
32}
33
34func (p *jaegerTraceContextPropagator) Inject(
35 ctx SpanContext,
36 abstractCarrier interface{},
37) error {
38 carrier, ok := abstractCarrier.(*SpanContext)
39 if !ok {
40 return opentracing.ErrInvalidCarrier
41 }
42
43 carrier.CopyFrom(&ctx)
44 return nil
45}
46
47func (p *jaegerTraceContextPropagator) Extract(abstractCarrier interface{}) (SpanContext, error) {
48 carrier, ok := abstractCarrier.(*SpanContext)
49 if !ok {
50 return emptyContext, opentracing.ErrInvalidCarrier
51 }
52 ctx := new(SpanContext)
53 ctx.CopyFrom(carrier)
54 return *ctx, nil
55}