From 6bda66b44dd741045cafd0aa7223c621712c8dcf Mon Sep 17 00:00:00 2001 From: Vladislav Veselskiy Date: Tue, 28 Jan 2025 16:45:22 +0300 Subject: [PATCH] Set span status to codes.Error. --- fcm.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fcm.go b/fcm.go index b1cb310..dece97f 100644 --- a/fcm.go +++ b/fcm.go @@ -463,17 +463,29 @@ func (c *Client) doSendEachInBatch( // Wait for all Validate/Send calls to finish wg.Wait() - successCount := 0 + successAmount := 0 for _, r := range responses { if r.Success { - successCount++ + successAmount++ } } + failedAmount := len(responses) - successAmount + + span.SetAttributes( + attribute.Int("res.total", len(responses)), + attribute.Int("res.sent", successAmount), + attribute.Int("res.failed", failedAmount), + ) + + if failedAmount > 0 { + span.SetStatus(codes.Error, "Got errors from method Client.Send().") + } + return MessageMultiSendResponse{ Responses: responses, - Sent: successCount, - Failed: len(responses) - successCount, + Sent: successAmount, + Failed: failedAmount, }, nil }