NewCounter creates a new Counter based on the provided CounterOpts. The returned implementation also implements ExemplarAdder. It is safe to perform the corresponding type assertion. The returned implementation tracks the counter value in two separate variables, a float64 and a uint64. The latter
(opts CounterOpts)
| 85 | // Both internal tracking values are added up in the Write method. This has to |
| 86 | // be taken into account when it comes to precision and overflow behavior. |
| 87 | func NewCounter(opts CounterOpts) Counter { |
| 88 | desc := NewDesc( |
| 89 | BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), |
| 90 | opts.Help, |
| 91 | nil, |
| 92 | opts.ConstLabels, |
| 93 | ) |
| 94 | if opts.now == nil { |
| 95 | opts.now = time.Now |
| 96 | } |
| 97 | result := &counter{desc: desc, labelPairs: desc.constLabelPairs, now: opts.now} |
| 98 | result.init(result) // Init self-collection. |
| 99 | result.createdTs = timestamppb.New(opts.now()) |
| 100 | return result |
| 101 | } |
| 102 | |
| 103 | type counter struct { |
| 104 | // valBits contains the bits of the represented float64 value, while |