interop.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. package jaeger
  15. import (
  16. "github.com/opentracing/opentracing-go"
  17. )
  18. // TODO this file should not be needed after TChannel PR.
  19. type formatKey int
  20. // SpanContextFormat is a constant used as OpenTracing Format.
  21. // Requires *SpanContext as carrier.
  22. // This format is intended for interop with TChannel or other Zipkin-like tracers.
  23. const SpanContextFormat formatKey = iota
  24. type jaegerTraceContextPropagator struct {
  25. tracer *Tracer
  26. }
  27. func (p *jaegerTraceContextPropagator) Inject(
  28. ctx SpanContext,
  29. abstractCarrier interface{},
  30. ) error {
  31. carrier, ok := abstractCarrier.(*SpanContext)
  32. if !ok {
  33. return opentracing.ErrInvalidCarrier
  34. }
  35. carrier.CopyFrom(&ctx)
  36. return nil
  37. }
  38. func (p *jaegerTraceContextPropagator) Extract(abstractCarrier interface{}) (SpanContext, error) {
  39. carrier, ok := abstractCarrier.(*SpanContext)
  40. if !ok {
  41. return emptyContext, opentracing.ErrInvalidCarrier
  42. }
  43. ctx := new(SpanContext)
  44. ctx.CopyFrom(carrier)
  45. return *ctx, nil
  46. }