feat(diagnostics): harden ingestion and delivery

This commit is contained in:
2026-07-15 00:43:49 +02:00
parent ead4e09a60
commit b602a3acb6
42 changed files with 22428 additions and 141 deletions

View File

@@ -37,32 +37,61 @@ plugins {
alias(libs.plugins.kotlinAtomicfu)
}
// Compile-time switch (gradle.properties or -Pvnidrop.diagnostics.included=false).
// false: no Share-diagnostics toggle, no telemetry/crash auto-upload stack.
// Compile-time switches (gradle.properties or -P).
// included=false: no Share-diagnostics toggle, no telemetry/crash auto-upload stack.
// endpoint/key both empty: transport is NoOp (safe default until Cloudflare is deployed).
val diagnosticsIncluded: Boolean =
(findProperty("vnidrop.diagnostics.included") as String?)?.toBooleanStrictOrNull() ?: true
val diagnosticsEndpoint: String =
(findProperty("vnidrop.diagnostics.endpoint") as String?)?.trim().orEmpty()
val diagnosticsIngestKey: String =
(findProperty("vnidrop.diagnostics.ingestKey") as String?)?.trim().orEmpty()
check(diagnosticsEndpoint.isEmpty() == diagnosticsIngestKey.isEmpty()) {
"vnidrop.diagnostics.endpoint and vnidrop.diagnostics.ingestKey must be configured together"
}
val diagnosticsBuildConfigDir = layout.buildDirectory.dir("generated/diagnostics/commonMain/kotlin")
val generateDiagnosticsBuildConfig by tasks.registering {
group = "build"
description = "Generates DiagnosticsBuildConfig from vnidrop.diagnostics.included"
description = "Generates DiagnosticsBuildConfig from vnidrop.diagnostics.* properties"
val outputDir = diagnosticsBuildConfigDir
val included = diagnosticsIncluded
val endpoint = diagnosticsEndpoint
val ingestKey = diagnosticsIngestKey
inputs.property("vnidrop.diagnostics.included", included)
inputs.property("vnidrop.diagnostics.endpoint", endpoint)
inputs.property("vnidrop.diagnostics.ingestKey", ingestKey)
outputs.dir(outputDir)
doLast {
val packageDir = outputDir.get().asFile.resolve("com/vnidrop/app/diagnostics")
packageDir.mkdirs()
fun esc(value: String): String = buildString {
for (ch in value) {
when (ch) {
'\\' -> append("\\\\")
'"' -> append("\\\"")
'\n' -> append("\\n")
'\r' -> append("\\r")
'\t' -> append("\\t")
'$' -> append("\\$")
else -> append(ch)
}
}
}
packageDir.resolve("DiagnosticsBuildConfig.kt").writeText(
"""
|package com.vnidrop.app.diagnostics
|
|/**
| * Generated by shared/build.gradle.kts.
| * Override with `-Pvnidrop.diagnostics.included=false` or gradle.properties.
| * Generated by shared/build.gradle.kts from vnidrop.diagnostics.* properties.
| *
| * - included=false → no opt-in UI / telemetry / crash hooks
| * - endpoint/key both empty → [NoOpDiagnosticsTransport] (no network)
| */
|object DiagnosticsBuildConfig {
| const val INCLUDED: Boolean = $included
| const val ENDPOINT: String = "${esc(endpoint)}"
| const val INGEST_KEY: String = "${esc(ingestKey)}"
|}
|
""".trimMargin(),