fix(jetbrains): keep sandbox telemetry local

This commit is contained in:
kirillk
2026-05-31 12:22:41 -04:00
parent 0d9ea23ec3
commit 2e2f3d924f
4 changed files with 17 additions and 12 deletions
@@ -1,5 +1,7 @@
package ai.kilocode.backend.dev
import ai.kilocode.log.KiloEnvironment
object KiloDevMode {
fun enabled(): Boolean = System.getProperty("idea.plugin.in.sandbox.mode", "false").toBoolean()
fun enabled(): Boolean = KiloEnvironment.sandbox()
}
@@ -20,7 +20,7 @@ class KiloBackendTelemetry(
suspend fun capture(http: OkHttpClient?, port: Int, event: String, properties: Map<String, String>) {
val body = payload(event, properties)
if (KiloDevMode.enabled()) {
log.debug { "telemetry capture dev-mode: $body" }
log.info("telemetry capture sandbox: $body")
return
}
if (http == null || port <= 0) return
@@ -30,7 +30,7 @@ class KiloBackendTelemetry(
suspend fun setEnabled(http: OkHttpClient?, port: Int, enabled: Boolean) {
val body = JsonObject(mapOf("enabled" to JsonPrimitive(enabled))).toString()
if (KiloDevMode.enabled()) {
log.debug { "telemetry setEnabled dev-mode: $body" }
log.info("telemetry setEnabled sandbox: $body")
return
}
if (http == null || port <= 0) return
@@ -2,6 +2,7 @@
package ai.kilocode.client.telemetry
import ai.kilocode.log.KiloEnvironment
import ai.kilocode.log.KiloLog
import ai.kilocode.rpc.KiloAppRpcApi
import ai.kilocode.rpc.dto.TelemetryCaptureDto
@@ -31,6 +32,11 @@ class KiloTelemetryService internal constructor(
}
fun send(event: String, properties: Map<String, String> = emptyMap()) {
if (KiloEnvironment.sandbox()) {
val payload = KiloEnvironment.payload(LOG) + properties
LOG.info("telemetry capture sandbox: event=$event ${payload.entries.joinToString(" ") { "${it.key}=${it.value}" }}")
return
}
cs.launch {
try {
val dto = TelemetryCaptureDto(event, properties)
@@ -24,9 +24,8 @@ import java.util.logging.LogRecord
* which writes to the standard IDE log file.
*
* In sandbox mode (i.e. when running via `./gradlew runIde`, detected via the `idea.plugin.in.sandbox.mode`
* system property), or in RC plugin builds, output is additionally written to a `kilo-dev.log` file inside the
* IDE log directory. This makes it easy to tail frontend and backend logs side-by-side during development or
* RC validation without opening the IDE's own log viewer.
* system property), output is written only to a `kilo-dev.log` file inside the IDE log directory. RC plugin builds
* write to both IntelliJ's log and `kilo-dev.log`.
*
* Usage:
* ```kotlin
@@ -49,19 +48,17 @@ interface KiloLog {
companion object {
fun create(cls: Class<*>): KiloLog {
if (KiloEnvironment.sandbox()) return FileLog(cls)
val intellij = IntellijLog(cls)
if (!fileEnabled()) return intellij
if (!runCatching { KiloPlugin.isRc() }.getOrDefault(false)) return intellij
return CompositeLog(intellij, FileLog(cls))
}
private fun fileEnabled(): Boolean {
if (System.getProperty("idea.plugin.in.sandbox.mode", "false").toBoolean()) return true
return runCatching { KiloPlugin.isRc() }.getOrDefault(false)
}
}
}
object KiloEnvironment {
fun sandbox(): Boolean = System.getProperty("idea.plugin.in.sandbox.mode", "false").toBoolean()
fun payload(log: KiloLog? = null): Map<String, String> = buildMap {
put("platform", "jetbrains")
put("client", "jetbrains")