Skip to content

Commit

Permalink
Merge pull request #916 from getlantern/atavism/datadog-update-geo-co…
Browse files Browse the repository at this point in the history
…untry-code
  • Loading branch information
oxtoacart authored Sep 26, 2023
2 parents 1b1494c + 7610f32 commit fc06a6e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
Binary file modified android/app/libs/alipaySdk-15.7.6-20200521195109.aar
Binary file not shown.
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 @@ -6,8 +6,6 @@ import android.os.StrictMode
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDex
import org.getlantern.lantern.datadog.Datadog
import org.getlantern.lantern.datadog.FlutterExcludingComponentPredicate
import org.getlantern.lantern.model.InAppBilling
import org.getlantern.lantern.model.LanternHttpClient
import org.getlantern.lantern.model.LanternSessionManager
Expand Down Expand Up @@ -48,7 +46,6 @@ open class LanternApp : Application() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
appContext = applicationContext
session = LanternSessionManager(this)
if (!BuildConfig.DEBUG) Datadog.initialize()

LanternProxySelector(session)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.getlantern.lantern.datadog

import android.util.Log
import com.datadog.android.Datadog as DatadogMain
import com.datadog.android.DatadogSite
import com.datadog.android.core.configuration.BatchSize
import com.datadog.android.core.configuration.Configuration
Expand All @@ -17,13 +16,20 @@ import org.getlantern.lantern.LanternApp
import org.getlantern.mobilesdk.Logger
import java.net.InetSocketAddress
import java.net.Proxy
import java.net.URI
import java.util.concurrent.atomic.AtomicBoolean
import com.datadog.android.Datadog as DatadogMain

object Datadog {
private val tracedHosts = listOf(
"datadoghq.eu",
"127.0.0.1",
)
private val tracedHosts =
listOf(
"datadoghq.eu",
"127.0.0.1",
"iantem.io",
"getlantern.org",
"getiantem.org",
"lantern.io",
)
private val initialized = AtomicBoolean()
private lateinit var datadogConfig: Configuration

Expand All @@ -33,13 +39,14 @@ object Datadog {
DatadogMain.setVerbosity(Log.VERBOSE)
datadogConfig = createDatadogConfiguration()

val datadogCredentials = Credentials(
clientToken = "puba617ab01333a95a25a9d3709f04e1654",
envName = "prod",
rumApplicationId = "f8eabf3c-5db3-4f7e-8e6a-5a72433b46d2",
variant = "release",
serviceName = "lantern-android",
)
val datadogCredentials =
Credentials(
clientToken = "puba617ab01333a95a25a9d3709f04e1654",
envName = "prod",
rumApplicationId = "f8eabf3c-5db3-4f7e-8e6a-5a72433b46d2",
variant = "release",
serviceName = "lantern-android",
)

DatadogMain.initialize(
LanternApp.getAppContext(),
Expand All @@ -52,9 +59,20 @@ object Datadog {
id = LanternApp.getSession().userId().toString(),
)

val monitor = RumMonitor.Builder().build()
GlobalRum.registerIfAbsent(monitor)
GlobalRum.registerIfAbsent {
RumMonitor.Builder().build()
}
val session = LanternApp.getSession()
setCountry(session.countryCode)
initialized.set(true)

// For some reason, sessions don't show up in DataDog RUM until we register a user action
// of some sort. So, here we fire the custom action "started" to get data to start flowing.
GlobalRum.get().addUserAction(RumActionType.CUSTOM, "started", emptyMap())
}

fun setCountry(country: String) {
GlobalRum.addAttribute("lantern.country_code", country)
}

fun addError(
Expand All @@ -68,12 +86,12 @@ 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(),
) {
GlobalRum.get().addUserAction(actionType, name, actionAttributes)
GlobalRum.get().addUserAction(actionType, name, actionAttributes)
}

// trackUserClick is used to track user clicks with RumMonitor
Expand All @@ -94,6 +112,8 @@ object Datadog {

private fun createDatadogConfiguration(): Configuration {
val session = LanternApp.getSession()
val hTTPAddr = session.hTTPAddr
val uri = URI("http://" + hTTPAddr)
return Configuration.Builder(
logsEnabled = true,
tracesEnabled = true,
Expand All @@ -105,15 +125,16 @@ object Datadog {
Proxy(
Proxy.Type.HTTP,
InetSocketAddress(
session.settings.httpProxyHost,
session.settings.httpProxyPort.toInt(),
"127.0.0.1",
uri.getPort(),
),
),
null,
)
.sampleRumSessions(100f)
.setUploadFrequency(UploadFrequency.FREQUENT)
.useSite(DatadogSite.EU1)
.trackBackgroundRumEvents(true)
.trackInteractions()
.trackLongTasks()
.setFirstPartyHosts(tracedHosts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.androidannotations.annotations.EService
import org.getlantern.lantern.BuildConfig
import org.getlantern.lantern.LanternApp
import org.getlantern.lantern.R
import org.getlantern.lantern.datadog.Datadog
import org.getlantern.lantern.model.AccountInitializationStatus
import org.getlantern.lantern.model.LanternHttpClient
import org.getlantern.lantern.model.LanternStatus
Expand Down Expand Up @@ -109,6 +110,8 @@ open class LanternService : Service(), Runnable {
createUser(0)
}

Datadog.initialize()

if (!BuildConfig.PLAY_VERSION && !BuildConfig.DEVELOPMENT_MODE) {
// check if an update is available
autoUpdater.checkForUpdates()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/getlantern/dnsgrab v0.0.0-20211216020425-5d5e155a01a8
github.com/getlantern/errors v1.0.3
github.com/getlantern/eventual/v2 v2.0.2
github.com/getlantern/flashlight/v7 v7.6.7
github.com/getlantern/flashlight/v7 v7.6.8
github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65
github.com/getlantern/idletiming v0.0.0-20201229174729-33d04d220c4e
github.com/getlantern/ipproxy v0.0.0-20230511223023-ee52513fd782
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ github.com/getlantern/fdcount v0.0.0-20210503151800-5decd65b3731/go.mod h1:XZwE+
github.com/getlantern/filepersist v0.0.0-20160317154340-c5f0cd24e799/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c h1:mcz27xtAkb1OuOLBct/uFfL1p3XxAIcFct82GbT+UZM=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/flashlight/v7 v7.6.7 h1:61ueXqAv2tzM2TjSfmL14I0oaxf6LhTYK2eHLAx29QQ=
github.com/getlantern/flashlight/v7 v7.6.7/go.mod h1:FLZhyLFeSojL4sRjQEaLRtVl4RB1DdliWegTsIqgzlI=
github.com/getlantern/flashlight/v7 v7.6.8 h1:z4jdHzZuHa0NT98ua8Qx24QIblDViyQ2RfgIxXAfibw=
github.com/getlantern/flashlight/v7 v7.6.8/go.mod h1:FLZhyLFeSojL4sRjQEaLRtVl4RB1DdliWegTsIqgzlI=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede h1:yrU6Px3ZkvCsDLPryPGi6FN+2iqFPq+JeCb7EFoDBhw=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede/go.mod h1:nhnoiS6DE6zfe+BaCMU4YI01UpsuiXnDqM5S8jxHuuI=
github.com/getlantern/fronted v0.0.0-20230601004823-7fec719639d8 h1:r/Z/SPPIfLXDI3QA7/tE6nOfPncrqeUPDjiFjnNGP50=
Expand Down

0 comments on commit fc06a6e

Please sign in to comment.