Skip to content

Commit

Permalink
[WIP] use SentryUUID instead of UUID.random().toString
Browse files Browse the repository at this point in the history
  • Loading branch information
lbloder committed Oct 22, 2024
1 parent a50d881 commit 149d59c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.sentry.MemoryCollectionData;
import io.sentry.PerformanceCollectionData;
import io.sentry.SentryLevel;
import io.sentry.SentryUUID;
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
import io.sentry.profilemeasurements.ProfileMeasurement;
import io.sentry.profilemeasurements.ProfileMeasurementValue;
Expand Down Expand Up @@ -137,7 +138,7 @@ public AndroidProfiler(
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP) return null;

// We create a file with a uuid name, so no need to check if it already exists
traceFile = new File(traceFilesDir, UUID.randomUUID() + ".trace");
traceFile = new File(traceFilesDir, SentryUUID.generateSentryId() + ".trace");

measurementsMap.clear();
screenFrameRateMeasurements.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import io.sentry.ISentryLifecycleToken;
import io.sentry.SentryUUID;
import io.sentry.util.AutoClosableReentrantLock;
import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -65,7 +66,7 @@ public static String id(final @NotNull Context context) throws RuntimeException
static @NotNull String writeInstallationFile(final @NotNull File installation)
throws IOException {
try (final OutputStream out = new FileOutputStream(installation)) {
final String id = UUID.randomUUID().toString();
final String id = SentryUUID.generateSentryId();
out.write(id.getBytes(UTF_8));
out.flush();
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.SentryUUID;
import io.sentry.android.core.BuildInfoProvider;
import io.sentry.android.core.ContextUtils;
import io.sentry.util.Objects;
Expand Down Expand Up @@ -262,7 +263,7 @@ public void onActivityDestroyed(@NotNull Activity activity) {}
if (!isAvailable) {
return null;
}
final String uid = UUID.randomUUID().toString();
final String uid = SentryUUID.generateSentryId();
listenerMap.put(uid, listener);
trackCurrentWindow();
return uid;
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/ProfilingTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public ProfilingTraceData(
// Stacktrace context
this.transactionId = transactionId;
this.traceId = traceId;
this.profileId = UUID.randomUUID().toString();
this.profileId = SentryUUID.generateSentryId();
this.environment = environment != null ? environment : DEFAULT_ENVIRONMENT;
this.truncationReason = truncationReason;
if (!isTruncationReasonValid()) {
Expand Down
10 changes: 2 additions & 8 deletions sentry/src/main/java/io/sentry/SpanId.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import static io.sentry.util.StringUtils.PROPER_NIL_UUID;

import io.sentry.util.LazyEvaluator;
import io.sentry.util.StringUtils;
import java.io.IOException;
import java.util.Objects;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;

public final class SpanId implements JsonSerializable {
public static final SpanId EMPTY_ID = new SpanId(PROPER_NIL_UUID);
public static final SpanId EMPTY_ID = new SpanId(PROPER_NIL_UUID.replace("-", ""));

private final @NotNull LazyEvaluator<String> lazyValue;

Expand All @@ -21,11 +19,7 @@ public SpanId(final @NotNull String value) {

public SpanId() {
this.lazyValue =
new LazyEvaluator<>(
() ->
StringUtils.normalizeUUID(UUID.randomUUID().toString())
.replace("-", "")
.substring(0, 16));
new LazyEvaluator<>(SentryUUID::generateSpanId);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion sentry/src/main/java/io/sentry/cache/EnvelopeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.sentry.SentryItemType;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.SentryUUID;
import io.sentry.Session;
import io.sentry.UncaughtExceptionHandlerIntegration;
import io.sentry.hints.AbnormalExit;
Expand Down Expand Up @@ -368,7 +369,7 @@ public void discard(final @NotNull SentryEnvelope envelope) {
if (fileNameMap.containsKey(envelope)) {
fileName = fileNameMap.get(envelope);
} else {
fileName = UUID.randomUUID() + SUFFIX_ENVELOPE_FILE;
fileName = SentryUUID.generateSentryId() + SUFFIX_ENVELOPE_FILE;
fileNameMap.put(envelope, fileName);
}

Expand Down
5 changes: 3 additions & 2 deletions sentry/src/main/java/io/sentry/protocol/SentryId.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.sentry.JsonSerializable;
import io.sentry.ObjectReader;
import io.sentry.ObjectWriter;
import io.sentry.SentryUUID;
import io.sentry.util.LazyEvaluator;
import io.sentry.util.StringUtils;
import java.io.IOException;
Expand All @@ -14,7 +15,7 @@

public final class SentryId implements JsonSerializable {

public static final SentryId EMPTY_ID = new SentryId(new UUID(0, 0));
public static final SentryId EMPTY_ID = new SentryId(StringUtils.PROPER_NIL_UUID);

private final @NotNull LazyEvaluator<String> lazyStringValue;

Expand All @@ -26,7 +27,7 @@ public SentryId(@Nullable UUID uuid) {
if (uuid != null) {
this.lazyStringValue = new LazyEvaluator<>(() -> normalize(uuid.toString()));
} else {
this.lazyStringValue = new LazyEvaluator<>(() -> normalize(UUID.randomUUID().toString()));
this.lazyStringValue = new LazyEvaluator<>(SentryUUID::generateSentryId);
}
}

Expand Down

0 comments on commit 149d59c

Please sign in to comment.