reporter_options.go 2.4 KB

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