diff --git a/api/server/handlers/billing/credits.go b/api/server/handlers/billing/credits.go index dcbeb6e7e2..033370971f 100644 --- a/api/server/handlers/billing/credits.go +++ b/api/server/handlers/billing/credits.go @@ -35,6 +35,11 @@ func (c *GetCreditsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if !proj.GetFeatureFlag(models.MetronomeEnabled, c.Config().LaunchDarklyClient) { c.WriteResult(w, r, "") + + telemetry.WithAttributes(span, + telemetry.AttributeKV{Key: "metronome-enabled", Value: false}, + ) + return } credits, err := c.Config().BillingManager.MetronomeClient.GetCustomerCredits(proj.UsageID) @@ -44,5 +49,11 @@ func (c *GetCreditsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + telemetry.WithAttributes(span, + telemetry.AttributeKV{Key: "metronome-enabled", Value: true}, + telemetry.AttributeKV{Key: "project-id", Value: proj.ID}, + telemetry.AttributeKV{Key: "usage-id", Value: proj.UsageID}, + ) + c.WriteResult(w, r, credits) } diff --git a/api/server/handlers/billing/list.go b/api/server/handlers/billing/list.go index 4cb47807df..ac386fc0f4 100644 --- a/api/server/handlers/billing/list.go +++ b/api/server/handlers/billing/list.go @@ -84,7 +84,8 @@ func (c *CheckPaymentEnabledHandler) ServeHTTP(w http.ResponseWriter, r *http.Re ) } - if proj.UsageID == uuid.Nil { + if c.Config().ServerConf.MetronomeAPIKey != "" && c.Config().ServerConf.PorterCloudPlanID != "" && + proj.GetFeatureFlag(models.MetronomeEnabled, c.Config().LaunchDarklyClient) && proj.UsageID == uuid.Nil { customerID, customerPlanID, err := c.Config().BillingManager.MetronomeClient.CreateCustomerWithPlan(user.CompanyName, proj.Name, proj.ID, proj.BillingID, c.Config().ServerConf.PorterCloudPlanID) if err != nil { err = telemetry.Error(ctx, span, err, "error creating Metronome customer")