|
|
@@ -5,7 +5,6 @@ import (
|
|
|
"bytes"
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
- "fmt"
|
|
|
"net/http"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
|
@@ -64,25 +63,22 @@ func (c *IngestEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|
|
telemetry.AttributeKV{Key: "usage-events-count", Value: len(ingestEventsRequest.Events)},
|
|
|
)
|
|
|
|
|
|
- // For Porter Cloud events, we apend a prefix to avoid collisions before sending to Lago
|
|
|
- if proj.EnableSandbox {
|
|
|
- for i := range ingestEventsRequest.Events {
|
|
|
- ingestEventsRequest.Events[i].CustomerID = fmt.Sprintf("porter-cloud-%s", ingestEventsRequest.Events[i].CustomerID)
|
|
|
+ var subscriptionID string
|
|
|
+ if !proj.EnableSandbox {
|
|
|
+ plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
|
|
|
+ if err != nil {
|
|
|
+ err := telemetry.Error(ctx, span, err, "error getting active subscription")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ return
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- plan, err := c.Config().BillingManager.LagoClient.GetCustomerActivePlan(ctx, proj.ID, proj.EnableSandbox)
|
|
|
- if err != nil {
|
|
|
- err := telemetry.Error(ctx, span, err, "error getting active subscription")
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
- return
|
|
|
+ subscriptionID = plan.ID
|
|
|
}
|
|
|
|
|
|
telemetry.WithAttributes(span,
|
|
|
- telemetry.AttributeKV{Key: "subscription_id", Value: plan.ID},
|
|
|
+ telemetry.AttributeKV{Key: "subscription_id", Value: subscriptionID},
|
|
|
)
|
|
|
|
|
|
- err = c.Config().BillingManager.LagoClient.IngestEvents(ctx, plan.ID, ingestEventsRequest.Events, proj.EnableSandbox)
|
|
|
+ err := c.Config().BillingManager.LagoClient.IngestEvents(ctx, subscriptionID, ingestEventsRequest.Events, proj.EnableSandbox)
|
|
|
if err != nil {
|
|
|
err := telemetry.Error(ctx, span, err, "error ingesting events")
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|