Skip to content

Commit 4f733cb

Browse files
feat: update sdk to support sdkPlatform metadata, update WASM lib, update OpenFeature (#166)
* feat: update sdk to support sdkPlatform metadata, update WASM lib, update OpenFeature * fix: update example apps, set sdkPlatform for OF context. Signed-off-by: Jonathan Norris <jonathan@taplytics.com> * chore: cleanup * feat: update OF version, cleanup event value code --------- Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
1 parent aedb9e4 commit 4f733cb

File tree

12 files changed

+212
-85
lines changed

12 files changed

+212
-85
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ sourceCompatibility = JavaVersion.VERSION_11
8484
targetCompatibility = JavaVersion.VERSION_11
8585

8686
def wasmResourcePath = "$projectDir/src/main/resources"
87-
def wasmVersion = "1.25.3"
87+
def wasmVersion = "1.31.2"
8888
def wasmUrl = "https://unpkg.com/@devcycle/bucketing-assembly-script@$wasmVersion/build/bucketing-lib.release.wasm"
8989
task downloadDVCBucketingWASM(type: Download) {
9090
src wasmUrl
@@ -113,7 +113,7 @@ ext {
113113
junit_version = "4.13.2"
114114
mockito_core_version = "5.6.0"
115115
protobuf_version = "3.24.4"
116-
openfeature_version = "1.7.0"
116+
openfeature_version = "1.14.1"
117117
eventsource_version = "4.1.1"
118118
}
119119

src/examples/java/com/devcycle/examples/LocalExample.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.devcycle.examples;
22

33
import com.devcycle.sdk.server.common.logging.SimpleDevCycleLogger;
4+
import com.devcycle.sdk.server.common.model.DevCycleEvent;
45
import com.devcycle.sdk.server.common.model.DevCycleUser;
56
import com.devcycle.sdk.server.local.api.DevCycleLocalClient;
67
import com.devcycle.sdk.server.local.model.DevCycleLocalOptions;
@@ -24,9 +25,7 @@ public static void main(String[] args) throws InterruptedException {
2425
Boolean defaultValue = false;
2526

2627
DevCycleLocalOptions options = DevCycleLocalOptions.builder()
27-
.configPollingIntervalMS(60000)
2828
.customLogger(new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.DEBUG))
29-
.enableBetaRealtimeUpdates(true)
3029
.build();
3130

3231
// Initialize DevCycle Client
@@ -50,6 +49,10 @@ public static void main(String[] args) throws InterruptedException {
5049
} else {
5150
System.out.println("feature is NOT enabled");
5251
}
53-
Thread.sleep(10000);
52+
53+
DevCycleEvent event = DevCycleEvent.builder().type("local-test").build();
54+
client.track(user, event);
55+
56+
Thread.sleep(20000);
5457
}
5558
}

src/examples/java/com/devcycle/examples/OpenFeatureExample.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.devcycle.examples;
22

3+
import com.devcycle.sdk.server.common.logging.SimpleDevCycleLogger;
34
import com.devcycle.sdk.server.local.api.DevCycleLocalClient;
45
import com.devcycle.sdk.server.local.model.DevCycleLocalOptions;
56
import dev.openfeature.sdk.*;
@@ -15,22 +16,16 @@ public static void main(String[] args) throws InterruptedException {
1516
System.exit(1);
1617
}
1718

18-
DevCycleLocalOptions options = DevCycleLocalOptions.builder().configPollingIntervalMS(60000)
19-
.disableAutomaticEventLogging(false).disableCustomEventLogging(false).build();
19+
DevCycleLocalOptions options = DevCycleLocalOptions.builder()
20+
.customLogger(new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.DEBUG))
21+
.build();
2022

2123
// Initialize DevCycle Client
2224
DevCycleLocalClient devCycleClient = new DevCycleLocalClient(server_sdk_key, options);
2325

24-
for (int i = 0; i < 10; i++) {
25-
if (devCycleClient.isInitialized()) {
26-
break;
27-
}
28-
Thread.sleep(500);
29-
}
30-
3126
// Setup OpenFeature with the DevCycle Provider
3227
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
33-
api.setProvider(devCycleClient.getOpenFeatureProvider());
28+
api.setProviderAndWait(devCycleClient.getOpenFeatureProvider());
3429

3530
Client openFeatureClient = api.getClient();
3631

@@ -41,7 +36,7 @@ public static void main(String[] args) throws InterruptedException {
4136
context.add("language", "en");
4237
context.add("country", "CA");
4338
context.add("appVersion", "1.0.0");
44-
context.add("appBuild", "1");
39+
context.add("appBuild", 1.0);
4540
context.add("deviceModel", "Macbook");
4641

4742
// Add Devcycle Custom Data values
@@ -81,5 +76,14 @@ public static void main(String[] args) throws InterruptedException {
8176
System.out.println("Value: " + details.getValue());
8277
System.out.println("Reason: " + details.getReason());
8378

79+
MutableTrackingEventDetails eventDetails = new MutableTrackingEventDetails(610.1);
80+
eventDetails.add("test-string", "test-value");
81+
eventDetails.add("test-number", 123.456);
82+
eventDetails.add("test-boolean", true);
83+
eventDetails.add("test-json", new Value(Structure.mapToStructure(defaultJsonData)));
84+
85+
openFeatureClient.track("test-of-event", context, eventDetails);
86+
87+
Thread.sleep(20000);
8488
}
8589
}

src/main/java/com/devcycle/sdk/server/common/api/IDevCycleClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.devcycle.sdk.server.common.api;
22

