header.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // HeadersConfig contains the values for the header keys that Jaeger will use.
  16. // These values may be either custom or default depending on whether custom
  17. // values were provided via a configuration.
  18. type HeadersConfig struct {
  19. // JaegerDebugHeader is the name of HTTP header or a TextMap carrier key which,
  20. // if found in the carrier, forces the trace to be sampled as "debug" trace.
  21. // The value of the header is recorded as the tag on the root span, so that the
  22. // trace can be found in the UI using this value as a correlation ID.
  23. JaegerDebugHeader string `yaml:"jaegerDebugHeader"`
  24. // JaegerBaggageHeader is the name of the HTTP header that is used to submit baggage.
  25. // It differs from TraceBaggageHeaderPrefix in that it can be used only in cases where
  26. // a root span does not exist.
  27. JaegerBaggageHeader string `yaml:"jaegerBaggageHeader"`
  28. // TraceContextHeaderName is the http header name used to propagate tracing context.
  29. // This must be in lower-case to avoid mismatches when decoding incoming headers.
  30. TraceContextHeaderName string `yaml:"TraceContextHeaderName"`
  31. // TraceBaggageHeaderPrefix is the prefix for http headers used to propagate baggage.
  32. // This must be in lower-case to avoid mismatches when decoding incoming headers.
  33. TraceBaggageHeaderPrefix string `yaml:"traceBaggageHeaderPrefix"`
  34. }
  35. func (c *HeadersConfig) applyDefaults() *HeadersConfig {
  36. if c.JaegerBaggageHeader == "" {
  37. c.JaegerBaggageHeader = JaegerBaggageHeader
  38. }
  39. if c.JaegerDebugHeader == "" {
  40. c.JaegerDebugHeader = JaegerDebugHeader
  41. }
  42. if c.TraceBaggageHeaderPrefix == "" {
  43. c.TraceBaggageHeaderPrefix = TraceBaggageHeaderPrefix
  44. }
  45. if c.TraceContextHeaderName == "" {
  46. c.TraceContextHeaderName = TraceContextHeaderName
  47. }
  48. return c
  49. }
  50. func getDefaultHeadersConfig() *HeadersConfig {
  51. return &HeadersConfig{
  52. JaegerDebugHeader: JaegerDebugHeader,
  53. JaegerBaggageHeader: JaegerBaggageHeader,
  54. TraceContextHeaderName: TraceContextHeaderName,
  55. TraceBaggageHeaderPrefix: TraceBaggageHeaderPrefix,
  56. }
  57. }