Skip to content

Commit 44f6cc9

Browse files
authored
Merge pull request #389 from Countly/limits
Limits
2 parents 979b012 + d7cb811 commit 44f6cc9

File tree

7 files changed

+250
-14
lines changed

7 files changed

+250
-14
lines changed

Countly.d.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,44 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
11291129
setAppStartTimestampOverride(timestamp: number): CountlyConfigApm;
11301130
}
11311131

1132+
class CountlyConfigSDKInternalLimits {
1133+
/**
1134+
* Limits the maximum size of all string keys
1135+
* @param keyLengthLimit - maximum char size of all string keys (default 128 chars)
1136+
*/
1137+
setMaxKeyLength(keyLengthLimit: number) : CountlyConfigSDKInternalLimits;
1138+
1139+
/**
1140+
* Limits the size of all values in segmentation key-value pairs
1141+
* @param valueSizeLimit - the maximum char size of all values in our key-value pairs (default 256 chars)
1142+
*/
1143+
setMaxValueSize(valueSizeLimit: number) : CountlyConfigSDKInternalLimits;
1144+
1145+
/**
1146+
* Limits the max amount of custom segmentation in one event
1147+
* @param segmentationAmountLimit - the maximum amount of custom segmentation in one event (default 100 key-value pairs)
1148+
*/
1149+
setMaxSegmentationValues(segmentationAmountLimit: number) : CountlyConfigSDKInternalLimits;
1150+
1151+
/**
1152+
* Limits the max amount of breadcrumbs that can be recorded before the oldest one is deleted
1153+
* @param breadcrumbCountLimit - the maximum amount of breadcrumbs that can be recorded before the oldest one is deleted (default 100)
1154+
*/
1155+
setMaxBreadcrumbCount(breadcrumbCountLimit: number) : CountlyConfigSDKInternalLimits;
1156+
1157+
/**
1158+
* Limits the max amount of stack trace lines to be recorded per thread
1159+
* @param stackTraceLinesPerThreadLimit - maximum amount of stack trace lines to be recorded per thread (default 30)
1160+
*/
1161+
setMaxStackTraceLinesPerThread(stackTraceLinesPerThreadLimit: number) : CountlyConfigSDKInternalLimits;
1162+
1163+
/**
1164+
* Limits the max characters allowed per stack trace lines. Also limits the crash message length
1165+
* @param stackTraceLineLengthLimit - maximum length of each stack trace line (default 200)
1166+
*/
1167+
setMaxStackTraceLineLength(stackTraceLineLengthLimit: number) : CountlyConfigSDKInternalLimits;
1168+
}
1169+
11321170
/**
11331171
*
11341172
* Config object for Countly Init
@@ -1146,6 +1184,10 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
11461184
* getter for CountlyConfigApm instance that is used to access CountlyConfigApm methods
11471185
*/
11481186
apm: CountlyConfigApm;
1187+
/**
1188+
* getter for CountlySDKLimits instance that is used to access CountlyConfigSDKInternalLimits methods
1189+
*/
1190+
limits: CountlyConfigSDKInternalLimits;
11491191