3+
import com.devcycle.sdk.server.common.exception.DevCycleException;
4+
import com.devcycle.sdk.server.common.model.DevCycleEvent;
35
import com.devcycle.sdk.server.common.model.DevCycleUser;
46
import com.devcycle.sdk.server.common.model.Variable;
57
import dev.openfeature.sdk.FeatureProvider;
@@ -32,6 +34,8 @@ public interface IDevCycleClient {
3234
*/
3335
<T> Variable<T> variable(DevCycleUser user, String key, T defaultValue);
3436

37+
void track(DevCycleUser user, DevCycleEvent event) throws DevCycleException;
38+
3539
/**
3640
* Close the client and release any resources.
3741
*/

src/main/java/com/devcycle/sdk/server/common/model/DevCycleUser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public class DevCycleUser {
104104
@JsonProperty("sdkVersion")
105105
private String sdkVersion = getPlatformData().getSdkVersion();
106106

107+
@Schema(description = "DevCycle SDK Platform")
108+
@Builder.Default
109+
@JsonProperty("sdkPlatform")
110+
private String sdkPlatform = null;
111+
107112
@Schema(description = "Hostname where the SDK is running")
108113
@Builder.Default
109114
@JsonProperty("hostname")
@@ -149,13 +154,13 @@ public static DevCycleUser fromEvaluationContext(EvaluationContext ctx) {
149154
throw new TargetingKeyMissingError();
150155
}
151156

152-
DevCycleUser user = DevCycleUser.builder().userId(userId).build();
157+
DevCycleUser user = DevCycleUser.builder().userId(userId).sdkPlatform("java-of").build();
153158

154159
Map<String, Object> customData = new LinkedHashMap<>();
155160
Map<String, Object> privateCustomData = new LinkedHashMap<>();
156161

157162
for (String key : ctx.keySet()) {
158-
if (key.equals("user_id")) {
163+
if (key.equals("user_id") || key.equals("targetingKey")) {
159164
continue;
160165
}
161166

src/main/java/com/devcycle/sdk/server/common/model/PlatformData.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,31 @@ public class PlatformData {
2020
@Schema(description = "Platform the SDK is running on")
2121
@Builder.Default
2222
private String platform = "Java";
23+
2324
@Schema(description = "Version of the platform the SDK is running on")
2425
@Builder.Default
2526
private String platformVersion = System.getProperty("java.version");
27+
2628
@Schema(description = "DevCycle SDK type")
2729
@Builder.Default
2830
private PlatformData.SdkTypeEnum sdkType = PlatformData.SdkTypeEnum.SERVER;
31+
2932
@Schema(description = "DevCycle SDK Version")
3033
@Builder.Default
3134
private String sdkVersion = "2.5.0";
35+
36+
@Schema(description = "DevCycle SDK Platform")
37+
private String sdkPlatform = null;
38+
3239
@Schema(description = "Hostname where the SDK is running")
3340
private String hostname;
3441

35-
public PlatformData(String platform, String platformVersion, SdkTypeEnum sdkType, String sdkVersion, String hostname) {
42+
public PlatformData(String platform, String platformVersion, SdkTypeEnum sdkType, String sdkVersion, String sdkPlatform, String hostname) {
3643
this.platform = platform;
3744
this.platformVersion = platformVersion;
3845
this.sdkType = sdkType;
3946
this.sdkVersion = sdkVersion;
47+
this.sdkPlatform = sdkPlatform;
4048
try {
4149
this.hostname = hostname != null ? hostname : InetAddress.getLocalHost().getHostName();
4250
} catch (UnknownHostException e) {
@@ -53,6 +61,9 @@ public String toString() {
5361
platformData.put("platformVersion", platformVersion);
5462
platformData.put("sdkType", sdkType.toString());
5563
platformData.put("sdkVersion", sdkVersion);
64+
if (sdkPlatform != null) {
65+
platformData.put("sdkPlatform", sdkPlatform);
66+
}
5667
platformData.put("hostname", hostname);
5768

5869
String platformDataString = null;

src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
public final class DevCycleLocalClient implements IDevCycleClient {
2626

2727
private final String sdkKey;
28-
private final DevCycleProvider openFeatureProvider;
2928
private final LocalBucketing localBucketing = new LocalBucketing();
3029
private final EnvironmentConfigManager configManager;
3130
private EventQueueManager eventQueueManager;
@@ -61,7 +60,6 @@ public DevCycleLocalClient(String sdkKey, DevCycleLocalOptions dvcOptions) {
6160
} catch (Exception e) {
6261
DevCycleLogger.error("Error creating event queue due to error: " + e.getMessage());
6362
}
64-
this.openFeatureProvider = new DevCycleProvider(this);
6563
}
6664

6765
/**
@@ -249,12 +247,24 @@ public void close() {
249247
}
250248
}
251249

250+
251+
private static DevCycleProvider openFeatureProvider = null;
252+
252253
/**
253254
* @return the OpenFeature provider for this client.
254255
*/
255256
@Override
256257
public FeatureProvider getOpenFeatureProvider() {
257-
return this.openFeatureProvider;
258+
if (openFeatureProvider == null) {
259+
synchronized (DevCycleLocalClient.class) {
260+
if (openFeatureProvider == null) {
261+
openFeatureProvider = new DevCycleProvider(this);
262+
}
263+
PlatformData platformData = PlatformData.builder().sdkPlatform("java-of").build();
264+
localBucketing.setPlatformData(platformData.toString());
265+
}
266+
}
267+
return openFeatureProvider;
258268
}
259269

260270
@Override

0 commit comments

Comments
 (0)