reporter_options.go 2.3 KB

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