@@ -107,13 +107,16 @@ func sessionSetup(cmd *cobra.Command) (context.Context, *sessionServices, func()
107107 dataDir, _ := cmd.Flags().GetString("data-dir")
108108 ctx := cmd.Context()
109109
110+ cfg, err := config.Init("", dataDir, false)
111+ if err != nil {
112+ return nil, nil, nil, fmt.Errorf("failed to initialize config: %w", err)
113+ }
110114 if dataDir == "" {
111− cfg, err := config.Init("", "", false)
112− if err != nil {
113− return nil, nil, nil, fmt.Errorf("failed to initialize config: %w", err)
114− }
115115 dataDir = cfg.Config().Options.DataDirectory
116116 }
117+ if shouldEnableMetrics(cfg.Config()) {
118+ event.Init()
119+ }
117120
118121 conn, err := db.Connect(ctx, dataDir)
119122 if err != nil {
@@ -130,7 +133,6 @@ func sessionSetup(cmd *cobra.Command) (context.Context, *sessionServices, func()
130133
131134func runSessionList(cmd *cobra.Command, _ []string) error {
132135 event.SetNonInteractive(true)
133− event.SessionListed(sessionListJSON)
134136
135137 ctx, svc, cleanup, err := sessionSetup(cmd)
136138 if err != nil {
@@ -138,6 +140,8 @@ func runSessionList(cmd *cobra.Command, _ []string) error {
138140 }
139141 defer cleanup()
140142
143+ event.SessionListed(sessionListJSON)
144+
141145 list, err := svc.sessions.List(ctx)
142146 if err != nil {
143147 return fmt.Errorf("failed to list sessions: %w", err)
@@ -253,7 +257,6 @@ func resolveSessionID(ctx context.Context, svc session.Service, id string) (sess
253257
254258func runSessionShow(cmd *cobra.Command, args []string) error {
255259 event.SetNonInteractive(true)
256− event.SessionShown(sessionShowJSON)
257260
258261 ctx, svc, cleanup, err := sessionSetup(cmd)
259262 if err != nil {
@@ -261,6 +264,8 @@ func runSessionShow(cmd *cobra.Command, args []string) error {
261264 }
262265 defer cleanup()
263266
267+ event.SessionShown(sessionShowJSON)
268+
264269 sess, err := resolveSessionID(ctx, svc.sessions, args[0])
265270 if err != nil {
266271 return err
@@ -280,7 +285,6 @@ func runSessionShow(cmd *cobra.Command, args []string) error {
280285
281286func runSessionDelete(cmd *cobra.Command, args []string) error {
282287 event.SetNonInteractive(true)
283− event.SessionDeletedCommand(sessionDeleteJSON)
284288
285289 ctx, svc, cleanup, err := sessionSetup(cmd)
286290 if err != nil {
@@ -288,6 +292,8 @@ func runSessionDelete(cmd *cobra.Command, args []string) error {
288292 }
289293 defer cleanup()
290294
295+ event.SessionDeletedCommand(sessionDeleteJSON)
296+
291297 sess, err := resolveSessionID(ctx, svc.sessions, args[0])
292298 if err != nil {
293299 return err
@@ -315,7 +321,6 @@ func runSessionDelete(cmd *cobra.Command, args []string) error {
315321
316322func runSessionRename(cmd *cobra.Command, args []string) error {
317323 event.SetNonInteractive(true)
318− event.SessionRenamed(sessionRenameJSON)
319324
320325 ctx, svc, cleanup, err := sessionSetup(cmd)
321326 if err != nil {
@@ -323,6 +328,8 @@ func runSessionRename(cmd *cobra.Command, args []string) error {
323328 }
324329 defer cleanup()
325330
331+ event.SessionRenamed(sessionRenameJSON)
332+
326333 sess, err := resolveSessionID(ctx, svc.sessions, args[0])
327334 if err != nil {
328335 return err
@@ -351,7 +358,6 @@ func runSessionRename(cmd *cobra.Command, args []string) error {
351358
352359func runSessionLast(cmd *cobra.Command, _ []string) error {
353360 event.SetNonInteractive(true)
354− event.SessionLastShown(sessionLastJSON)
355361
356362 ctx, svc, cleanup, err := sessionSetup(cmd)
357363 if err != nil {
@@ -359,6 +365,8 @@ func runSessionLast(cmd *cobra.Command, _ []string) error {
359365 }
360366 defer cleanup()
361367
368+ event.SessionLastShown(sessionLastJSON)
369+
362370 list, err := svc.sessions.List(ctx)
363371 if err != nil {
364372 return fmt.Errorf("failed to list sessions: %w", err)