diff --git a/devbox/common/src/Util.scala b/devbox/common/src/Util.scala index 001fe1c..f1d683a 100644 --- a/devbox/common/src/Util.scala +++ b/devbox/common/src/Util.scala @@ -3,6 +3,8 @@ package devbox.common import java.time.ZoneId import java.time.format.{DateTimeFormatter, FormatStyle} +import io.sentry.event.Event + object Util { val blockSize = 4 * 1024 * 1024 @@ -88,8 +90,13 @@ object Util { } .toMap } + def sentryCapture(e: Throwable): Unit = { io.sentry.Sentry.getContext().addTag("whoami", System.getProperty("user.name")) io.sentry.Sentry.capture(e) } + + def sentryCapture(e: Event): Unit = { + io.sentry.Sentry.capture(e) + } } diff --git a/launcher/src/Instance.scala b/launcher/src/Instance.scala index 2daa4e2..7138b17 100644 --- a/launcher/src/Instance.scala +++ b/launcher/src/Instance.scala @@ -3,10 +3,14 @@ import java.io.EOFException import java.time.ZoneId import java.time.format.DateTimeFormatter +import devbox.common.Util +import io.sentry.event.Event.Level +import io.sentry.event.EventBuilder import software.amazon.awssdk.services.ec2.Ec2Client import software.amazon.awssdk.services.ec2.model._ import scala.collection.JavaConverters._ +import scala.collection.immutable.HashMap import scala.concurrent.duration._ object Instance{ @@ -107,10 +111,22 @@ object Instance{ case _ => ??? } case multiple => + val event = new EventBuilder() + .withMessage("Multiple devbox instances running") + .withLevel(Level.WARNING) + .withTag("whoami", System.getProperty("user.name")) val instanceOptions = multiple.zipWithIndex.map { case (instance, idx) => val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z").withZone(ZoneId.systemDefault()) - s"\t[${idx + 1}] ${instance.instanceId()} (${instance.placement().availabilityZone()}) launched at ${dateFormatter.format(instance.launchTime())}" + val launchTime = dateFormatter.format(instance.launchTime()) + event.withExtra(s"instance-${idx}", Map( + "id" -> instance.instanceId, + "region" -> instance.placement().availabilityZone(), + "launchTime" -> launchTime, + "state" -> instance.state().nameAsString() + )) + s"\t[${idx + 1}] ${instance.instanceId()} (${instance.placement().availabilityZone()}) launched at ${launchTime}" }.mkString("\n") + Util.sentryCapture(event.build()) log(s"Multiple Devbox instances found. Which one would you like to keep? (enter 0 to discard all and get a new one)\n" + instanceOptions) val chosen = readChoice(log) val idsToDelete = (multiple.take(chosen) ++ multiple.drop(chosen + 1)).map(_.instanceId())