Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
changliu-wk committed Oct 17, 2024
1 parent b37fbf6 commit d353d01
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/src/sdk/trace/exporters/collector_exporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CollectorExporter implements sdk.SpanExporter {
: client = httpClient ?? http.Client();

@override
void export(List<sdk.ReadOnlySpan> spans) {
void export(List<sdk.ReadOnlySpan> spans) async {
if (_isShutdown) {
return;
}
Expand All @@ -38,7 +38,7 @@ class CollectorExporter implements sdk.SpanExporter {
return;
}

unawaited(_send(uri, spans));
await _send(uri, spans);
}

Future<void> _send(
Expand All @@ -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) {
Expand All @@ -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');
Expand Down

0 comments on commit d353d01

Please sign in to comment.