From 2899fcfdcaf0d5499d2659b93cee7e609da8c65d Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Sun, 30 Jul 2023 13:26:17 -0700 Subject: [PATCH] Document the Reader and Exporter concurrent safe requirements (#4381) --- CHANGELOG.md | 1 + sdk/metric/exporter.go | 6 ++++++ sdk/metric/reader.go | 6 ++++++ sdk/metric/reader_test.go | 12 ++++++++++++ 4 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83f78535e..f73501f88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. (#4381) ### Changed diff --git a/sdk/metric/exporter.go b/sdk/metric/exporter.go index b4f7c7b72..7efb8bf2f 100644 --- a/sdk/metric/exporter.go +++ b/sdk/metric/exporter.go @@ -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. diff --git a/sdk/metric/reader.go b/sdk/metric/reader.go index a281104bd..da68ef336 100644 --- a/sdk/metric/reader.go +++ b/sdk/metric/reader.go @@ -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 diff --git a/sdk/metric/reader_test.go b/sdk/metric/reader_test.go index d375a1b4f..8904d68ee 100644 --- a/sdk/metric/reader_test.go +++ b/sdk/metric/reader_test.go @@ -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()