Просмотр исходного кода

Add telemetry, remove publishable key from create customer handler

Mauricio Araujo 2 лет назад
Родитель
Сommit
d33457e0e4
2 измененных файлов с 12 добавлено и 6 удалено
  1. 9 5
      api/server/handlers/billing/customer.go
  2. 3 1
      api/server/router/project.go

+ 9 - 5
api/server/handlers/billing/customer.go

@@ -41,12 +41,8 @@ func (c *CreateBillingCustomerHandler) ServeHTTP(w http.ResponseWriter, r *http.
 		return
 	}
 
-	// There is no easy way to pass environment variables to the frontend,
-	// so for now pass via the backend. This is acceptable because the key is
-	// meant to be public
-	publishableKey := c.Config().BillingManager.GetPublishableKey(ctx)
 	if proj.BillingID != "" {
-		c.WriteResult(w, r, publishableKey)
+		c.WriteResult(w, r, "")
 		return
 	}
 
@@ -95,9 +91,17 @@ func (c *GetPublishableKeyHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 	ctx, span := telemetry.NewSpan(r.Context(), "get-publishable-key-endpoint")
 	defer span.End()
 
+	proj, _ := ctx.Value(types.ProjectScope).(*models.Project)
+
 	// There is no easy way to pass environment variables to the frontend,
 	// so for now pass via the backend. This is acceptable because the key is
 	// meant to be public
 	publishableKey := c.Config().BillingManager.GetPublishableKey(ctx)
+
+	telemetry.WithAttributes(span,
+		telemetry.AttributeKV{Key: "project-id", Value: proj.ID},
+		telemetry.AttributeKV{Key: "customer-id", Value: proj.BillingID},
+	)
+
 	c.WriteResult(w, r, publishableKey)
 }

+ 3 - 1
api/server/router/project.go

@@ -460,7 +460,9 @@ func getProjectRoutes(
 				Parent:       basePath,
 				RelativePath: relPath + "/billing/publishable_key",
 			},
-			Scopes: []types.PermissionScope{},
+			Scopes: []types.PermissionScope{
+				types.ProjectScope,
+			},
 		},
 	)