header.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2017 Uber Technologies, Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. package jaeger
  21. // HeadersConfig contains the values for the header keys that Jaeger will use.
  22. // These values may be either custom or default depending on whether custom
  23. // values were provided via a configuration.
  24. type HeadersConfig struct {
  25. // JaegerDebugHeader is the name of HTTP header or a TextMap carrier key which,
  26. // if found in the carrier, forces the trace to be sampled as "debug" trace.
  27. // The value of the header is recorded as the tag on the root span, so that the
  28. // trace can be found in the UI using this value as a correlation ID.
  29. JaegerDebugHeader string `yaml:"jaegerDebugHeader"`
  30. // JaegerBaggageHeader is the name of the HTTP header that is used to submit baggage.
  31. // It differs from TraceBaggageHeaderPrefix in that it can be used only in cases where
  32. // a root span does not exist.
  33. JaegerBaggageHeader string `yaml:"jaegerBaggageHeader"`
  34. // TraceContextHeaderName is the http header name used to propagate tracing context.
  35. // This must be in lower-case to avoid mismatches when decoding incoming headers.
  36. TraceContextHeaderName string `yaml:"TraceContextHeaderName"`
  37. // TraceBaggageHeaderPrefix is the prefix for http headers used to propagate baggage.
  38. // This must be in lower-case to avoid mismatches when decoding incoming headers.
  39. TraceBaggageHeaderPrefix string `yaml:"traceBaggageHeaderPrefix"`
  40. }
  41. func (c *HeadersConfig) applyDefaults() *HeadersConfig {
  42. if c.JaegerBaggageHeader == "" {
  43. c.JaegerBaggageHeader = JaegerBaggageHeader
  44. }
  45. if c.JaegerDebugHeader == "" {
  46. c.JaegerDebugHeader = JaegerDebugHeader
  47. }
  48. if c.TraceBaggageHeaderPrefix == "" {
  49. c.TraceBaggageHeaderPrefix = TraceBaggageHeaderPrefix
  50. }
  51. if c.TraceContextHeaderName == "" {
  52. c.TraceContextHeaderName = TraceContextHeaderName
  53. }
  54. return c
  55. }
  56. func getDefaultHeadersConfig() *HeadersConfig {
  57. return &HeadersConfig{
  58. JaegerDebugHeader: JaegerDebugHeader,
  59. JaegerBaggageHeader: JaegerBaggageHeader,
  60. TraceContextHeaderName: TraceContextHeaderName,
  61. TraceBaggageHeaderPrefix: TraceBaggageHeaderPrefix,
  62. }
  63. }