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

Faster ID generation #3818

Merged
merged 36 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
22029c1
lazy uuid generation for SentryId and SpanId
lbloder Oct 7, 2024
f947f82
add changelog
lbloder Oct 7, 2024
debd140
Merge branch '8.x.x' into feat/lazy-span-id-v8
adinauer Oct 9, 2024
e6df0ad
add tests for lazy init, rework SentryId to cache string result
lbloder Oct 11, 2024
8a93fec
Merge branch '8.x.x' into feat/lazy-span-id-v8
lbloder Oct 11, 2024
fe8ccb0
Merge branch '8.x.x' into feat/lazy-span-id-v8
lbloder Oct 15, 2024
28b5bde
Merge branch '8.x.x' into feat/lazy-span-id-v8
lbloder Oct 18, 2024
f2fba85
fix changelog
lbloder Oct 18, 2024
3e1a32c
Merge branch '8.x.x' into feat/lazy-span-id-v8
lbloder Oct 21, 2024
c7ab294
Update sentry/src/main/java/io/sentry/protocol/SentryId.java
lbloder Oct 22, 2024
f1e66b2
Update sentry/src/main/java/io/sentry/protocol/SentryId.java
lbloder Oct 22, 2024
76b23c8
Update sentry/src/main/java/io/sentry/protocol/SentryId.java
lbloder Oct 22, 2024
8599535
Update sentry/src/main/java/io/sentry/protocol/SentryId.java
lbloder Oct 22, 2024
3bae1d7
Update sentry/src/main/java/io/sentry/protocol/SentryId.java
lbloder Oct 22, 2024
edba0c7
Format code
getsentry-bot Oct 22, 2024
c18a74d
Add object comparison to SpanFrameMetricsCollector only check for tim…
lbloder Oct 22, 2024
35b17db
Merge branch 'feat/lazy-span-id-v8' of github.com:getsentry/sentry-ja…
lbloder Oct 22, 2024
a50d881
add proposed SentryUUID class
lbloder Oct 22, 2024
149d59c
[WIP] use SentryUUID instead of UUID.random().toString
lbloder Oct 22, 2024
6418a33
Format code
getsentry-bot Oct 23, 2024
5314e83
split SentryUUID internals into separate classes for easier attribution
lbloder Oct 29, 2024
58a00c4
Merge branch '8.x.x' into feat/lazy-span-id-v8
lbloder Oct 29, 2024
097738b
add changelog
lbloder Oct 29, 2024
3518fce
Merge branch 'feat/lazy-span-id-v8' into feat/fast-id-generation
lbloder Oct 29, 2024
d11c3cc
fix tests
lbloder Oct 29, 2024
1ea4212
Merge branch '8.x.x' into feat/fast-id-generation
lbloder Oct 29, 2024
81a3bdb
fix SpanId.EMPTY_ID
lbloder Oct 29, 2024
5d00ae5
Merge branch '8.x.x' into feat/fast-id-generation
lbloder Nov 4, 2024
fac412e
test normalized is never called in no-arg constructor, only called on…
lbloder Nov 8, 2024
9f360d1
Merge branch '8.x.x' into feat/fast-id-generation
lbloder Nov 8, 2024
30b2602
fix test
lbloder Nov 8, 2024
05540a3
Format code
getsentry-bot Nov 8, 2024
143c26e
use new Random Generator
lbloder Nov 8, 2024
57d0a9b
Merge branch 'feat/fast-id-generation' of github.com:getsentry/sentry…
lbloder Nov 8, 2024
45c3cbe
fix Sentry Empty ID, replace dashes if 36 char uuid String is passed …
lbloder Nov 8, 2024
5c2c580
fix Tests for SpanId, add tests for SentryUUID and UUIDStringUtils
lbloder Nov 8, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add `globalHubMode` to options ([#3805](https://github.com/getsentry/sentry-java/pull/3805))
- `globalHubMode` used to only be a param on `Sentry.init`. To make it easier to be used in e.g. Desktop environments, we now additionally added it as an option on SentryOptions that can also be set via `sentry.properties`.
- If both the param on `Sentry.init` and the option are set, the option will win. By default the option is set to `null` meaning whatever is passed to `Sentry.init` takes effect.
- Lazy uuid generation for SentryId and SpanId ([#3770](https://github.com/getsentry/sentry-java/pull/3770))

## 8.0.0-beta.1

Expand Down
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 All @@ -24,7 +25,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -137,7 +137,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,14 +2,14 @@

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;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
Expand Down Expand Up @@ -65,7 +65,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 @@ -45,17 +45,19 @@ public class SpanFrameMetricsCollector
private final @NotNull SortedSet<ISpan> runningSpans =
new TreeSet<>(
(o1, o2) -> {
if (o1 == o2) {
return 0;
}
int timeDiff = o1.getStartDate().compareTo(o2.getStartDate());
if (timeDiff != 0) {
return timeDiff;
} else {
// TreeSet uses compareTo to check for duplicates, so ensure that
// two non-equal spans with the same start date are not considered equal
return o1.getSpanContext()
.getSpanId()
.toString()
.compareTo(o2.getSpanContext().getSpanId().toString());
}
// TreeSet uses compareTo to check for duplicates, so ensure that
// two non-equal spans with the same start date are not considered equal
return o1.getSpanContext()
.getSpanId()
.toString()
.compareTo(o2.getSpanContext().getSpanId().toString());
});

// all collected frames, sorted by frame end time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
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;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -262,7 +262,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
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -6151,6 +6151,7 @@ public final class io/sentry/util/SpanUtils {
}

public final class io/sentry/util/StringUtils {
public static final field PROPER_NIL_UUID Ljava/lang/String;
public static fun byteCountToString (J)Ljava/lang/String;
public static fun calculateStringHash (Ljava/lang/String;Lio/sentry/ILogger;)Ljava/lang/String;
public static fun camelCase (Ljava/lang/String;)Ljava/lang/String;
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/main/java/io/sentry/ProfilingTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -154,7 +153,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
Loading