diff --git a/CHANGELOG.md b/CHANGELOG.md index faa6dcfde8..1ab0a2bcd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ the release. ([#1733](https://github.com/open-telemetry/opentelemetry-demo/pull/1733)) * [chore] Move opensearch image version to .env file ([#1743](https://github.com/open-telemetry/opentelemetry-demo/pull/1743)) +* [cartservice] Propagate cartservice exceptions + ([#1744](https://github.com/open-telemetry/opentelemetry-demo/pull/1744)) * [cartservice] Update cart service to fail when cartServiceFailure is enabled ([#1748](https://github.com/open-telemetry/opentelemetry-demo/pull/1748)) diff --git a/src/cartservice/src/services/CartService.cs b/src/cartservice/src/services/CartService.cs index 7c16fce91d..d071c37080 100644 --- a/src/cartservice/src/services/CartService.cs +++ b/src/cartservice/src/services/CartService.cs @@ -33,8 +33,18 @@ public override async Task AddItem(AddItemRequest request, ServerCallCont activity?.SetTag("app.product.id", request.Item.ProductId); activity?.SetTag("app.product.quantity", request.Item.Quantity); - await _cartStore.AddItemAsync(request.UserId, request.Item.ProductId, request.Item.Quantity); - return Empty; + try + { + await _cartStore.AddItemAsync(request.UserId, request.Item.ProductId, request.Item.Quantity); + + return Empty; + } + catch (RpcException ex) + { + activity?.RecordException(ex); + activity?.SetStatus(ActivityStatusCode.Error, ex.Message); + throw; + } } public override async Task GetCart(GetCartRequest request, ServerCallContext context) @@ -43,15 +53,24 @@ public override async Task GetCart(GetCartRequest request, ServerCallConte activity?.SetTag("app.user.id", request.UserId); activity?.AddEvent(new("Fetch cart")); - var cart = await _cartStore.GetCartAsync(request.UserId); - var totalCart = 0; - foreach (var item in cart.Items) + try { - totalCart += item.Quantity; - } - activity?.SetTag("app.cart.items.count", totalCart); + var cart = await _cartStore.GetCartAsync(request.UserId); + var totalCart = 0; + foreach (var item in cart.Items) + { + totalCart += item.Quantity; + } + activity?.SetTag("app.cart.items.count", totalCart); - return cart; + return cart; + } + catch (RpcException ex) + { + activity?.RecordException(ex); + activity?.SetStatus(ActivityStatusCode.Error, ex.Message); + throw; + } } public override async Task EmptyCart(EmptyCartRequest request, ServerCallContext context)