Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate timestamps at call site rather than asynchronously #686

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions analytics/src/main/java/com/segment/analytics/Analytics.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.segment.analytics.integrations.Logger;
import com.segment.analytics.integrations.ScreenPayload;
import com.segment.analytics.integrations.TrackPayload;
import com.segment.analytics.internal.NanoDate;
import com.segment.analytics.internal.Private;
import com.segment.analytics.internal.Utils;
import com.segment.analytics.internal.Utils.AnalyticsNetworkExecutorService;
Expand Down Expand Up @@ -476,7 +477,7 @@ public void identify(
if (isNullOrEmpty(userId) && isNullOrEmpty(newTraits)) {
throw new IllegalArgumentException("Either userId or some traits must be provided.");
}

NanoDate timestamp = new NanoDate();
analyticsExecutor.submit(
new Runnable() {
@Override
Expand All @@ -493,7 +494,7 @@ public void run() {
analyticsContext.setTraits(traits); // Update the references

IdentifyPayload.Builder builder =
new IdentifyPayload.Builder().traits(traitsCache.get());
new IdentifyPayload.Builder().timestamp(timestamp).traits(traitsCache.get());
fillAndEnqueue(builder, options);
}
});
Expand Down Expand Up @@ -531,7 +532,7 @@ public void group(
if (isNullOrEmpty(groupId)) {
throw new IllegalArgumentException("groupId must not be null or empty.");
}

NanoDate timestamp = new NanoDate();
analyticsExecutor.submit(
new Runnable() {
@Override
Expand All @@ -544,7 +545,10 @@ public void run() {
}

GroupPayload.Builder builder =
new GroupPayload.Builder().groupId(groupId).traits(finalGroupTraits);
new GroupPayload.Builder()
.timestamp(timestamp)
.groupId(groupId)
.traits(finalGroupTraits);
fillAndEnqueue(builder, options);
}
});
Expand Down Expand Up @@ -580,7 +584,7 @@ public void track(
if (isNullOrEmpty(event)) {
throw new IllegalArgumentException("event must not be null or empty.");
}

NanoDate timestamp = new NanoDate();
analyticsExecutor.submit(
new Runnable() {
@Override
Expand All @@ -593,7 +597,10 @@ public void run() {
}

TrackPayload.Builder builder =
new TrackPayload.Builder().event(event).properties(finalProperties);
new TrackPayload.Builder()
.timestamp(timestamp)
.event(event)
.properties(finalProperties);
fillAndEnqueue(builder, options);
}
});
Expand Down Expand Up @@ -646,7 +653,7 @@ public void screen(
if (isNullOrEmpty(category) && isNullOrEmpty(name)) {
throw new IllegalArgumentException("either category or name must be provided.");
}

NanoDate timestamp = new NanoDate();
analyticsExecutor.submit(
new Runnable() {
@Override
Expand All @@ -661,6 +668,7 @@ public void run() {
//noinspection deprecation
ScreenPayload.Builder builder =
new ScreenPayload.Builder()
.timestamp(timestamp)
.name(name)
.category(category)
.properties(finalProperties);
Expand Down Expand Up @@ -700,12 +708,14 @@ public void alias(final @NonNull String newId, final @Nullable Options options)
throw new IllegalArgumentException("newId must not be null or empty.");
}

NanoDate timestamp = new NanoDate();
analyticsExecutor.submit(
new Runnable() {
@Override
public void run() {
AliasPayload.Builder builder =
new AliasPayload.Builder()
.timestamp(timestamp)
.userId(newId)
.previousId(analyticsContext.traits().currentId());
fillAndEnqueue(builder, options);
Expand Down