Skip to content

Commit 082b792

Browse files
runningcodeclaude
andcommitted
ref(telemetry): Use kotlin.concurrent.thread for org lookup
Replace the manual Thread { }.apply { isDaemon = true; name = ...; start() } with the kotlin.concurrent.thread helper, which creates, configures, and starts the daemon thread in a single call. Behavior is unchanged: the sentry-cli org lookup still runs as a named daemon thread so it never blocks or outlives the build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 73d9f21 commit 082b792

1 file changed

Lines changed: 34 additions & 40 deletions

File tree

plugin-build/src/main/kotlin/io/sentry/android/gradle/telemetry/SentryTelemetryService.kt

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import io.sentry.gradle.common.SentryVariant
2828
import io.sentry.protocol.Mechanism
2929
import io.sentry.protocol.User
3030
import java.util.concurrent.TimeUnit
31+
import kotlin.concurrent.thread
3132
import org.gradle.api.Project
3233
import org.gradle.api.Task
3334
import org.gradle.api.file.DirectoryProperty
@@ -223,54 +224,47 @@ abstract class SentryTelemetryService : BuildService<None>, BuildOperationListen
223224
val projectDir = params.cliProjectDir ?: return
224225
val rootDir = params.cliRootDir ?: return
225226

226-
Thread {
227-
try {
228-
val cliPath = SentryCliProvider.getSentryCliPath(projectDir, buildDir, rootDir)
229-
val resolvedCli = SentryCliProvider.maybeExtractFromResources(buildDir, cliPath)
230-
231-
val args = mutableListOf(resolvedCli)
232-
params.cliUrl?.let { url ->
233-
args.add("--url")
234-
args.add(url)
235-
}
236-
args.add("--log-level=error")
237-
args.add("info")
227+
thread(isDaemon = true, name = "sentry-cli-info") {
228+
try {
229+
val cliPath = SentryCliProvider.getSentryCliPath(projectDir, buildDir, rootDir)
230+
val resolvedCli = SentryCliProvider.maybeExtractFromResources(buildDir, cliPath)
238231

239-
val processBuilder = ProcessBuilder(args).redirectErrorStream(true)
240-
params.cliPropertiesFilePath?.let {
241-
processBuilder.environment()["SENTRY_PROPERTIES"] = it
242-
}
243-
params.cliAuthToken?.let { processBuilder.environment()["SENTRY_AUTH_TOKEN"] = it }
244-
processBuilder.environment()["SENTRY_PIPELINE"] =
245-
"sentry-gradle-plugin/${BuildConfig.Version}"
246-
247-
val process = processBuilder.start()
248-
val output = process.inputStream.bufferedReader().readText()
249-
if (!process.waitFor(CLI_INFO_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
250-
process.destroyForcibly()
251-
return@Thread
252-
}
232+
val args = mutableListOf(resolvedCli)
233+
params.cliUrl?.let { url ->
234+
args.add("--url")
235+
args.add(url)
236+
}
237+
args.add("--log-level=error")
238+
args.add("info")
239+
240+
val processBuilder = ProcessBuilder(args).redirectErrorStream(true)
241+
params.cliPropertiesFilePath?.let { processBuilder.environment()["SENTRY_PROPERTIES"] = it }
242+
params.cliAuthToken?.let { processBuilder.environment()["SENTRY_AUTH_TOKEN"] = it }
243+
processBuilder.environment()["SENTRY_PIPELINE"] =
244+
"sentry-gradle-plugin/${BuildConfig.Version}"
245+
246+
val process = processBuilder.start()
247+
val output = process.inputStream.bufferedReader().readText()
248+
if (!process.waitFor(CLI_INFO_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
249+
process.destroyForcibly()
250+
return@thread
251+
}
253252

254-
if (process.exitValue() == 0) {
255-
ORG_REGEX.find(output)?.groupValues?.getOrNull(1)?.let { org ->
256-
if (org != "-") {
257-
hub.configureScope { scope ->
258-
if (scope.user?.id == null) {
259-
scope.user = User().also { it.id = org }
260-
}
253+
if (process.exitValue() == 0) {
254+
ORG_REGEX.find(output)?.groupValues?.getOrNull(1)?.let { org ->
255+
if (org != "-") {
256+
hub.configureScope { scope ->
257+
if (scope.user?.id == null) {
258+
scope.user = User().also { it.id = org }
261259
}
262260
}
263261
}
264262
}
265-
} catch (t: Throwable) {
266-
SentryPlugin.logger.info { "Failed to fetch default org from sentry-cli: ${t.message}" }
267263
}
264+
} catch (t: Throwable) {
265+
SentryPlugin.logger.info { "Failed to fetch default org from sentry-cli: ${t.message}" }
268266
}
269-
.apply {
270-
isDaemon = true
271-
name = "sentry-cli-info"
272-
start()
273-
}
267+
}
274268
}
275269

276270
override fun close() {

0 commit comments

Comments
 (0)