Skip to content

Commit 81059e8

Browse files
committed
gate timeout changes behind the feature gate
1 parent f9603a9 commit 81059e8

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

sdk/metric/periodic_reader.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ func (r *PeriodicReader) cardinalityLimit(kind InstrumentKind) (int, bool) {
240240
// collectAndExport gather all metric data related to the periodicReader r from
241241
// the SDK and exports it with r's exporter.
242242
func (r *PeriodicReader) collectAndExport(ctx context.Context) error {
243+
if !x.MetricExportBatchSize.Enabled() {
244+
var cancel context.CancelFunc
245+
ctx, cancel = context.WithTimeoutCause(ctx, r.timeout, errors.New("reader collect and export timeout"))
246+
defer cancel()
247+
}
243248
// TODO (#3047): Use a sync.Pool or persistent pointer instead of allocating rm every Collect.
244249
rm := r.rmPool.Get().(*metricdata.ResourceMetrics)
245250
err := r.Collect(ctx, rm)
@@ -277,8 +282,11 @@ func (r *PeriodicReader) Collect(ctx context.Context, rm *metricdata.ResourceMet
277282

278283
// collect unwraps p as a produceHolder and returns its produce results.
279284
func (r *PeriodicReader) collect(ctx context.Context, p any, rm *metricdata.ResourceMetrics) error {
280-
ctx, cancel := context.WithTimeoutCause(ctx, r.timeout, errors.New("reader collect timeout"))
281-
defer cancel()
285+
if x.MetricExportBatchSize.Enabled() {
286+
var cancel context.CancelFunc
287+
ctx, cancel = context.WithTimeoutCause(ctx, r.timeout, errors.New("reader collect timeout"))
288+
defer cancel()
289+
}
282290

283291
var err error
284292
if r.inst != nil {
@@ -320,8 +328,11 @@ func (r *PeriodicReader) collect(ctx context.Context, p any, rm *metricdata.Reso
320328

321329
// export exports metric data m using r's exporter.
322330
func (r *PeriodicReader) export(ctx context.Context, m *metricdata.ResourceMetrics) error {
323-
ctx, cancel := context.WithTimeoutCause(ctx, r.timeout, errors.New("reader export timeout"))
324-
defer cancel()
331+
if x.MetricExportBatchSize.Enabled() {
332+
var cancel context.CancelFunc
333+
ctx, cancel = context.WithTimeoutCause(ctx, r.timeout, errors.New("reader export timeout"))
334+
defer cancel()
335+
}
325336
return r.exporter.Export(ctx, m)
326337
}
327338

0 commit comments

Comments
 (0)