Skip to content

Commit

Permalink
Document the Reader and Exporter concurrent safe requirements
Browse files Browse the repository at this point in the history
The aggregation and temporality methods may be called concurrently. Both
with themselves and with other methods of the Reader or Exporter.
Implementations need to provide concurrent safe methods. This change
adds documentation about this requirement.

Part of open-telemetry#3925
  • Loading branch information
MrAlias committed Jul 28, 2023
1 parent 859a870 commit f52b429
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add info and debug logging to the metric SDK. (#4315)
- The `go.opentelemetry.io/otel/semconv/v1.21.0` package.
The package contains semantic conventions from the `v1.21.0` version of the OpenTelemetry Semantic Conventions. (#4362)
- Document the `Temporality` and `Aggregation` methods of the `"go.opentelemetry.io/otel/sdk/metric".Exporter"` need to be concurrent safe. (#TBD)

### Changed

Expand Down
6 changes: 6 additions & 0 deletions sdk/metric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ var ErrExporterShutdown = fmt.Errorf("exporter is shutdown")
// the final component in the metric push pipeline.
type Exporter interface {
// Temporality returns the Temporality to use for an instrument kind.
//
// This method needs to be concurrent safe with itself and all the other
// Exporter methods.
Temporality(InstrumentKind) metricdata.Temporality

// Aggregation returns the Aggregation to use for an instrument kind.
//
// This method needs to be concurrent safe with itself and all the other
// Exporter methods.
Aggregation(InstrumentKind) aggregation.Aggregation

// Export serializes and transmits metric data to a receiver.
Expand Down
6 changes: 6 additions & 0 deletions sdk/metric/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ type Reader interface {
RegisterProducer(Producer)

// temporality reports the Temporality for the instrument kind provided.
//
// This method needs to be concurrent safe with itself and all the other
// Reader methods.
temporality(InstrumentKind) metricdata.Temporality

// aggregation returns what Aggregation to use for an instrument kind.
//
// This method needs to be concurrent safe with itself and all the other
// Reader methods.
aggregation(InstrumentKind) aggregation.Aggregation // nolint:revive // import-shadow for method scoped by type.

// Collect gathers and returns all metric data related to the Reader from
Expand Down
12 changes: 12 additions & 0 deletions sdk/metric/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ func (ts *readerTestSuite) TestMethodConcurrentSafe() {
var wg sync.WaitGroup
const threads = 2
for i := 0; i < threads; i++ {
wg.Add(1)
go func() {
defer wg.Done()
_ = ts.Reader.temporality(InstrumentKindCounter)
}()

wg.Add(1)
go func() {
defer wg.Done()
_ = ts.Reader.aggregation(InstrumentKindCounter)
}()

wg.Add(1)
go func() {
defer wg.Done()
Expand Down

0 comments on commit f52b429

Please sign in to comment.