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