| 1 |
// Code generated by gotmpl. DO NOT MODIFY. |
| 2 |
// source: internal/shared/counter/counter.go.tmpl |
| 3 |
|
| 4 |
// Copyright The OpenTelemetry Authors |
| 5 |
// SPDX-License-Identifier: Apache-2.0 |
| 6 |
|
| 7 |
// Package counter provides a simple counter for generating unique IDs. |
| 8 |
// |
| 9 |
// This package is used to generate unique IDs while allowing testing packages |
| 10 |
// to reset the counter. |
| 11 |
package counter // import "go.opentelemetry.io/otel/exporters/stdout/stdouttrace/internal/counter" |
| 12 |
|
| 13 |
import "sync/atomic" |
| 14 |
|
| 15 |
// exporterN is a global 0-based count of the number of exporters created. |
| 16 |
var exporterN atomic.Int64 |
| 17 |
|
| 18 |
// NextExporterID returns the next unique ID for an exporter. |
| 19 |
func NextExporterID() int64 { |
| 20 |
const inc = 1 |
| 21 |
return exporterN.Add(inc) - inc |
| 22 |
} |
| 23 |
|
| 24 |
// SetExporterID sets the exporter ID counter to v and returns the previous |
| 25 |
// value. |
| 26 |
// |
| 27 |
// This function is useful for testing purposes, allowing you to reset the |
| 28 |
// counter. It should not be used in production code. |
| 29 |
func SetExporterID(v int64) int64 { |
| 30 |
return exporterN.Swap(v) |
| 31 |
} |