11501192
/**
11511193
* Method to set the server url

CountlyConfig.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { initialize } from "./Logger.js";
22
import CountlyConfigApm from "./lib/configuration_interfaces/countly_config_apm.js";
3+
import CountlyConfigSDKInternalLimits from "./lib/configuration_interfaces/countly_config_limits.js";
34
/**
45
* Countly SDK React Native Bridge
56
* https://github.com/Countly/countly-sdk-react-native-bridge
@@ -18,6 +19,7 @@ class CountlyConfig {
1819
this.serverURL = serverURL;
1920
this.appKey = appKey;
2021
this._countlyConfigApmInstance = new CountlyConfigApm();
22+
this._countlyConfigSDKLimitsInstance = new CountlyConfigSDKInternalLimits();
2123
}
2224

2325
/**
@@ -27,6 +29,10 @@ class CountlyConfig {
2729
return this._countlyConfigApmInstance;
2830
}
2931

32+
get limits() {
33+
return this._countlyConfigSDKLimitsInstance;
34+
}
35+
3036
/**
3137
* Method to set the server url
3238
*

Utils.js

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ const DeviceIdType = {
1717
function intToDeviceIDType(deviceIdType) {
1818
let result = null;
1919
switch (deviceIdType) {
20-
case 10101:
21-
result = DeviceIdType.SDK_GENERATED;
22-
break;
23-
case 20202:
24-
result = DeviceIdType.DEVELOPER_SUPPLIED;
25-
break;
26-
case 30303:
27-
result = DeviceIdType.TEMPORARY_ID;
28-
break;
29-
default:
30-
L.e("_getDeviceIdType, " + `unexpected deviceIdType [${deviceIdType}] from native side`);
31-
result = DeviceIdType.SDK_GENERATED;
32-
break;
20+
case 10101:
21+
result = DeviceIdType.SDK_GENERATED;
22+
break;
23+
case 20202:
24+
result = DeviceIdType.DEVELOPER_SUPPLIED;
25+
break;
26+
case 30303:
27+
result = DeviceIdType.TEMPORARY_ID;
28+
break;
29+
default:
30+
L.e("_getDeviceIdType, " + `unexpected deviceIdType [${deviceIdType}] from native side`);
31+
result = DeviceIdType.SDK_GENERATED;
32+
break;
3333
}
3434
L.d(`_getDeviceIdType, DeviceIDType: ${result}`);
3535
return result;
@@ -134,6 +134,50 @@ function configToJson(config) {
134134
if (config.attributionValues) {
135135
json.attributionValues = config.attributionValues;
136136
}
137+
// Limits -----------------------------------------------
138+
if (config.limits.maxKeyLength) {
139+
if (config.limits.maxKeyLength < 1) {
140+
L.w(`configToJson, Provided value for maxKeyLength is invalid!`)
141+
} else {
142+
json.maxKeyLength = config.limits.maxKeyLength;
143+
}
144+
}
145+
if (config.limits.maxValueSize) {
146+
if (config.limits.maxValueSize < 1) {
147+
L.w(`configToJson, Provided value for maxValueSize is invalid!`)
148+
} else {
149+
json.maxValueSize = config.limits.maxValueSize;
150+
}
151+
}
152+
if (config.limits.maxSegmentationValues) {
153+
if (config.limits.maxSegmentationValues < 1) {
154+
L.w(`configToJson, Provided value for maxSegmentationValues is invalid!`)
155+
} else {
156+
json.maxSegmentationValues = config.limits.maxSegmentationValues;
157+
}
158+
}
159+
if (config.limits.maxBreadcrumbCount) {
160+
if (config.limits.maxBreadcrumbCount < 1) {
161+
L.w(`configToJson, Provided value for maxBreadcrumbCount is invalid!`)
162+
} else {
163+
json.maxBreadcrumbCount = config.limits.maxBreadcrumbCount;
164+
}
165+
}
166+
if (config.limits.maxStackTraceLinesPerThread) {
167+
if (config.limits.maxStackTraceLinesPerThread < 1) {
168+
L.w(`configToJson, Provided value for maxStackTraceLinesPerThread is invalid!`)
169+
} else {
170+
json.maxStackTraceLinesPerThread = config.limits.maxStackTraceLinesPerThread;
171+
}
172+
}
173+
if (config.limits.maxStackTraceLineLength) {
174+
if (config.limits.maxStackTraceLineLength < 1) {
175+
L.w(`configToJson, Provided value for maxStackTraceLineLength is invalid!`)
176+
} else {
177+
json.maxStackTraceLineLength = config.limits.maxStackTraceLineLength;
178+
}
179+
}
180+
// Limits End --------------------------------------------
137181
} catch (err) {
138182
L.e(`configToJson, Exception occured during converting config to json.${err.toString()}`);
139183
}

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ private void populateConfig(JSONObject _config) {
235235
config.setRecordAppStartTime(_config.getBoolean("enableApm"));
236236
}
237237
// APM END --------------------------------------------
238+
// Limits -----------------------------------------------
239+
if(_config.has("maxKeyLength")) {
240+
config.sdkInternalLimits.setMaxKeyLength(_config.getInt("maxKeyLength"));
241+
}
242+
if(_config.has("maxValueSize")) {
243+
config.sdkInternalLimits.setMaxValueSize(_config.getInt("maxValueSize"));
244+
}
245+
if(_config.has("maxSegmentationValues")) {
246+
config.sdkInternalLimits.setMaxSegmentationValues(_config.getInt("maxSegmentationValues"));
247+
}
248+
if(_config.has("maxBreadcrumbCount")) {
249+
config.sdkInternalLimits.setMaxBreadcrumbCount(_config.getInt("maxBreadcrumbCount"));
250+
}
251+
if(_config.has("maxStackTraceLinesPerThread")) {
252+
config.sdkInternalLimits.setMaxStackTraceLinesPerThread(_config.getInt("maxStackTraceLinesPerThread"));
253+
}
254+
if(_config.has("maxStackTraceLineLength")) {
255+
config.sdkInternalLimits.setMaxStackTraceLineLength(_config.getInt("maxStackTraceLineLength"));
256+
}
257+
// Limits End -------------------------------------------
238258
if (_config.has("crashReporting")) {
239259
config.enableCrashReporting();
240260
}

example/CountlyRNExample/Configuration.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ const countlyConfig = new CountlyConfig(COUNTLY_SERVER_KEY, COUNTLY_APP_KEY).set
3030
// .enableManualAppLoadedTrigger()
3131
// .setAppStartTimestampOverride(11223344);
3232

33+
// Countly SDK Limits ========================================
34+
// countlyConfig.limits
35+
// .setMaxKeyLength()
36+
// .setMaxValueSize()
37+
// .setMaxSegmentationValues()
38+
// .setMaxBreadcrumbCount()
39+
// .setMaxStackTraceLineLength()
40+
// .setMaxStackTraceLinesPerThread();
41+
3342
export default countlyConfig;

ios/src/CountlyReactNative.m

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,33 @@ - (void) populateConfig:(id) json {
147147
if (json[@"starRatingTextMessage"]) {
148148
config.starRatingMessage = json[@"starRatingTextMessage"];
149149
}
150-
150+
// Limits -----------------------------------------------
151+
// maxKeyLength
152+
NSNumber *maxKeyLength = json[@"maxKeyLength"];
153+
if (maxKeyLength) {
154+
[config.sdkInternalLimits setMaxKeyLength:[maxKeyLength intValue]];
155+
}
156+
NSNumber *maxValueSize = json[@"maxValueSize"];
157+
if (maxValueSize) {
158+
[config.sdkInternalLimits setMaxValueSize:[maxValueSize intValue]];
159+
}
160+
NSNumber *maxSegmentationValues = json[@"maxSegmentationValues"];
161+
if (maxSegmentationValues) {
162+
[config.sdkInternalLimits setMaxSegmentationValues:[maxSegmentationValues intValue]];
163+
}
164+
NSNumber *maxBreadcrumbCount = json[@"maxBreadcrumbCount"];
165+
if (maxBreadcrumbCount) {
166+
[config.sdkInternalLimits setMaxBreadcrumbCount:[maxBreadcrumbCount intValue]];
167+
}
168+
NSNumber *maxStackTraceLineLength = json[@"maxStackTraceLineLength"];
169+
if (maxStackTraceLineLength) {
170+
[config.sdkInternalLimits setMaxStackTraceLineLength:[maxStackTraceLineLength intValue]];
171+
}
172+
NSNumber *maxStackTraceLinesPerThread = json[@"maxStackTraceLinesPerThread"];
173+
if (maxStackTraceLinesPerThread) {
174+
[config.sdkInternalLimits setMaxStackTraceLinesPerThread:[maxStackTraceLinesPerThread intValue]];
175+
}
176+
// Limits End -------------------------------------------
151177
// APM ------------------------------------------------
152178
NSNumber *enableForegroundBackground = json[@"enableForegroundBackground"];
153179
if (enableForegroundBackground) {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Countly SDK React Native Bridge SDK Internal Limits
3+
* https://github.com/Countly/countly-sdk-react-native-bridge
4+
* @Countly
5+
*/
6+
7+
// This class holds SDK internal limits (https://support.count.ly/hc/en-us/articles/360037753291-SDK-development-guide#01H821RTQ7AZ6J858BHP4883ZC) specific configurations to be used with CountlyConfig class and serves as an interface.
8+
// You can chain multiple configurations.
9+
class CountlyConfigSDKInternalLimits {
10+
constructor() {
11+
_maxKeyLength = 0;
12+
_maxValueSize = 0;
13+
_maxSegmentationValues = 0;
14+
_maxBreadcrumbCount = 0;
15+
_maxStackTraceLinesPerThread = 0;
16+
_maxStackTraceLineLength = 0;
17+
}
18+
19+
// getters
20+
get maxKeyLength() {
21+
return this._maxKeyLength;
22+
}
23+
24+
get maxValueSize() {
25+
return this._maxValueSize;
26+
}
27+
28+
get maxSegmentationValues() {
29+
return this._maxSegmentationValues;
30+
}
31+
32+
get maxBreadcrumbCount() {
33+
return this._maxBreadcrumbCount;
34+
}
35+
36+
get maxStackTraceLinesPerThread() {
37+
return this._maxStackTraceLinesPerThread;
38+
}
39+
40+
get maxStackTraceLineLength() {
41+
return this._maxStackTraceLineLength;
42+
}
43+
44+
// setters / methods
45+
46+
// Limits the maximum size of all string keys
47+
// keyLengthLimit is the maximum char size of all string keys (default 128 chars)
48+
setMaxKeyLength(keyLengthLimit) {
49+
this._maxKeyLength = keyLengthLimit;
50+
return this;
51+
}
52+
53+
// Limits the size of all values in segmentation key-value pairs
54+
// valueSizeLimit is the maximum char size of all values in our key-value pairs (default 256 chars)
55+
setMaxValueSize(valueSizeLimit) {
56+
this._maxValueSize = valueSizeLimit;
57+
return this;
58+
}
59+
60+
// Limits the max amount of custom segmentation in one event
61+
// segmentationAmountLimit is the max amount of custom segmentation in one event (default 100 key-value pairs)
62+
setMaxSegmentationValues(segmentationAmountLimit) {
63+
this._maxSegmentationValues = segmentationAmountLimit;
64+
return this;
65+
}
66+
67+
// Limits the max amount of breadcrumbs that can be recorded before the oldest one is deleted
68+
// breadcrumbCountLimit is the max amount of breadcrumbs that can be recorded before the oldest one is deleted (default 100)
69+
setMaxBreadcrumbCount(breadcrumbCountLimit) {
70+
this._maxBreadcrumbCount = breadcrumbCountLimit;
71+
return this;
72+
}
73+
74+
// Limits the max amount of stack trace lines to be recorded per thread
75+
// stackTraceLinesPerThreadLimit is the max amount of stack trace lines to be recorded per thread (default 30)
76+
setMaxStackTraceLinesPerThread(stackTraceLinesPerThreadLimit) {
77+
this._maxStackTraceLinesPerThread = stackTraceLinesPerThreadLimit;
78+
return this;
79+
}
80+
81+
// Limits the max characters allowed per stack trace lines. Also limits the crash message length
82+
// stackTraceLineLengthLimit is the max length of each stack trace line (default 200)
83+
setMaxStackTraceLineLength(stackTraceLineLengthLimit) {
84+
this._maxStackTraceLineLength = stackTraceLineLengthLimit;
85+
return this;
86+
}
87+
}
88+
89+
export default CountlyConfigSDKInternalLimits;

0 commit comments

Comments
 (0)