mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-10-30 19:32:39 +08:00
fix(jetbrains): keep telemetry payload on logger
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
package ai.kilocode.backend.dev
|
||||
|
||||
import ai.kilocode.log.KiloEnvironment
|
||||
import ai.kilocode.log.KiloLog
|
||||
|
||||
object KiloDevMode {
|
||||
fun enabled(): Boolean = KiloEnvironment.sandbox()
|
||||
fun enabled(): Boolean = KiloLog.sandbox()
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
package ai.kilocode.backend.telemetry
|
||||
|
||||
import ai.kilocode.backend.dev.KiloDevMode
|
||||
import ai.kilocode.log.KiloEnvironment
|
||||
import ai.kilocode.log.KiloLog
|
||||
import com.intellij.openapi.components.Service
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -62,5 +61,5 @@ class KiloBackendTelemetry(
|
||||
).toString()
|
||||
|
||||
private fun base(): Map<String, JsonPrimitive> =
|
||||
KiloEnvironment.payload(log).mapValues { JsonPrimitive(it.value) }
|
||||
KiloLog.payload(log).mapValues { JsonPrimitive(it.value) }
|
||||
}
|
||||
|
||||
+2
-3
@@ -2,7 +2,6 @@
|
||||
|
||||
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
|
||||
@@ -32,8 +31,8 @@ class KiloTelemetryService internal constructor(
|
||||
}
|
||||
|
||||
fun send(event: String, properties: Map<String, String> = emptyMap()) {
|
||||
if (KiloEnvironment.sandbox()) {
|
||||
val payload = KiloEnvironment.payload(LOG) + properties
|
||||
if (KiloLog.sandbox()) {
|
||||
val payload = KiloLog.payload(LOG) + properties
|
||||
LOG.info("telemetry capture sandbox: event=$event ${payload.entries.joinToString(" ") { "${it.key}=${it.value}" }}")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -48,33 +48,31 @@ interface KiloLog {
|
||||
|
||||
companion object {
|
||||
fun create(cls: Class<*>): KiloLog {
|
||||
if (KiloEnvironment.sandbox()) return FileLog(cls)
|
||||
if (sandbox()) return FileLog(cls)
|
||||
val intellij = IntellijLog(cls)
|
||||
if (!runCatching { KiloPlugin.isRc() }.getOrDefault(false)) return intellij
|
||||
return CompositeLog(intellij, FileLog(cls))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object KiloEnvironment {
|
||||
fun sandbox(): Boolean = System.getProperty("idea.plugin.in.sandbox.mode", "false").toBoolean()
|
||||
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")
|
||||
put("feature", "jetbrains-plugin")
|
||||
runCatching {
|
||||
val info = ApplicationInfo.getInstance()
|
||||
put("editorName", info.fullApplicationName)
|
||||
put("jetbrainsBuild", info.build.asString())
|
||||
}.onFailure { log?.info("Could not read ApplicationInfo for environment payload: ${it.message}") }
|
||||
runCatching {
|
||||
val version = KiloPlugin.version()
|
||||
if (version != null) {
|
||||
put("pluginVersion", version)
|
||||
put("appVersion", version)
|
||||
}
|
||||
}.onFailure { log?.info("Could not read plugin version for environment payload: ${it.message}") }
|
||||
fun payload(log: KiloLog? = null): Map<String, String> = buildMap {
|
||||
put("platform", "jetbrains")
|
||||
put("client", "jetbrains")
|
||||
put("feature", "jetbrains-plugin")
|
||||
runCatching {
|
||||
val info = ApplicationInfo.getInstance()
|
||||
put("editorName", info.fullApplicationName)
|
||||
put("jetbrainsBuild", info.build.asString())
|
||||
}.onFailure { log?.info("Could not read ApplicationInfo for environment payload: ${it.message}") }
|
||||
runCatching {
|
||||
val version = KiloPlugin.version()
|
||||
if (version != null) {
|
||||
put("pluginVersion", version)
|
||||
put("appVersion", version)
|
||||
}
|
||||
}.onFailure { log?.info("Could not read plugin version for environment payload: ${it.message}") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +100,7 @@ internal class FileLog(cls: Class<*>) : KiloLog {
|
||||
|
||||
private val root: java.util.logging.Logger by lazy {
|
||||
val logger = java.util.logging.Logger.getLogger("ai.kilocode")
|
||||
val payload = KiloEnvironment.payload().entries.joinToString(" ") { "${it.key}=${it.value}" }
|
||||
val payload = KiloLog.payload().entries.joinToString(" ") { "${it.key}=${it.value}" }
|
||||
logger.addHandler(handler)
|
||||
logger.useParentHandlers = false
|
||||
logger.level = level
|
||||
|
||||
Reference in New Issue
Block a user