Skip to content

Commit

Permalink
call event
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSinn committed Jun 17, 2024
1 parent 254c9cc commit 2a58a27
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DevCycl
}
this.configETag = currentETag;
this.configLastModified = lastModified;
try {
this.eventQueueManager.queueSDKConfigEvent(call.request(), response);
} catch (Exception e) {
// Explicitly ignore - best effort.
}
return response.body();
} else if (httpResponseCode == HttpResponseCode.NOT_MODIFIED) {
DevCycleLogger.debug("Config not modified, using cache, etag: " + this.configETag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.devcycle.sdk.server.common.model.DevCycleEvent;
import com.devcycle.sdk.server.common.model.DevCycleResponse;
import com.devcycle.sdk.server.common.model.DevCycleUser;
import com.devcycle.sdk.server.common.model.ProjectConfig;
import com.devcycle.sdk.server.local.api.DevCycleLocalEventsApiClient;
import com.devcycle.sdk.server.local.bucketing.LocalBucketing;
import com.devcycle.sdk.server.local.model.BucketedUserConfig;
Expand Down Expand Up @@ -109,29 +110,33 @@ public void queueEvent(DevCycleUser user, DevCycleEvent event) throws Exception
this.localBucketing.queueEvent(this.sdkKey, OBJECT_MAPPER.writeValueAsString(user), OBJECT_MAPPER.writeValueAsString(event));
}

public void queueSDKConfigEvent(Request req, okhttp3.Response response) throws Exception {
public void queueSDKConfigEvent(Request req, Response<ProjectConfig> response) throws Exception {
DevCycleUser user = new DevCycleUser();
user.setUserId(localBucketing.getClientUUID() + "@" + InetAddress.getLocalHost().getHostName());
DevCycleEvent event = new DevCycleEvent();
event.setType("sdkConfig");
event.setTarget(req.url().toString());

if (response.networkResponse() != null)
event.setValue(BigDecimal.valueOf(response.networkResponse().receivedResponseAtMillis() - response.networkResponse().sentRequestAtMillis()));
else
event.setValue(BigDecimal.valueOf(-1));

event.setMetaData(Map.of(
"clientUUID", localBucketing.getClientUUID(),
"reqEtag", req.header("If-None-Match"),
"reqLastModified", req.header("If-Modified-Since"),
"resEtag", response.header("etag"),
"resLastModified", response.header("Last-Modified"),
"resRayId", response.header("cf-ray"),
"resStatus", response.code(),
"errMsg", response.code() != 200 && response.code() != 304 ? response.message() : null,
"sseConnected", null));
try(okhttp3.Response res = response.raw()) {
if (res.isSuccessful()) {
event.setValue(BigDecimal.valueOf(res.networkResponse().receivedResponseAtMillis() - res.networkResponse().sentRequestAtMillis()));
} else {
event.setValue(BigDecimal.valueOf(-1));
}
event.setMetaData(Map.of(
"clientUUID", localBucketing.getClientUUID(),
"reqEtag", req.header("If-None-Match"),
"reqLastModified", req.header("If-Modified-Since"),
"resEtag", res.header("etag"),
"resLastModified", res.header("Last-Modified"),
"resRayId", res.header("cf-ray"),
"resStatus", response.code(),
"errMsg", response.code() != 200 && response.code() != 304 ? response.message() : null,
"sseConnected", null));

} catch (Exception e) {
event.setValue(BigDecimal.valueOf(-1));
}
queueEvent(user, event);
}

Expand Down

0 comments on commit 2a58a27

Please sign in to comment.