Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ebf46f4

Browse files
authoredOct 30, 2024
Add Config Version and Rule Passed to Exposure Metadata (#400)
1 parent 2287db8 commit ebf46f4

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed
 

‎src/main/kotlin/com/statsig/sdk/ConfigEvaluation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ConfigEvaluation(
1313
var configDelegate: String? = null,
1414
var evaluationDetails: EvaluationDetails? = null,
1515
var isExperimentGroup: Boolean = false,
16+
var configVersion: Long? = null,
1617
) {
1718
internal var isDelegate: Boolean = false
1819

‎src/main/kotlin/com/statsig/sdk/DataTypes.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal data class APIConfig(
3939
@SerializedName("explicitParameters") val explicitParameters: Array<String>?,
4040
@SerializedName("hasSharedParams") val hasSharedParams: Boolean?,
4141
@SerializedName("targetAppIDs") val targetAppIDs: Array<String>? = null,
42+
@SerializedName("version") val version: Long? = 0,
4243
)
4344

4445
internal data class APIRule(
@@ -121,9 +122,10 @@ internal data class LayerExposureMetadata(
121122
@SerializedName("secondaryExposures") val secondaryExposures: ArrayList<Map<String, String>>,
122123
@SerializedName("isManualExposure") var isManualExposure: String = "false",
123124
@SerializedName("evaluationDetails") val evaluationDetails: EvaluationDetails?,
125+
@SerializedName("configVersion") val configVersion: Long? = null,
124126
) {
125127
fun toStatsigEventMetadataMap(): MutableMap<String, String> {
126-
return mutableMapOf(
128+
var map = mutableMapOf(
127129
"config" to config,
128130
"ruleID" to ruleID,
129131
"allocatedExperiment" to allocatedExperiment,
@@ -132,5 +134,9 @@ internal data class LayerExposureMetadata(
132134
"isManualExposure" to isManualExposure,
133135
// secondaryExposures excluded -- StatsigEvent adds secondaryExposures explicitly as a top level key
134136
)
137+
if (configVersion != null) {
138+
map["configVersion"] = configVersion.toString()
139+
}
140+
return map
135141
}
136142
}

‎src/main/kotlin/com/statsig/sdk/Evaluator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ internal class Evaluator(
445445

446446
private fun evaluate(ctx: EvaluationContext, config: APIConfig) {
447447
ctx.evaluation.evaluationDetails = createEvaluationDetails(specStore.getEvaluationReason())
448+
ctx.evaluation.configVersion = config.version
448449

449450
if (!config.enabled) {
450451
logger.debug("${config.name} is not enabled.")

‎src/main/kotlin/com/statsig/sdk/Layer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,6 @@ internal fun createLayerExposureMetadata(
174174
isExplicit.toString(),
175175
exposures,
176176
evaluationDetails = configEvaluation.evaluationDetails,
177+
configVersion = configEvaluation.configVersion,
177178
)
178179
}

‎src/main/kotlin/com/statsig/sdk/StatsigLogger.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,71 +72,72 @@ internal class StatsigLogger(
7272
fun logGateExposure(
7373
user: StatsigUser?,
7474
gateName: String,
75-
value: Boolean,
76-
ruleID: String,
77-
secondaryExposures: ArrayList<Map<String, String>>,
75+
result: ConfigEvaluation,
7876
isManualExposure: Boolean = false,
79-
evaluationDetails: EvaluationDetails?,
8077
) {
8178
if (!isUniqueExposure(
8279
user,
8380
gateName,
84-
ruleID,
85-
value.toString(),
81+
result.ruleID,
82+
result.booleanValue.toString(),
8683
"",
8784
)
8885
) {
8986
return
9087
}
9188
val metadata = mutableMapOf(
9289
"gate" to gateName,
93-
"gateValue" to value.toString(),
94-
"ruleID" to ruleID,
90+
"gateValue" to result.booleanValue.toString(),
91+
"ruleID" to result.ruleID,
9592
"isManualExposure" to isManualExposure.toString(),
9693
)
9794

98-
safeAddEvaluationToEvent(evaluationDetails, metadata)
95+
safeAddEvaluationToEvent(result.evaluationDetails, metadata)
96+
if (result.configVersion != null) {
97+
metadata["configVersion"] = result.configVersion.toString()
98+
}
9999

100100
val event = StatsigEvent(
101101
GATE_EXPOSURE_EVENT,
102102
eventValue = null,
103103
metadata,
104104
user,
105105
statsigMetadata,
106-
secondaryExposures,
106+
result.secondaryExposures,
107107
)
108108
log(event)
109109
}
110110

111111
fun logConfigExposure(
112112
user: StatsigUser?,
113113
configName: String,
114-
ruleID: String,
115-
secondaryExposures: ArrayList<Map<String, String>>,
114+
result: ConfigEvaluation,
116115
isManualExposure: Boolean,
117-
evaluationDetails: EvaluationDetails?,
118116
) {
119117
if (!isUniqueExposure(
120118
user,
121119
configName,
122-
ruleID,
120+
result.ruleID,
123121
"",
124122
"",
125123
)
126124
) {
127125
return
128126
}
129127
val metadata =
130-
mutableMapOf("config" to configName, "ruleID" to ruleID, "isManualExposure" to isManualExposure.toString())
131-
safeAddEvaluationToEvent(evaluationDetails, metadata)
128+
mutableMapOf("config" to configName, "ruleID" to result.ruleID, "isManualExposure" to isManualExposure.toString(), "rulePassed" to result.booleanValue.toString())
129+
safeAddEvaluationToEvent(result.evaluationDetails, metadata)
130+
if (result.configVersion != null) {
131+
metadata["configVersion"] = result.configVersion.toString()
132+
}
132133

133134
val event = StatsigEvent(
134135
CONFIG_EXPOSURE_EVENT,
135136
eventValue = null,
136137
metadata,
137138
user,
138139
statsigMetadata,
139-
secondaryExposures,
140+
result.secondaryExposures,
140141
)
141142
log(event)
142143
}

‎src/main/kotlin/com/statsig/sdk/StatsigServer.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,8 @@ private class StatsigServerImpl() :
501501
logger.logGateExposure(
502502
normalizeUser(user),
503503
gateName,
504-
evaluation.booleanValue,
505-
evaluation.ruleID,
506-
evaluation.secondaryExposures,
504+
evaluation,
507505
isManualExposure,
508-
evaluation.evaluationDetails,
509506
)
510507
}
511508

@@ -1307,10 +1304,8 @@ private class StatsigServerImpl() :
13071304
logger.logConfigExposure(
13081305
user,
13091306
configName,
1310-
result.ruleID,
1311-
result.secondaryExposures,
1307+
result,
13121308
isManualExposure,
1313-
result.evaluationDetails,
13141309
)
13151310
}
13161311

0 commit comments

Comments
 (0)
Please sign in to comment.