Skip to content

Commit

Permalink
feat(logging): extend logs with isDebugMode field
Browse files Browse the repository at this point in the history
SDK-226

Co-authored-by: davidSchuppa <[email protected]>
Co-authored-by: LasOri <[email protected]>
Co-authored-by: megamegax <[email protected]>
Co-authored-by: matusekma <[email protected]>
  • Loading branch information
5 people committed Feb 6, 2025
1 parent 4d3bc1b commit a6d59bd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class LogShardListMergerTest {
every { mockDeviceInfo.model } returns "Pixel"
every { mockDeviceInfo.clientId } returns "clientId"
every { mockDeviceInfo.sdkVersion } returns "1.6.1"
every { mockDeviceInfo.isDebugMode } returns true


merger = LogShardListMerger(
Expand Down Expand Up @@ -119,6 +120,7 @@ class LogShardListMergerTest {
"osVersion" to "8.0",
"model" to "Pixel",
"hwId" to "clientId",
"isDebugMode" to "true",
"applicationCode" to APPLICATION_CODE,
"merchantId" to MERCHANT_ID
)
Expand Down
120 changes: 49 additions & 71 deletions core/src/main/java/com/emarsys/core/util/log/LogShardListMerger.kt
Original file line number Diff line number Diff line change
@@ -1,81 +1,59 @@
package com.emarsys.core.util.log;

import com.emarsys.core.Mapper;
import com.emarsys.core.device.DeviceInfo;
import com.emarsys.core.endpoint.Endpoint;
import com.emarsys.core.provider.timestamp.TimestampProvider;
import com.emarsys.core.provider.uuid.UUIDProvider;
import com.emarsys.core.request.model.RequestMethod;
import com.emarsys.core.request.model.RequestModel;
import com.emarsys.core.shard.ShardModel;
import com.emarsys.core.util.Assert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogShardListMerger implements Mapper<List<ShardModel>, RequestModel> {


private final TimestampProvider timestampProvider;
private final UUIDProvider uuidProvider;
private final DeviceInfo deviceInfo;
private final String applicationCode;
private final String merchantId;

public LogShardListMerger(TimestampProvider timestampProvider, UUIDProvider uuidProvider, DeviceInfo deviceInfo, String applicationCode, String merchantId) {
Assert.notNull(timestampProvider, "TimestampProvider must not be null!");
Assert.notNull(uuidProvider, "UuidProvider must not be null!");
Assert.notNull(deviceInfo, "DeviceInfo must not be null!");

this.timestampProvider = timestampProvider;
this.uuidProvider = uuidProvider;
this.deviceInfo = deviceInfo;
this.applicationCode = applicationCode;
this.merchantId = merchantId;
}

@Override
public RequestModel map(List<ShardModel> shards) {
Assert.notNull(shards, "Shards must not be null!");
Assert.notEmpty(shards, "Shards must not be empty!");
Assert.elementsNotNull(shards, "Shard elements must not be null!");

return new RequestModel.Builder(timestampProvider, uuidProvider)
package com.emarsys.core.util.log

import com.emarsys.core.Mapper
import com.emarsys.core.device.DeviceInfo
import com.emarsys.core.endpoint.Endpoint
import com.emarsys.core.provider.timestamp.TimestampProvider
import com.emarsys.core.provider.uuid.UUIDProvider
import com.emarsys.core.request.model.RequestMethod
import com.emarsys.core.request.model.RequestModel
import com.emarsys.core.shard.ShardModel

class LogShardListMerger(
private val timestampProvider: TimestampProvider,
private val uuidProvider: UUIDProvider,
private val deviceInfo: DeviceInfo,
private val applicationCode: String?,
private val merchantId: String?
) : Mapper<List<ShardModel>, RequestModel> {

override fun map(value: List<ShardModel>): RequestModel {
return if (value.isNotEmpty()) {
RequestModel.Builder(timestampProvider, uuidProvider)
.url(Endpoint.LOG_URL)
.method(RequestMethod.POST)
.payload(createPayload(shards))
.build();
.payload(createPayload(value))
.build()
} else throw IllegalArgumentException("Shards must not be empty!")
}

private Map<String, Object> createPayload(List<ShardModel> shards) {
Map<String, Object> result = new HashMap<>();
List<Map<String, Object>> datas = new ArrayList<>(shards.size());
Map<String, String> deviceInfo = createDeviceInfo();
for (ShardModel shard : shards) {
Map<String, Object> data = new HashMap<>();
data.put("type", shard.getType());
data.put("deviceInfo", deviceInfo);
data.putAll(shard.getData());
datas.add(data);
private fun createPayload(shards: List<ShardModel>): Map<String, Any?> {
val result: MutableMap<String, Any?> = mutableMapOf()
val dataList: MutableList<Map<String, Any>> = mutableListOf()
val deviceInfo = createDeviceInfo()
shards.forEach { shard ->
val data: MutableMap<String, Any> = mutableMapOf()
data["type"] = shard.type
data["deviceInfo"] = deviceInfo
data.putAll(shard.data)
dataList.add(data)
}

result.put("logs", datas);
return result;
result["logs"] = dataList
return result
}

private Map<String, String> createDeviceInfo() {
Map<String, String> data = new HashMap<>();
data.put("platform", deviceInfo.getPlatform());
data.put("appVersion", deviceInfo.getApplicationVersion());
data.put("sdkVersion", deviceInfo.getSdkVersion());
data.put("osVersion", deviceInfo.getOsVersion());
data.put("model", deviceInfo.getModel());
data.put("hwId", deviceInfo.getClientId());
data.put("applicationCode", applicationCode);
data.put("merchantId", merchantId);
return data;
private fun createDeviceInfo(): Map<String, String?> {
val data: MutableMap<String, String?> = mutableMapOf()
data["platform"] = deviceInfo.platform
data["appVersion"] = deviceInfo.applicationVersion
data["sdkVersion"] = deviceInfo.sdkVersion
data["osVersion"] = deviceInfo.osVersion
data["model"] = deviceInfo.model
data["hwId"] = deviceInfo.clientId
data["isDebugMode"] = deviceInfo.isDebugMode.toString()
data["applicationCode"] = applicationCode
data["merchantId"] = merchantId
return data
}

}

0 comments on commit a6d59bd

Please sign in to comment.