khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame^] | 1 | // 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 | |
| 15 | package jaeger |
| 16 | |
| 17 | import ( |
| 18 | "github.com/opentracing/opentracing-go" |
| 19 | ) |
| 20 | |
| 21 | // TODO this file should not be needed after TChannel PR. |
| 22 | |
| 23 | type 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. |
| 28 | const SpanContextFormat formatKey = iota |
| 29 | |
| 30 | type jaegerTraceContextPropagator struct { |
| 31 | tracer *Tracer |
| 32 | } |
| 33 | |
| 34 | func (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 | |
| 47 | func (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 | } |