header.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // ApplyDefaults sets missing configuration keys to default values
  36. func (c *HeadersConfig) ApplyDefaults() *HeadersConfig {
  37. if c.JaegerBaggageHeader == "" {
  38. c.JaegerBaggageHeader = JaegerBaggageHeader
  39. }
  40. if c.JaegerDebugHeader == "" {
  41. c.JaegerDebugHeader = JaegerDebugHeader
  42. }
  43. if c.TraceBaggageHeaderPrefix == "" {
  44. c.TraceBaggageHeaderPrefix = TraceBaggageHeaderPrefix
  45. }
  46. if c.TraceContextHeaderName == "" {
  47. c.TraceContextHeaderName = TraceContextHeaderName
  48. }
  49. return c
  50. }
  51. func getDefaultHeadersConfig() *HeadersConfig {
  52. return &HeadersConfig{
  53. JaegerDebugHeader: JaegerDebugHeader,
  54. JaegerBaggageHeader: JaegerBaggageHeader,
  55. TraceContextHeaderName: TraceContextHeaderName,
  56. TraceBaggageHeaderPrefix: TraceBaggageHeaderPrefix,
  57. }
  58. }