Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions devbox/common/src/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -88,8 +90,13 @@ object Util {
}
.toMap
}

def sentryCapture(e: Throwable): Unit = {
io.sentry.Sentry.getContext().addTag("whoami", System.getProperty("user.name"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to reuse this with the Event but for some reason it didn't work. So I ended up adding it on the EventBuilder as well.

io.sentry.Sentry.capture(e)
}

def sentryCapture(e: Event): Unit = {
io.sentry.Sentry.capture(e)
}
}
18 changes: 17 additions & 1 deletion launcher/src/Instance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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())
Expand Down