tracer_options.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2022 The OpenZipkin Authors
  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 zipkintracer
  15. import (
  16. otobserver "github.com/opentracing-contrib/go-observer"
  17. )
  18. // B3InjectOption type holds information on B3 injection style when using
  19. // native OpenTracing HTTPHeadersCarrier.
  20. type B3InjectOption int
  21. // Available B3InjectOption values
  22. const (
  23. B3InjectStandard B3InjectOption = iota
  24. B3InjectSingle
  25. B3InjectBoth
  26. )
  27. // TracerOptions allows creating a customized Tracer.
  28. type TracerOptions struct {
  29. observer otobserver.Observer
  30. b3InjectOpt B3InjectOption
  31. }
  32. // TracerOption allows for functional options.
  33. // See: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
  34. type TracerOption func(opts *TracerOptions)
  35. // WithObserver assigns an initialized observer to opts.observer
  36. func WithObserver(observer otobserver.Observer) TracerOption {
  37. return func(opts *TracerOptions) {
  38. opts.observer = observer
  39. }
  40. }
  41. // WithB3InjectOption sets the B3 injection style if using the native OpenTracing HTTPHeadersCarrier
  42. func WithB3InjectOption(b3InjectOption B3InjectOption) TracerOption {
  43. return func(opts *TracerOptions) {
  44. opts.b3InjectOpt = b3InjectOption
  45. }
  46. }