Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[checkout] span attributes update #333

Merged
merged 5 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/manual_span_attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ This document contains the list of manual Span Attributes used throughout the de

## CheckoutService

| Name | Type | Description |
|---------------------------|--------|---------------------------------|
| `app.cart.items.count` | number | Number of unique items in cart |
| `app.order.id` | string | Order Id |
| `app.order.shipping.cost` | number | Order shipping cost |
| `app.order.total.cost` | number | Order total cost |
| `app.order.tracking.id` | string | Order shipping tracking Id |
| `app.order.items.count` | number | Number of unique items in order |
| `app.user.currency` | string | User currency |
| `app.user.id` | string | User Id |
| Name | Type | Description |
|------------------------------|--------|---------------------------------|
| `app.cart.items.count` | number | Total number of items in cart |
| `app.order.amount` | number | Order amount |
| `app.order.id` | string | Order Id |
| `app.order.items.count` | number | Number of unique items in order |
| `app.payment.transaction.id` | string | Payment transaction Id |
| `app.shipping.amount` | number | Shipping amount |
| `app.shipping.tracking.id` | string | Shipping tracking Id |
| `app.user.currency` | string | User currency |
| `app.user.id` | string | User Id |

## CurrencyService

Expand Down
16 changes: 10 additions & 6 deletions src/checkoutservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderReq
return nil, status.Errorf(codes.Internal, "failed to charge card: %+v", err)
}
log.Infof("payment went through (transaction_id: %s)", txID)
span.AddEvent("charged", trace.WithAttributes(attribute.String("app.order.transaction.id", txID)))
span.AddEvent("charged", trace.WithAttributes(attribute.String("app.payment.transaction.id", txID)))

shippingTrackingID, err := cs.shipOrder(ctx, req.Address, prep.cartItems)
if err != nil {
return nil, status.Errorf(codes.Unavailable, "shipping error: %+v", err)
}
shippingTrackingAttribute := attribute.String("app.order.tracking.id", shippingTrackingID)
shippingTrackingAttribute := attribute.String("app.shipping.tracking.id", shippingTrackingID)
span.AddEvent("shipped", trace.WithAttributes(shippingTrackingAttribute))

_ = cs.emptyUserCart(ctx, req.UserId)
Expand All @@ -212,8 +212,8 @@ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderReq
span.SetAttributes(
attribute.String("app.order.id", orderID.String()),
shippingTrackingAttribute,
attribute.Float64("app.shipping.cost.total", shippingCostFloat),
attribute.Float64("app.order.total.cost", totalPriceFloat),
attribute.Float64("app.shipping.amount", shippingCostFloat),
attribute.Float64("app.order.amount", totalPriceFloat),
attribute.Int("app.order.items.count", len(prep.orderItems)),
)

Expand Down Expand Up @@ -259,11 +259,15 @@ func (cs *checkoutService) prepareOrderItemsAndShippingQuoteFromCart(ctx context
out.cartItems = cartItems
out.orderItems = orderItems

var totalCart int32
for _, ci := range cartItems {
totalCart += ci.Quantity
}
shippingCostFloat, _ := strconv.ParseFloat(fmt.Sprintf("%d.%02d", shippingPrice.GetUnits(), shippingPrice.GetNanos()/1000000000), 64)

span.SetAttributes(
attribute.Float64("app.shipping.cost.total", shippingCostFloat),
attribute.Int("app.cart.items.count", len(cartItems)),
attribute.Float64("app.shipping.amount", shippingCostFloat),
attribute.Int("app.cart.items.count", int(totalCart)),
attribute.Int("app.order.items.count", len(orderItems)),
)
return out, nil
Expand Down