propagator.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Unless explicitly stated otherwise all files in this repository are licensed
  2. // under the Apache License Version 2.0.
  3. // This product includes software developed at Datadog (https://www.datadoghq.com/).
  4. // Copyright 2016 Datadog, Inc.
  5. package tracer
  6. import (
  7. "errors"
  8. "gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
  9. )
  10. // Propagator implementations should be able to inject and extract
  11. // SpanContexts into an implementation specific carrier.
  12. type Propagator interface {
  13. // Inject takes the SpanContext and injects it into the carrier.
  14. Inject(context ddtrace.SpanContext, carrier interface{}) error
  15. // Extract returns the SpanContext from the given carrier.
  16. Extract(carrier interface{}) (ddtrace.SpanContext, error)
  17. }
  18. // TextMapWriter allows setting key/value pairs of strings on the underlying
  19. // data structure. Carriers implementing TextMapWriter are compatible to be
  20. // used with Datadog's TextMapPropagator.
  21. type TextMapWriter interface {
  22. // Set sets the given key/value pair.
  23. Set(key, val string)
  24. }
  25. // TextMapReader allows iterating over sets of key/value pairs. Carriers implementing
  26. // TextMapReader are compatible to be used with Datadog's TextMapPropagator.
  27. type TextMapReader interface {
  28. // ForeachKey iterates over all keys that exist in the underlying
  29. // carrier. It takes a callback function which will be called
  30. // using all key/value pairs as arguments. ForeachKey will return
  31. // the first error returned by the handler.
  32. ForeachKey(handler func(key, val string) error) error
  33. }
  34. var (
  35. // ErrInvalidCarrier is returned when the carrier provided to the propagator
  36. // does not implement the correct interfaces.
  37. ErrInvalidCarrier = errors.New("invalid carrier")
  38. // ErrInvalidSpanContext is returned when the span context found in the
  39. // carrier is not of the expected type.
  40. ErrInvalidSpanContext = errors.New("invalid span context")
  41. // ErrSpanContextCorrupted is returned when there was a problem parsing
  42. // the information found in the carrier.
  43. ErrSpanContextCorrupted = errors.New("span context corrupted")
  44. // ErrSpanContextNotFound represents missing information in the given carrier.
  45. ErrSpanContextNotFound = errors.New("span context not found")
  46. )