diff --git a/internal/server/handlers.go b/internal/server/handlers.go index b9e159bf02..a91992c5d9 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -9,7 +9,6 @@ import ( "time" "github.com/gin-gonic/gin" - "gopkg.in/segmentio/analytics-go.v3" "github.com/infrahq/infra/api" "github.com/infrahq/infra/internal" @@ -514,11 +513,7 @@ func (a *API) Login(c *gin.Context, r *api.LoginRequest) (*api.LoginResponse, er setAuthCookie(c, key, expires) - if a.t != nil { - if err := a.t.Enqueue(analytics.Track{Event: "infra.login.exchange", UserId: identity.ID.String()}); err != nil { - logging.S.Debug(err) - } - } + a.t.Event(c, "login", Properties{"method": "exchange"}) return &api.LoginResponse{PolymorphicID: identity.PolyID(), Name: identity.Name, AccessKey: key, Expires: api.Time(expires)}, nil case r.PasswordCredentials != nil: diff --git a/internal/server/server.go b/internal/server/server.go index abd9d59388..e24a249394 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -143,12 +143,6 @@ func New(options Options) (*Server, error) { return nil, fmt.Errorf("loading certificate provider: %w", err) } - if options.EnableTelemetry { - if err := configureTelemetry(server); err != nil { - return nil, fmt.Errorf("configuring telemetry: %w", err) - } - } - if err := server.setupInternalInfraIdentityProvider(); err != nil { return nil, fmt.Errorf("setting up internal identity provider: %w", err) } @@ -162,6 +156,12 @@ func New(options Options) (*Server, error) { return nil, fmt.Errorf("settings: %w", err) } + if options.EnableTelemetry { + if err := configureTelemetry(server); err != nil { + return nil, fmt.Errorf("configuring telemetry: %w", err) + } + } + sentry.ConfigureScope(func(scope *sentry.Scope) { scope.SetContext("serverId", settings.ID) }) diff --git a/internal/server/telemetry.go b/internal/server/telemetry.go index 2da6c24dfa..4d1aed1ec3 100644 --- a/internal/server/telemetry.go +++ b/internal/server/telemetry.go @@ -27,6 +27,12 @@ func NewTelemetry(db *gorm.DB) (*Telemetry, error) { return nil, errors.New("db cannot be nil") } + var err error + settings, err = data.GetSettings(db) + if err != nil { + return nil, err + } + return &Telemetry{ client: analytics.New(internal.TelemetryWriteKey), db: db, @@ -40,14 +46,6 @@ func (t *Telemetry) Enqueue(track analytics.Message) error { return nil } - if settings == nil { - var err error - settings, err = data.GetSettings(t.db) - if err != nil { - return err - } - } - switch track := track.(type) { case analytics.Track: if track.Properties == nil {