From d353d0102f306636b6accbd035038b8e7e30d79e Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Thu, 17 Oct 2024 15:19:16 -0400 Subject: [PATCH] update --- .../trace/exporters/collector_exporter.dart | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/src/sdk/trace/exporters/collector_exporter.dart b/lib/src/sdk/trace/exporters/collector_exporter.dart index e2a63321..b11555d3 100644 --- a/lib/src/sdk/trace/exporters/collector_exporter.dart +++ b/lib/src/sdk/trace/exporters/collector_exporter.dart @@ -29,7 +29,7 @@ class CollectorExporter implements sdk.SpanExporter { : client = httpClient ?? http.Client(); @override - void export(List spans) { + void export(List spans) async { if (_isShutdown) { return; } @@ -38,7 +38,7 @@ class CollectorExporter implements sdk.SpanExporter { return; } - unawaited(_send(uri, spans)); + await _send(uri, spans); } Future _send( @@ -48,13 +48,14 @@ class CollectorExporter implements sdk.SpanExporter { const maxRetries = 3; const retryDelay = Duration(seconds: 1); var retries = 0; - while (retries < maxRetries) { - try { - final body = pb_trace_service.ExportTraceServiceRequest( - resourceSpans: _spansToProtobuf(spans)); - final headers = {'Content-Type': 'application/x-protobuf'} - ..addAll(this.headers); + final body = pb_trace_service.ExportTraceServiceRequest( + resourceSpans: _spansToProtobuf(spans)); + final headers = {'Content-Type': 'application/x-protobuf'} + ..addAll(this.headers); + + while (retries++ < maxRetries) { + try { final response = await client.post(uri, body: body.writeToBuffer(), headers: headers); if (response.statusCode == 200) { @@ -65,10 +66,7 @@ class CollectorExporter implements sdk.SpanExporter { } catch (e, statckTrace) { _log.warning('Failed to export ${spans.length} spans.', e, statckTrace); } - retries++; - if (retries < maxRetries) { - await Future.delayed(retryDelay); - } + await Future.delayed(retryDelay); } _log.severe( 'Failed to export ${spans.length} spans after $maxRetries retries');