Skip to content

Commit

Permalink
Merge pull request #389 from Countly/limits
Browse files Browse the repository at this point in the history
Limits
  • Loading branch information
turtledreams authored Sep 26, 2024
2 parents 979b012 + d7cb811 commit 44f6cc9
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 14 deletions.
42 changes: 42 additions & 0 deletions Countly.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,44 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
setAppStartTimestampOverride(timestamp: number): CountlyConfigApm;
}

class CountlyConfigSDKInternalLimits {
/**
* Limits the maximum size of all string keys
* @param keyLengthLimit - maximum char size of all string keys (default 128 chars)
*/
setMaxKeyLength(keyLengthLimit: number) : CountlyConfigSDKInternalLimits;

/**
* Limits the size of all values in segmentation key-value pairs
* @param valueSizeLimit - the maximum char size of all values in our key-value pairs (default 256 chars)
*/
setMaxValueSize(valueSizeLimit: number) : CountlyConfigSDKInternalLimits;

/**
* Limits the max amount of custom segmentation in one event
* @param segmentationAmountLimit - the maximum amount of custom segmentation in one event (default 100 key-value pairs)
*/
setMaxSegmentationValues(segmentationAmountLimit: number) : CountlyConfigSDKInternalLimits;

/**
* Limits the max amount of breadcrumbs that can be recorded before the oldest one is deleted
* @param breadcrumbCountLimit - the maximum amount of breadcrumbs that can be recorded before the oldest one is deleted (default 100)
*/
setMaxBreadcrumbCount(breadcrumbCountLimit: number) : CountlyConfigSDKInternalLimits;

/**
* Limits the max amount of stack trace lines to be recorded per thread
* @param stackTraceLinesPerThreadLimit - maximum amount of stack trace lines to be recorded per thread (default 30)
*/
setMaxStackTraceLinesPerThread(stackTraceLinesPerThreadLimit: number) : CountlyConfigSDKInternalLimits;

/**
* Limits the max characters allowed per stack trace lines. Also limits the crash message length
* @param stackTraceLineLengthLimit - maximum length of each stack trace line (default 200)
*/
setMaxStackTraceLineLength(stackTraceLineLengthLimit: number) : CountlyConfigSDKInternalLimits;
}

/**
*
* Config object for Countly Init
Expand All @@ -1146,6 +1184,10 @@ declare module "countly-sdk-react-native-bridge/CountlyConfig" {
* getter for CountlyConfigApm instance that is used to access CountlyConfigApm methods
*/
apm: CountlyConfigApm;
/**
* getter for CountlySDKLimits instance that is used to access CountlyConfigSDKInternalLimits methods
*/
limits: CountlyConfigSDKInternalLimits;

