Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 62c03dc

Browse files
committed
[PLAT-26620] Log multiple instances of devbox to sentry
1 parent eb0d7bb commit 62c03dc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

devbox/common/src/Util.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package devbox.common
33
import java.time.ZoneId
44
import java.time.format.{DateTimeFormatter, FormatStyle}
55

6+
import io.sentry.event.Event
7+
68
object Util {
79
val blockSize = 4 * 1024 * 1024
810

@@ -88,8 +90,13 @@ object Util {
8890
}
8991
.toMap
9092
}
93+
9194
def sentryCapture(e: Throwable): Unit = {
9295
io.sentry.Sentry.getContext().addTag("whoami", System.getProperty("user.name"))
9396
io.sentry.Sentry.capture(e)
9497
}
98+
99+
def sentryCapture(e: Event): Unit = {
100+
io.sentry.Sentry.capture(e)
101+
}
95102
}

launcher/src/Instance.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import java.io.EOFException
33
import java.time.ZoneId
44
import java.time.format.DateTimeFormatter
55

6+
import devbox.common.Util
7+
import io.sentry.event.Event.Level
8+
import io.sentry.event.EventBuilder
69
import software.amazon.awssdk.services.ec2.Ec2Client
710
import software.amazon.awssdk.services.ec2.model._
811

912
import scala.collection.JavaConverters._
13+
import scala.collection.immutable.HashMap
1014
import scala.concurrent.duration._
1115

1216
object Instance{
@@ -107,10 +111,22 @@ object Instance{
107111
case _ => ???
108112
}
109113
case multiple =>
114+
val event = new EventBuilder()
115+
.withMessage("Multiple devbox instances running")
116+
.withLevel(Level.WARNING)
117+
.withTag("whoami", System.getProperty("user.name"))
110118
val instanceOptions = multiple.zipWithIndex.map { case (instance, idx) =>
111119
val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z").withZone(ZoneId.systemDefault())
112-
s"\t[${idx + 1}] ${instance.instanceId()} (${instance.placement().availabilityZone()}) launched at ${dateFormatter.format(instance.launchTime())}"
120+
val launchTime = dateFormatter.format(instance.launchTime())
121+
event.withExtra(s"instance-${idx}", Map(
122+
"id" -> instance.instanceId,
123+
"region" -> instance.placement().availabilityZone(),
124+
"launchTime" -> launchTime,
125+
"state" -> instance.state().nameAsString()
126+
))
127+
s"\t[${idx + 1}] ${instance.instanceId()} (${instance.placement().availabilityZone()}) launched at ${launchTime}"
113128
}.mkString("\n")
129+
Util.sentryCapture(event.build())
114130
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)
115131
val chosen = readChoice(log)
116132
val idsToDelete = (multiple.take(chosen) ++ multiple.drop(chosen + 1)).map(_.instanceId())

0 commit comments

Comments
 (0)