|
| 1 | +import java.io.ByteArrayOutputStream |
1 | 2 | import java.time.LocalDate |
2 | 3 | import java.time.format.DateTimeFormatter |
3 | 4 | import java.util.Properties |
@@ -29,18 +30,34 @@ fun calculateVersion(): Pair<Int, String> { |
29 | 30 | return Pair(runNumber, versionName) |
30 | 31 | } |
31 | 32 |
|
| 33 | +fun resolveGitSha(): String { |
| 34 | + return try { |
| 35 | + val output = ByteArrayOutputStream() |
| 36 | + exec { |
| 37 | + commandLine("git", "rev-parse", "HEAD") |
| 38 | + standardOutput = output |
| 39 | + isIgnoreExitValue = true |
| 40 | + } |
| 41 | + output.toString().trim().ifBlank { "local" } |
| 42 | + } catch (e: Exception) { |
| 43 | + "local" |
| 44 | + } |
| 45 | +} |
| 46 | + |
32 | 47 | android { |
33 | 48 | namespace = "com.dkhalife.tasks" |
34 | 49 | compileSdk = 36 |
35 | 50 |
|
36 | 51 | val (calculatedVersionCode, calculatedVersionName) = calculateVersion() |
| 52 | + val gitSha = resolveGitSha() |
37 | 53 |
|
38 | 54 | defaultConfig { |
39 | 55 | applicationId = "com.dkhalife.tasks" |
40 | 56 | minSdk = 34 |
41 | 57 | targetSdk = 36 |
42 | 58 | versionCode = calculatedVersionCode |
43 | 59 | versionName = calculatedVersionName |
| 60 | + buildConfigField("String", "GIT_SHA", "\"$gitSha\"") |
44 | 61 |
|
45 | 62 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
46 | 63 | } |
@@ -80,6 +97,19 @@ android { |
80 | 97 | if (releaseSigningConfig.storeFile != null) { |
81 | 98 | signingConfig = releaseSigningConfig |
82 | 99 | } |
| 100 | + |
| 101 | + // Note: connection string is embedded in the APK. App Insights ingestion keys are |
| 102 | + // low-sensitivity (write-only, no read access to data). If spoofed telemetry is a |
| 103 | + // concern, consider proxying ingestion through the backend. |
| 104 | + val appInsightsKey = localProperties.getProperty("APPINSIGHTS_CONNECTION_STRING") |
| 105 | + ?: System.getenv("APPINSIGHTS_CONNECTION_STRING") ?: "" |
| 106 | + buildConfigField("String", "APPINSIGHTS_CONNECTION_STRING", "\"$appInsightsKey\"") |
| 107 | + } |
| 108 | + |
| 109 | + debug { |
| 110 | + val appInsightsKey = localProperties.getProperty("APPINSIGHTS_CONNECTION_STRING") |
| 111 | + ?: System.getenv("APPINSIGHTS_CONNECTION_STRING") ?: "" |
| 112 | + buildConfigField("String", "APPINSIGHTS_CONNECTION_STRING", "\"$appInsightsKey\"") |
83 | 113 | } |
84 | 114 | } |
85 | 115 |
|
@@ -138,6 +168,10 @@ dependencies { |
138 | 168 | implementation(libs.androidx.glance.appwidget) |
139 | 169 | implementation(libs.androidx.glance.material3) |
140 | 170 |
|
| 171 | + implementation(libs.opentelemetry.api) |
| 172 | + implementation(libs.opentelemetry.sdk) |
| 173 | + implementation(libs.opentelemetry.exporter.logging) |
| 174 | + |
141 | 175 | testImplementation(libs.junit) |
142 | 176 | androidTestImplementation(libs.androidx.junit) |
143 | 177 | androidTestImplementation(libs.androidx.espresso.core) |
|
0 commit comments