reporter_options.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. import (
  22. "time"
  23. )
  24. // ReporterOption is a function that sets some option on the reporter.
  25. type ReporterOption func(c *reporterOptions)
  26. // ReporterOptions is a factory for all available ReporterOption's
  27. var ReporterOptions reporterOptions
  28. // reporterOptions control behavior of the reporter.
  29. type reporterOptions struct {
  30. // queueSize is the size of internal queue where reported spans are stored before they are processed in the background
  31. queueSize int
  32. // bufferFlushInterval is how often the buffer is force-flushed, even if it's not full
  33. bufferFlushInterval time.Duration
  34. // logger is used to log errors of span submissions
  35. logger Logger
  36. // metrics is used to record runtime stats
  37. metrics *Metrics
  38. }
  39. // QueueSize creates a ReporterOption that sets the size of the internal queue where
  40. // spans are stored before they are processed.
  41. func (reporterOptions) QueueSize(queueSize int) ReporterOption {
  42. return func(r *reporterOptions) {
  43. r.queueSize = queueSize
  44. }
  45. }
  46. // Metrics creates a ReporterOption that initializes Metrics in the reporter,
  47. // which is used to record runtime statistics.
  48. func (reporterOptions) Metrics(metrics *Metrics) ReporterOption {
  49. return func(r *reporterOptions) {
  50. r.metrics = metrics
  51. }
  52. }
  53. // BufferFlushInterval creates a ReporterOption that sets how often the queue
  54. // is force-flushed.
  55. func (reporterOptions) BufferFlushInterval(bufferFlushInterval time.Duration) ReporterOption {
  56. return func(r *reporterOptions) {
  57. r.bufferFlushInterval = bufferFlushInterval
  58. }
  59. }
  60. // Logger creates a ReporterOption that initializes the logger used to log
  61. // errors of span submissions.
  62. func (reporterOptions) Logger(logger Logger) ReporterOption {
  63. return func(r *reporterOptions) {
  64. r.logger = logger
  65. }
  66. }