Skip to content

Commit

Permalink
Merge pull request #2103 from DataDog/xgouchet/RUM-4822/sample
Browse files Browse the repository at this point in the history
RUM-4822 adapt sample app
  • Loading branch information
xgouchet authored Jun 21, 2024
2 parents b680df7 + 20f8edf commit c2572e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.datadog.android.core.configuration.BatchSize
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.configuration.UploadFrequency
import com.datadog.android.core.sampling.RateBasedSampler
import com.datadog.android.event.EventMapper
import com.datadog.android.log.Logger
import com.datadog.android.log.Logs
import com.datadog.android.log.LogsConfiguration
Expand All @@ -31,12 +30,6 @@ import com.datadog.android.rum.GlobalRumMonitor
import com.datadog.android.rum.Rum
import com.datadog.android.rum.RumConfiguration
import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.event.ViewEventMapper
import com.datadog.android.rum.model.ActionEvent
import com.datadog.android.rum.model.ErrorEvent
import com.datadog.android.rum.model.LongTaskEvent
import com.datadog.android.rum.model.ResourceEvent
import com.datadog.android.rum.model.ViewEvent
import com.datadog.android.rum.tracking.NavigationViewTrackingStrategy
import com.datadog.android.sample.data.db.LocalDataSource
import com.datadog.android.sample.data.remote.RemoteDataSource
Expand Down Expand Up @@ -226,36 +219,30 @@ class SampleApplication : Application() {
.trackUserInteractions()
.trackLongTasks(250L)
.trackNonFatalAnrs(true)
.setViewEventMapper(object : ViewEventMapper {
override fun map(event: ViewEvent): ViewEvent {
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
return event
}
})
.setActionEventMapper(object : EventMapper<ActionEvent> {
override fun map(event: ActionEvent): ActionEvent {
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
return event
}
})
.setResourceEventMapper(object : EventMapper<ResourceEvent> {
override fun map(event: ResourceEvent): ResourceEvent {
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
return event
}
})
.setErrorEventMapper(object : EventMapper<ErrorEvent> {
override fun map(event: ErrorEvent): ErrorEvent {
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
return event
}
})
.setLongTaskEventMapper(object : EventMapper<LongTaskEvent> {
override fun map(event: LongTaskEvent): LongTaskEvent {
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
return event
.setViewEventMapper { event ->
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
event
}
.setActionEventMapper { event ->
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
event
}
.setResourceEventMapper { event ->
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
if (KEEP_UPLOAD_REQUEST_AS_RESOURCES) {
event
} else {
null
}
})
}
.setErrorEventMapper { event ->
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
event
}
.setLongTaskEventMapper { event ->
event.context?.additionalProperties?.put(ATTR_IS_MAPPED, true)
event
}
.build()
}

Expand Down Expand Up @@ -285,6 +272,8 @@ class SampleApplication : Application() {
)
)

configBuilder.addNetworkInterceptor(DatadogInterceptor())

return configBuilder.build()
}

Expand Down Expand Up @@ -320,6 +309,8 @@ class SampleApplication : Application() {
companion object {
private const val SAMPLE_IN_ALL_SESSIONS = 100f

private const val KEEP_UPLOAD_REQUEST_AS_RESOURCES = true

init {
System.loadLibrary("datadog-native-sample-lib")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ class LogsForegroundService : Service() {
}
STOP_RUM_RESOURCE -> {
rumMonitor.stopResource(
BACKGROUND_RESOURCE_URL,
200,
200,
RumResourceKind.IMAGE,
emptyMap()
key = BACKGROUND_RESOURCE_URL,
statusCode = 200,
uploadSize = 32,
downloadSize = 512,
kind = RumResourceKind.IMAGE,
attributes = emptyMap()
)
}
else -> {
Expand Down

0 comments on commit c2572e7

Please sign in to comment.