Skip to content

Commit

Permalink
App StartTime with Custom Event
Browse files Browse the repository at this point in the history
  • Loading branch information
jobykorahgeorgeibm committed Aug 1, 2024
1 parent 3e4eb6d commit 916f4c8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
5 changes: 5 additions & 0 deletions android-compose-robotshop/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name=".common.starttimehandler.StartupInitializer"
android:authorities="${applicationId}.instanaagentinitializer"
android:initOrder="2147483647"
android:exported="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.compose.rememberNavController
import com.ibm.instashop.common.starttimehandler.LaunchTimeTracker
import com.ibm.instashop.graphs.base_grapg.RootNavigationGraph
import com.ibm.instashop.ui.theme.RobotShopTheme
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -38,4 +40,7 @@ private fun ShowScreen(context: Context) {
val navHostController = rememberNavController()

RootNavigationGraph(navHostController = navHostController, context = context)
LaunchedEffect(Unit){
LaunchTimeTracker.stopTimer()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ibm.instashop.common.starttimehandler

import com.instana.android.CustomEvent
import com.instana.android.Instana


object LaunchTimeTracker{

private var initialTimeInNanos: Long = 0
var launchTimeInNanos: Long = 0
private var doneTracking = false
fun startTimer(){
this.initialTimeInNanos = System.nanoTime()
}

fun stopTimer():Boolean{
if(doneTracking){
return false
}
launchTimeInNanos = System.nanoTime() - this.initialTimeInNanos;
Instana.reportEvent(CustomEvent("APP_START_TIMINGS").apply {
meta = mapOf(
"APP_START_LOAD_TIME_DURATION" to (launchTimeInNanos/1_000_000).toString()+"ms",
)
})
doneTracking = true
return true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ibm.instashop.common.starttimehandler

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri

class StartupInitializer : ContentProvider() {
override fun onCreate(): Boolean {
LaunchTimeTracker.startTimer()
return true
}

override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? {
return null
}

override fun getType(uri: Uri): String? {
return null
}

override fun insert(uri: Uri, values: ContentValues?): Uri? {
return null
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
return 0
}

override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int {
return 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class App : Application(){
if(dataManager.getString(INSTANA_KEY).isNotEmpty()&&dataManager.getString(INSTANA_URL).isNotEmpty()){
setupInstana(dataManager.getString(INSTANA_KEY),dataManager.getString(INSTANA_URL))
}
setupInstana("dataManager.getString(INSTANA_KEY)","dataManager.getString(INSTANA_URL)")
if(dataManager.getString(Constants.CURRENT_API_VERSION).isNotEmpty()){
CurrentVersionInUse = dataManager.getString(Constants.CURRENT_API_VERSION)
}
Expand Down

0 comments on commit 916f4c8

Please sign in to comment.