/**
* Method to set the server url
Expand Down
6 changes: 6 additions & 0 deletions CountlyConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { initialize } from "./Logger.js";
import CountlyConfigApm from "./lib/configuration_interfaces/countly_config_apm.js";
import CountlyConfigSDKInternalLimits from "./lib/configuration_interfaces/countly_config_limits.js";
/**
* Countly SDK React Native Bridge
* https://github.com/Countly/countly-sdk-react-native-bridge
Expand All @@ -18,6 +19,7 @@ class CountlyConfig {
this.serverURL = serverURL;
this.appKey = appKey;
this._countlyConfigApmInstance = new CountlyConfigApm();
this._countlyConfigSDKLimitsInstance = new CountlyConfigSDKInternalLimits();
}

/**
Expand All @@ -27,6 +29,10 @@ class CountlyConfig {
return this._countlyConfigApmInstance;
}

get limits() {
return this._countlyConfigSDKLimitsInstance;
}

/**
* Method to set the server url
*
Expand Down
70 changes: 57 additions & 13 deletions Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const DeviceIdType = {
function intToDeviceIDType(deviceIdType) {
let result = null;
switch (deviceIdType) {
case 10101:
result = DeviceIdType.SDK_GENERATED;
break;
case 20202:
result = DeviceIdType.DEVELOPER_SUPPLIED;
break;
case 30303:
result = DeviceIdType.TEMPORARY_ID;
break;
default:
L.e("_getDeviceIdType, " + `unexpected deviceIdType [${deviceIdType}] from native side`);
result = DeviceIdType.SDK_GENERATED;
break;
case 10101:
result = DeviceIdType.SDK_GENERATED;
break;
case 20202:
result = DeviceIdType.DEVELOPER_SUPPLIED;
break;
case 30303:
result = DeviceIdType.TEMPORARY_ID;
break;
default:
L.e("_getDeviceIdType, " + `unexpected deviceIdType [${deviceIdType}] from native side`);
result = DeviceIdType.SDK_GENERATED;
break;
}
L.d(`_getDeviceIdType, DeviceIDType: ${result}`);
return result;
Expand Down Expand Up @@ -134,6 +134,50 @@ function configToJson(config) {
if (config.attributionValues) {
json.attributionValues = config.attributionValues;
}
// Limits -----------------------------------------------
if (config.limits.maxKeyLength) {
if (config.limits.maxKeyLength < 1) {
L.w(`configToJson, Provided value for maxKeyLength is invalid!`)
} else {
json.maxKeyLength = config.limits.maxKeyLength;
}
}
if (config.limits.maxValueSize) {
if (config.limits.maxValueSize < 1) {
L.w(`configToJson, Provided value for maxValueSize is invalid!`)
} else {
json.maxValueSize = config.limits.maxValueSize;
}
}
if (config.limits.maxSegmentationValues) {
if (config.limits.maxSegmentationValues < 1) {
L.w(`configToJson, Provided value for maxSegmentationValues is invalid!`)
} else {
json.maxSegmentationValues = config.limits.maxSegmentationValues;
}
}
if (config.limits.maxBreadcrumbCount) {
if (config.limits.maxBreadcrumbCount < 1) {
L.w(`configToJson, Provided value for maxBreadcrumbCount is invalid!`)
} else {
json.maxBreadcrumbCount = config.limits.maxBreadcrumbCount;
}
}
if (config.limits.maxStackTraceLinesPerThread) {
if (config.limits.maxStackTraceLinesPerThread < 1) {
L.w(`configToJson, Provided value for maxStackTraceLinesPerThread is invalid!`)
} else {
json.maxStackTraceLinesPerThread = config.limits.maxStackTraceLinesPerThread;
}
}
if (config.limits.maxStackTraceLineLength) {
if (config.limits.maxStackTraceLineLength < 1) {
L.w(`configToJson, Provided value for maxStackTraceLineLength is invalid!`)
} else {
json.maxStackTraceLineLength = config.limits.maxStackTraceLineLength;
}
}
// Limits End --------------------------------------------
} catch (err) {
L.e(`configToJson, Exception occured during converting config to json.${err.toString()}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@ private void populateConfig(JSONObject _config) {
config.setRecordAppStartTime(_config.getBoolean("enableApm"));
}
// APM END --------------------------------------------
// Limits -----------------------------------------------
if(_config.has("maxKeyLength")) {
config.sdkInternalLimits.setMaxKeyLength(_config.getInt("maxKeyLength"));
}
if(_config.has("maxValueSize")) {
config.sdkInternalLimits.setMaxValueSize(_config.getInt("maxValueSize"));
}
if(_config.has("maxSegmentationValues")) {
config.sdkInternalLimits.setMaxSegmentationValues(_config.getInt("maxSegmentationValues"));
}
if(_config.has("maxBreadcrumbCount")) {
config.sdkInternalLimits.setMaxBreadcrumbCount(_config.getInt("maxBreadcrumbCount"));
}
if(_config.has("maxStackTraceLinesPerThread")) {
config.sdkInternalLimits.setMaxStackTraceLinesPerThread(_config.getInt("maxStackTraceLinesPerThread"));
}
if(_config.has("maxStackTraceLineLength")) {
config.sdkInternalLimits.setMaxStackTraceLineLength(_config.getInt("maxStackTraceLineLength"));
}
// Limits End -------------------------------------------
if (_config.has("crashReporting")) {
config.enableCrashReporting();
}
Expand Down
9 changes: 9 additions & 0 deletions example/CountlyRNExample/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ const countlyConfig = new CountlyConfig(COUNTLY_SERVER_KEY, COUNTLY_APP_KEY).set
// .enableManualAppLoadedTrigger()
// .setAppStartTimestampOverride(11223344);

// Countly SDK Limits ========================================
// countlyConfig.limits
// .setMaxKeyLength()
// .setMaxValueSize()
// .setMaxSegmentationValues()
// .setMaxBreadcrumbCount()
// .setMaxStackTraceLineLength()
// .setMaxStackTraceLinesPerThread();

export default countlyConfig;
28 changes: 27 additions & 1 deletion ios/src/CountlyReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,33 @@ - (void) populateConfig:(id) json {
if (json[@"starRatingTextMessage"]) {
config.starRatingMessage = json[@"starRatingTextMessage"];
}

// Limits -----------------------------------------------
// maxKeyLength
NSNumber *maxKeyLength = json[@"maxKeyLength"];
if (maxKeyLength) {
[config.sdkInternalLimits setMaxKeyLength:[maxKeyLength intValue]];
}
NSNumber *maxValueSize = json[@"maxValueSize"];
if (maxValueSize) {
[config.sdkInternalLimits setMaxValueSize:[maxValueSize intValue]];
}
NSNumber *maxSegmentationValues = json[@"maxSegmentationValues"];
if (maxSegmentationValues) {
[config.sdkInternalLimits setMaxSegmentationValues:[maxSegmentationValues intValue]];
}
NSNumber *maxBreadcrumbCount = json[@"maxBreadcrumbCount"];
if (maxBreadcrumbCount) {
[config.sdkInternalLimits setMaxBreadcrumbCount:[maxBreadcrumbCount intValue]];
}
NSNumber *maxStackTraceLineLength = json[@"maxStackTraceLineLength"];
if (maxStackTraceLineLength) {
[config.sdkInternalLimits setMaxStackTraceLineLength:[maxStackTraceLineLength intValue]];
}
NSNumber *maxStackTraceLinesPerThread = json[@"maxStackTraceLinesPerThread"];
if (maxStackTraceLinesPerThread) {
[config.sdkInternalLimits setMaxStackTraceLinesPerThread:[maxStackTraceLinesPerThread intValue]];
}
// Limits End -------------------------------------------
// APM ------------------------------------------------
NSNumber *enableForegroundBackground = json[@"enableForegroundBackground"];
if (enableForegroundBackground) {
Expand Down
89 changes: 89 additions & 0 deletions lib/configuration_interfaces/countly_config_limits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Countly SDK React Native Bridge SDK Internal Limits
* https://github.com/Countly/countly-sdk-react-native-bridge
* @Countly
*/

