Skip to content

Commit 57a6a7f

Browse files
committed
Fix dupe metrics export
1 parent a781837 commit 57a6a7f

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • tracer/test/test-applications/integrations/Samples.OpenTelemetrySdk

tracer/test/test-applications/integrations/Samples.OpenTelemetrySdk/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ public static async Task Main(string[] args)
145145
}
146146

147147
#if OTEL_1_2
148-
// Flush OTLP metric batches before Dispose. MeterProviderSdk.Dispose caps its shutdown
149-
// call at 5s, but the first gRPC export (TCP+HTTP/2+TLS handshake) can exceed that and
150-
// the OTel SDK's metric export timeout default is 30s. Force a flush on the critical
151-
// path with the full export timeout instead of racing the 5s shutdown cap.
152-
meterProvider?.ForceFlush(timeoutMilliseconds: 30_000);
153-
meterProvider?.Dispose();
148+
// Shutdown with a generous timeout so the single final Collect+Export can complete even
149+
// when the first gRPC export has to negotiate TCP+HTTP/2+TLS. We avoid ForceFlush-then-
150+
// Dispose because two Collects on cumulative-temporality observable instruments re-emit
151+
// the same cumulative values and produce duplicate resource_metrics batches. Shutdown
152+
// performs exactly one Collect; the `using var` Dispose at end-of-scope no-ops via the
153+
// SDK's internal shutdown-count guard.
154+
meterProvider?.Shutdown(timeoutMilliseconds: 30_000);
154155
#endif
155156
#if OTEL_1_9
156157
// Flush OTLP log batches before the ServiceProvider's `using` disposes them.

0 commit comments

Comments
 (0)