diff --git a/cmd/cart/checkout_server.go b/cmd/cart/checkout_server.go index dca800f..44d7633 100644 --- a/cmd/cart/checkout_server.go +++ b/cmd/cart/checkout_server.go @@ -65,7 +65,7 @@ func (a *App) HandleCheckoutRequests(amqpUrl string, mux *http.ServeMux, invento orderId := r.URL.Query().Get("order_id") log.Printf("Order confirmation push: %s", orderId) - order, err := a.klarnaClient.GetOrder(orderId) + order, err := a.klarnaClient.GetOrder(r.Context(), orderId) if err != nil { log.Printf("Error creating request: %v\n", err) @@ -105,7 +105,7 @@ func (a *App) HandleCheckoutRequests(amqpUrl string, mux *http.ServeMux, invento mux.HandleFunc("GET /confirmation/{order_id}", func(w http.ResponseWriter, r *http.Request) { orderId := r.PathValue("order_id") - order, err := a.klarnaClient.GetOrder(orderId) + order, err := a.klarnaClient.GetOrder(r.Context(), orderId) if err != nil { w.WriteHeader(http.StatusInternalServerError) diff --git a/cmd/cart/klarna-client.go b/cmd/cart/klarna-client.go index 0e0a95e..b36f2b5 100644 --- a/cmd/cart/klarna-client.go +++ b/cmd/cart/klarna-client.go @@ -31,11 +31,14 @@ const ( KlarnaPlaygroundUrl = "https://api.playground.klarna.com" ) -func (k *KlarnaClient) GetOrder(orderId string) (*CheckoutOrder, error) { +func (k *KlarnaClient) GetOrder(ctx context.Context, orderId string) (*CheckoutOrder, error) { req, err := http.NewRequest("GET", k.Url+"/checkout/v3/orders/"+orderId, nil) if err != nil { return nil, err } + spanCtx, span := tracer.Start(ctx, "Get klarna order") + defer span.End() + req = req.WithContext(spanCtx) req.Header.Add("Content-Type", "application/json") req.SetBasicAuth(k.UserName, k.Password) diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index 32230f7..2705ea0 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -592,7 +592,7 @@ func (s *PoolServer) CheckoutHandler(fn func(order *CheckoutOrder, w http.Respon s.ApplyCheckoutStarted(order, cartId) return fn(order, w) } - order, err := s.klarnaClient.GetOrder(orderId) + order, err := s.klarnaClient.GetOrder(r.Context(), orderId) if err != nil { return err }