Skip to content

Commit

Permalink
Update Datadog country every time country changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Sep 25, 2023
1 parent bd1e59f commit 798f399
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.lantern.model.BaseModel
import io.lantern.model.Vpn
import org.getlantern.lantern.BuildConfig
import org.getlantern.lantern.LanternApp
import org.getlantern.lantern.datadog.Datadog
import org.getlantern.lantern.model.Bandwidth
import org.getlantern.lantern.model.Stats
import org.getlantern.lantern.model.Utils
Expand Down Expand Up @@ -385,6 +386,7 @@ abstract class SessionManager(application: Application) : Session {

override fun setCountry(country: String) {
prefs.edit().putString(GEO_COUNTRY_CODE, country).apply()
Datadog.setCountry(country)
}

private val hasUpdatedStats = AtomicBoolean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
import org.getlantern.lantern.LanternApp
import org.getlantern.lantern.BuildConfig
import org.getlantern.mobilesdk.Logger
import org.getlantern.mobilesdk.model.SessionManager
import java.net.InetSocketAddress
import java.net.Proxy
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -57,11 +58,14 @@ object Datadog {
RumMonitor.Builder().build()
}
val session = LanternApp.getSession()
val country = session.getCountryCode()
GlobalRum.addAttribute(GEO_COUNTRY_CODE, country)
setCountry(session.countryCode)
initialized.set(true)
}

fun setCountry(country: String) {
GlobalRum.addAttribute(GEO_COUNTRY_CODE, country)
}

fun addError(
message: String,
throwable: Throwable? = null,
Expand All @@ -73,7 +77,7 @@ object Datadog {

// trackUserAction is used to track specific user actions (such as taps, clicks, and scrolls)
// with RumMonitor
fun trackUserAction(
private fun trackUserAction(
actionType: RumActionType,
name: String,
actionAttributes: Map<String, Any?> = emptyMap(),
Expand Down

0 comments on commit 798f399

Please sign in to comment.