// 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.
// You can chain multiple configurations.
class CountlyConfigSDKInternalLimits {
constructor() {
_maxKeyLength = 0;
_maxValueSize = 0;
_maxSegmentationValues = 0;
_maxBreadcrumbCount = 0;
_maxStackTraceLinesPerThread = 0;
_maxStackTraceLineLength = 0;
}

// getters
get maxKeyLength() {
return this._maxKeyLength;
}

get maxValueSize() {
return this._maxValueSize;
}

get maxSegmentationValues() {
return this._maxSegmentationValues;
}

get maxBreadcrumbCount() {
return this._maxBreadcrumbCount;
}

get maxStackTraceLinesPerThread() {
return this._maxStackTraceLinesPerThread;
}

get maxStackTraceLineLength() {
return this._maxStackTraceLineLength;
}

// setters / methods

// Limits the maximum size of all string keys
// keyLengthLimit is the maximum char size of all string keys (default 128 chars)
setMaxKeyLength(keyLengthLimit) {
this._maxKeyLength = keyLengthLimit;
return this;
}

// Limits the size of all values in segmentation key-value pairs
// valueSizeLimit is the maximum char size of all values in our key-value pairs (default 256 chars)
setMaxValueSize(valueSizeLimit) {
this._maxValueSize = valueSizeLimit;
return this;
}

// Limits the max amount of custom segmentation in one event
// segmentationAmountLimit is the max amount of custom segmentation in one event (default 100 key-value pairs)
setMaxSegmentationValues(segmentationAmountLimit) {
this._maxSegmentationValues = segmentationAmountLimit;
return this;
}

// Limits the max amount of breadcrumbs that can be recorded before the oldest one is deleted
// breadcrumbCountLimit is the max amount of breadcrumbs that can be recorded before the oldest one is deleted (default 100)
setMaxBreadcrumbCount(breadcrumbCountLimit) {
this._maxBreadcrumbCount = breadcrumbCountLimit;
return this;
}

// Limits the max amount of stack trace lines to be recorded per thread
// stackTraceLinesPerThreadLimit is the max amount of stack trace lines to be recorded per thread (default 30)
setMaxStackTraceLinesPerThread(stackTraceLinesPerThreadLimit) {
this._maxStackTraceLinesPerThread = stackTraceLinesPerThreadLimit;
return this;
}

// Limits the max characters allowed per stack trace lines. Also limits the crash message length
// stackTraceLineLengthLimit is the max length of each stack trace line (default 200)
setMaxStackTraceLineLength(stackTraceLineLengthLimit) {
this._maxStackTraceLineLength = stackTraceLineLengthLimit;
return this;
}
}

export default CountlyConfigSDKInternalLimits;

0 comments on commit 44f6cc9

Please sign in to comment.