Skip to content

Commit

Permalink
feat(android): implement core API for perf tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaysood committed Dec 10, 2024
1 parent 15fc9dd commit 782c866
Show file tree
Hide file tree
Showing 116 changed files with 4,861 additions and 777 deletions.
2 changes: 1 addition & 1 deletion android/docs/internal-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ has been ignored for now.
# Batching & export

Events are sent to the server in batches at regular intervals (30s) while the app is in foreground and when the app
goes to background.
goes to background.

* [Periodic batching and export](#periodic-batching-and-export)
* [Exceptions and ANRs export](#exceptions-and-anrs-export)
Expand Down
62 changes: 60 additions & 2 deletions android/measure/api/measure.api
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ public final class sh/measure/android/Measure {
public static final field $stable I
public static final field INSTANCE Lsh/measure/android/Measure;
public static final fun clearUserId ()V
public final fun createSpan (Ljava/lang/String;)Lsh/measure/android/tracing/SpanBuilder;
public final fun getCurrentSpan ()Lsh/measure/android/tracing/Span;
public final fun getCurrentTime ()J
public final fun getTraceParentHeaderKey ()Ljava/lang/String;
public final fun getTraceParentHeaderValue (Lsh/measure/android/tracing/Span;)Ljava/lang/String;
public static final fun init (Landroid/content/Context;)V
public static final fun init (Landroid/content/Context;Lsh/measure/android/config/MeasureConfig;)V
public static synthetic fun init$default (Landroid/content/Context;Lsh/measure/android/config/MeasureConfig;ILjava/lang/Object;)V
public static final fun setUserId (Ljava/lang/String;)V
public final fun start ()V
public final fun startSpan (Ljava/lang/String;)Lsh/measure/android/tracing/Span;
public final fun startSpan (Ljava/lang/String;J)Lsh/measure/android/tracing/Span;
public final fun startSpan (Ljava/lang/String;JZ)Lsh/measure/android/tracing/Span;
public final fun startSpan (Ljava/lang/String;Z)Lsh/measure/android/tracing/Span;
public final fun stop ()V
public static final fun trackHandledException (Ljava/lang/Throwable;)V
public static final fun trackNavigation (Ljava/lang/String;)V
Expand All @@ -26,15 +35,16 @@ public final class sh/measure/android/Measure {
public final class sh/measure/android/config/MeasureConfig : sh/measure/android/config/IMeasureConfig {
public static final field $stable I
public fun <init> ()V
public fun <init> (ZZLsh/measure/android/config/ScreenshotMaskLevel;ZZLjava/util/List;Ljava/util/List;Ljava/util/List;ZFZ)V
public synthetic fun <init> (ZZLsh/measure/android/config/ScreenshotMaskLevel;ZZLjava/util/List;Ljava/util/List;Ljava/util/List;ZFZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (ZZLsh/measure/android/config/ScreenshotMaskLevel;ZZLjava/util/List;Ljava/util/List;Ljava/util/List;ZFZF)V
public synthetic fun <init> (ZZLsh/measure/android/config/ScreenshotMaskLevel;ZZLjava/util/List;Ljava/util/List;Ljava/util/List;ZFZFILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getAutoStart ()Z
public fun getEnableLogging ()Z
public fun getHttpHeadersBlocklist ()Ljava/util/List;
public fun getHttpUrlAllowlist ()Ljava/util/List;
public fun getHttpUrlBlocklist ()Ljava/util/List;
public fun getSamplingRateForErrorFreeSessions ()F
public fun getScreenshotMaskLevel ()Lsh/measure/android/config/ScreenshotMaskLevel;
public fun getTraceSamplingRate ()F
public fun getTrackActivityIntentData ()Z
public fun getTrackHttpBody ()Z
public fun getTrackHttpHeaders ()Z
Expand Down Expand Up @@ -67,3 +77,51 @@ public final class sh/measure/android/okhttp/MeasureOkHttpApplicationInterceptor
public fun intercept (Lokhttp3/Interceptor$Chain;)Lokhttp3/Response;
}

public final class sh/measure/android/tracing/Checkpoint {
public static final field $stable I
public fun <init> (Ljava/lang/String;J)V
public fun equals (Ljava/lang/Object;)Z
public final fun getName ()Ljava/lang/String;
public final fun getTimestamp ()J
public fun hashCode ()I
}

public abstract interface class sh/measure/android/tracing/Scope : java/lang/AutoCloseable {
}

public abstract interface class sh/measure/android/tracing/Span {
public static final field Companion Lsh/measure/android/tracing/Span$Companion;
public abstract fun end ()Lsh/measure/android/tracing/Span;
public abstract fun end (J)Lsh/measure/android/tracing/Span;
public abstract fun getDuration ()J
public abstract fun getParentId ()Ljava/lang/String;
public abstract fun getSpanId ()Ljava/lang/String;
public abstract fun getTraceId ()Ljava/lang/String;
public abstract fun hasEnded ()Z
public abstract fun isSampled ()Z
public abstract fun makeCurrent ()Lsh/measure/android/tracing/Scope;
public abstract fun setCheckpoint (Ljava/lang/String;)Lsh/measure/android/tracing/Span;
public abstract fun setParent (Lsh/measure/android/tracing/Span;)Lsh/measure/android/tracing/Span;
public abstract fun setStatus (Lsh/measure/android/tracing/SpanStatus;)Lsh/measure/android/tracing/Span;
public abstract fun withScope (Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
}

public final class sh/measure/android/tracing/Span$Companion {
}

public abstract interface class sh/measure/android/tracing/SpanBuilder {
public abstract fun setNoParent ()Lsh/measure/android/tracing/SpanBuilder;
public abstract fun setParent (Lsh/measure/android/tracing/Span;)Lsh/measure/android/tracing/SpanBuilder;
public abstract fun startSpan ()Lsh/measure/android/tracing/Span;
public abstract fun startSpan (J)Lsh/measure/android/tracing/Span;
}

public final class sh/measure/android/tracing/SpanStatus : java/lang/Enum {
public static final field Error Lsh/measure/android/tracing/SpanStatus;
public static final field Ok Lsh/measure/android/tracing/SpanStatus;
public static final field Unset Lsh/measure/android/tracing/SpanStatus;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lsh/measure/android/tracing/SpanStatus;
public static fun values ()[Lsh/measure/android/tracing/SpanStatus;
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FakeConfigProvider : ConfigProvider {
override var httpUrlAllowlist: List<String> = emptyList()
override var trackActivityIntentData: Boolean = true
override var samplingRateForErrorFreeSessions: Float = 1f
override val traceSamplingRate: Float = 1f
override var maxAttachmentSizeInEventsBatchInBytes: Int = 1_000_000
override var eventsBatchingIntervalMs: Long = 1_000_000
override var maxEventsInBatch: Int = 1_000_000
Expand All @@ -47,6 +48,9 @@ class FakeConfigProvider : ConfigProvider {
override var screenshotMaskHexColor: String = "#222222"
override var screenshotCompressionQuality: Int = 100
override var eventTypeExportAllowList: List<String> = emptyList()
override var maxEventsInDatabase: Int = 50000
override val autoStart: Boolean = true
override var maxSignalsInDatabase: Int = 50000
override val maxSpanNameLength: Int = 64
override val maxCheckpointNameLength: Int = 64
override val maxCheckpointsPerSpan: Int = 32
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sh.measure.android

import sh.measure.android.exporter.PeriodicEventExporter
import sh.measure.android.exporter.PeriodicExporter

internal class NoopPeriodicEventExporter : PeriodicEventExporter {
internal class NoopPeriodicExporter : PeriodicExporter {
override fun register() {
// No-op
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ import sh.measure.android.config.ConfigProvider
import sh.measure.android.config.ConfigProviderImpl
import sh.measure.android.config.MeasureConfig
import sh.measure.android.events.DefaultEventTransformer
import sh.measure.android.events.EventProcessor
import sh.measure.android.events.EventProcessorImpl
import sh.measure.android.events.EventTransformer
import sh.measure.android.events.SignalProcessor
import sh.measure.android.events.SignalProcessorImpl
import sh.measure.android.events.UserTriggeredEventCollector
import sh.measure.android.events.UserTriggeredEventCollectorImpl
import sh.measure.android.exceptions.UnhandledExceptionCollector
import sh.measure.android.executors.ExecutorServiceRegistry
import sh.measure.android.executors.ExecutorServiceRegistryImpl
import sh.measure.android.exporter.BatchCreator
import sh.measure.android.exporter.BatchCreatorImpl
import sh.measure.android.exporter.EventExporter
import sh.measure.android.exporter.EventExporterImpl
import sh.measure.android.exporter.ExceptionExporter
import sh.measure.android.exporter.ExceptionExporterImpl
import sh.measure.android.exporter.Exporter
import sh.measure.android.exporter.ExporterImpl
import sh.measure.android.exporter.NetworkClient
import sh.measure.android.exporter.NetworkClientImpl
import sh.measure.android.exporter.PeriodicEventExporter
import sh.measure.android.exporter.PeriodicExporter
import sh.measure.android.gestures.GestureCollector
import sh.measure.android.layoutinspector.LayoutSnapshotThrottler
import sh.measure.android.lifecycle.ActivityLifecycleCollector
Expand All @@ -64,18 +64,25 @@ import sh.measure.android.storage.DataCleanupService
import sh.measure.android.storage.DataCleanupServiceImpl
import sh.measure.android.storage.Database
import sh.measure.android.storage.DatabaseImpl
import sh.measure.android.storage.EventStore
import sh.measure.android.storage.EventStoreImpl
import sh.measure.android.storage.FileStorage
import sh.measure.android.storage.FileStorageImpl
import sh.measure.android.storage.PrefsStorage
import sh.measure.android.storage.PrefsStorageImpl
import sh.measure.android.storage.SignalStore
import sh.measure.android.storage.SignalStoreImpl
import sh.measure.android.tracing.MsrSpanProcessor
import sh.measure.android.tracing.MsrTracer
import sh.measure.android.tracing.SpanProcessor
import sh.measure.android.tracing.TraceSampler
import sh.measure.android.tracing.TraceSamplerImpl
import sh.measure.android.tracing.Tracer
import sh.measure.android.utils.AndroidSystemClock
import sh.measure.android.utils.AndroidTimeProvider
import sh.measure.android.utils.DebugProvider
import sh.measure.android.utils.DefaultDebugProvider
import sh.measure.android.utils.DefaultRuntimeProvider
import sh.measure.android.utils.IdProvider
import sh.measure.android.utils.IdProviderImpl
import sh.measure.android.utils.LocaleProvider
import sh.measure.android.utils.LocaleProviderImpl
import sh.measure.android.utils.LowMemoryCheck
Expand All @@ -88,13 +95,14 @@ import sh.measure.android.utils.ProcProvider
import sh.measure.android.utils.ProcProviderImpl
import sh.measure.android.utils.ProcessInfoProvider
import sh.measure.android.utils.ProcessInfoProviderImpl
import sh.measure.android.utils.Randomizer
import sh.measure.android.utils.RandomizerImpl
import sh.measure.android.utils.ResumedActivityProvider
import sh.measure.android.utils.ResumedActivityProviderImpl
import sh.measure.android.utils.RuntimeProvider
import sh.measure.android.utils.SystemServiceProvider
import sh.measure.android.utils.SystemServiceProviderImpl
import sh.measure.android.utils.TimeProvider
import sh.measure.android.utils.UUIDProvider

internal class TestMeasureInitializer(
private val application: Application,
Expand Down Expand Up @@ -127,7 +135,8 @@ internal class TestMeasureInitializer(
logger = logger,
fileStorage = fileStorage,
),
private val idProvider: IdProvider = UUIDProvider(),
private val randomizer: Randomizer = RandomizerImpl(),
private val idProvider: IdProvider = IdProviderImpl(randomizer),
override val processInfoProvider: ProcessInfoProvider = ProcessInfoProviderImpl(),
private val prefsStorage: PrefsStorage = PrefsStorageImpl(
context = application,
Expand All @@ -144,6 +153,7 @@ internal class TestMeasureInitializer(
configProvider = configProvider,
ioExecutor = executorServiceRegistry.ioExecutor(),
packageInfoProvider = packageInfoProvider,
randomizer = randomizer,
),
private val procProvider: ProcProvider = ProcProviderImpl(),
private val debugProvider: DebugProvider = DefaultDebugProvider(),
Expand Down Expand Up @@ -214,7 +224,7 @@ internal class TestMeasureInitializer(
private val eventTransformer: EventTransformer = DefaultEventTransformer(
configProvider = configProvider,
),
private val eventStore: EventStore = EventStoreImpl(
private val signalStore: SignalStore = SignalStoreImpl(
logger = logger,
database = database,
fileStorage = fileStorage,
Expand All @@ -239,7 +249,7 @@ internal class TestMeasureInitializer(
configProvider = configProvider,
idProvider = idProvider,
),
private val eventExporter: EventExporter = EventExporterImpl(
private val exporter: Exporter = ExporterImpl(
logger = logger,
database = database,
networkClient = networkClient,
Expand All @@ -249,12 +259,12 @@ internal class TestMeasureInitializer(
private val exceptionExporter: ExceptionExporter = ExceptionExporterImpl(
logger = logger,
exportExecutor = executorServiceRegistry.eventExportExecutor(),
eventExporter = eventExporter,
exporter = exporter,
),
override val eventProcessor: EventProcessor = EventProcessorImpl(
override val signalProcessor: SignalProcessor = SignalProcessorImpl(
logger = logger,
ioExecutor = executorServiceRegistry.ioExecutor(),
eventStore = eventStore,
signalStore = signalStore,
idProvider = idProvider,
sessionManager = sessionManager,
attributeProcessors = attributeProcessors,
Expand All @@ -265,22 +275,22 @@ internal class TestMeasureInitializer(
userDefinedAttribute = userDefinedAttribute,
),
override val userTriggeredEventCollector: UserTriggeredEventCollector = UserTriggeredEventCollectorImpl(
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
timeProvider = timeProvider,
processInfoProvider = processInfoProvider,
),
override val periodicEventExporter: PeriodicEventExporter = NoopPeriodicEventExporter(),
override val periodicExporter: PeriodicExporter = NoopPeriodicExporter(),
override val unhandledExceptionCollector: UnhandledExceptionCollector = UnhandledExceptionCollector(
logger = logger,
timeProvider = timeProvider,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
processInfo = processInfoProvider,
),
private val nativeBridgeImpl: NativeBridgeImpl = NativeBridgeImpl(logger),
override val anrCollector: AnrCollector = AnrCollector(
logger = logger,
processInfo = processInfoProvider,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
nativeBridge = nativeBridgeImpl,
),
private val appExitProvider: AppExitProvider = AppExitProviderImpl(
Expand All @@ -290,23 +300,23 @@ internal class TestMeasureInitializer(
override val appExitCollector: AppExitCollector = AppExitCollector(
appExitProvider = appExitProvider,
ioExecutor = executorServiceRegistry.ioExecutor(),
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
sessionManager = sessionManager,
database = database,
logger = logger,
),
override val cpuUsageCollector: CpuUsageCollector = CpuUsageCollector(
logger = logger,
timeProvider = timeProvider,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
processInfo = processInfoProvider,
procProvider = procProvider,
osSysConfProvider = osSysConfProvider,
defaultExecutor = executorServiceRegistry.defaultExecutor(),
),
override val memoryUsageCollector: MemoryUsageCollector = MemoryUsageCollector(
logger = logger,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
timeProvider = timeProvider,
defaultExecutor = executorServiceRegistry.defaultExecutor(),
memoryReader = memoryReader,
Expand All @@ -315,13 +325,13 @@ internal class TestMeasureInitializer(
override val componentCallbacksCollector: ComponentCallbacksCollector = ComponentCallbacksCollector(
application = application,
timeProvider = timeProvider,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
),
override val appLifecycleManager: AppLifecycleManager = AppLifecycleManager(
application = application,
),
override val activityLifecycleCollector: ActivityLifecycleCollector = ActivityLifecycleCollector(
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
timeProvider = timeProvider,
appLifecycleManager = appLifecycleManager,
),
Expand All @@ -332,7 +342,7 @@ internal class TestMeasureInitializer(
),
override val gestureCollector: GestureCollector = GestureCollector(
logger = logger,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
timeProvider = timeProvider,
defaultExecutor = executorServiceRegistry.defaultExecutor(),
layoutSnapshotThrottler = LayoutSnapshotThrottler(timeProvider),
Expand All @@ -341,14 +351,14 @@ internal class TestMeasureInitializer(
override val appLaunchCollector: AppLaunchCollector = AppLaunchCollector(
logger = logger,
application = application,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
timeProvider = timeProvider,
launchTracker = launchTracker,
),
override val networkChangesCollector: NetworkChangesCollector = NetworkChangesCollector(
logger = logger,
context = application,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
systemServiceProvider = systemServiceProvider,
timeProvider = timeProvider,
networkStateProvider = networkStateProvider,
Expand All @@ -363,7 +373,25 @@ internal class TestMeasureInitializer(
),
override val httpEventCollector: HttpEventCollector = OkHttpEventCollectorImpl(
logger = logger,
eventProcessor = eventProcessor,
signalProcessor = signalProcessor,
timeProvider = timeProvider,
),
private val spanProcessor: SpanProcessor = MsrSpanProcessor(
signalProcessor = signalProcessor,
attributeProcessors = emptyList(),
logger = logger,
configProvider = configProvider,
),
private val traceSampler: TraceSampler = TraceSamplerImpl(
randomizer = randomizer,
configProvider = configProvider,
),
override val tracer: Tracer = MsrTracer(
logger = logger,
sessionManager = sessionManager,
spanProcessor = spanProcessor,
idProvider = idProvider,
timeProvider = timeProvider,
traceSampler = traceSampler,
),
) : MeasureInitializer
Loading

0 comments on commit 782c866

Please sign in to comment.