Skip to content

SessionID as string #3834

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

Merged
merged 51 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
4070536
replace uuid with string for sessionId, use SentryUUID for generating…
lbloder Oct 29, 2024
df743f2
add changelog
lbloder Oct 29, 2024
9803d5c
Format code
getsentry-bot 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
c15312f
Merge branch 'feat/fast-id-generation' into feat/session-id-as-string
adinauer Oct 30, 2024
5d00ae5
Merge branch '8.x.x' into feat/fast-id-generation
lbloder Nov 4, 2024
311c151
Merge branch 'feat/fast-id-generation' into feat/session-id-as-string
lbloder Nov 4, 2024
32097ad
fix tests
lbloder Nov 4, 2024
3adf03d
Format code
getsentry-bot Nov 4, 2024
9a1cf0e
move changelog entry to breaking changes section, add more detail
lbloder Nov 4, 2024
fac412e
test normalized is never called in no-arg constructor, only called on…
lbloder Nov 8, 2024
d015201
add log if invalid session id is being deserialized
lbloder Nov 8, 2024
9f360d1
Merge branch '8.x.x' into feat/fast-id-generation
lbloder Nov 8, 2024
7828b42
Merge branch 'feat/fast-id-generation' into feat/session-id-as-string
lbloder Nov 8, 2024
30b2602
fix test
lbloder Nov 8, 2024
fce5ac8
Merge branch 'feat/fast-id-generation' into feat/session-id-as-string
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
3293382
Merge branch 'feat/fast-id-generation' into feat/session-id-as-string
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
613cc60
Merge branch 'feat/fast-id-generation' into feat/session-id-as-string
lbloder Nov 8, 2024
1e8c6a7
allow 36 and 32 character session ids
lbloder Nov 8, 2024
22e215e
Merge branch '8.x.x' into feat/session-id-as-string
adinauer Nov 11, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Breaking Changes

- Use String instead of UUID for SessionId ([#3834](https://github.com/getsentry/sentry-java/pull/3834))
- The `Session` constructor now takes a `String` instead of a `UUID` for the `sessionId` parameter.
- `Session.getSessionId()` now returns a `String` instead of a `UUID`.
- The Android minSdk level for all Android modules is now 21 ([#3852](https://github.com/getsentry/sentry-java/pull/3852))
- The minSdk level for sentry-android-ndk changed from 19 to 21 ([#3851](https://github.com/getsentry/sentry-java/pull/3851))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class LifecycleWatcherTest {
DateUtils.getCurrentDateTime(),
0,
"abc",
UUID.fromString("3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17"),
"3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17",
true,
0,
10.0,
Expand All @@ -222,7 +222,7 @@ class LifecycleWatcherTest {
DateUtils.getDateTime(-1),
0,
"abc",
UUID.fromString("3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17"),
"3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17",
true,
0,
10.0,
Expand Down Expand Up @@ -263,7 +263,7 @@ class LifecycleWatcherTest {
DateUtils.getCurrentDateTime(),
0,
"abc",
UUID.fromString("3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17"),
"3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17",
true,
0,
10.0,
Expand Down
4 changes: 2 additions & 2 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3277,7 +3277,7 @@ public final class io/sentry/SentryWrapper {
}

public final class io/sentry/Session : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/Session$State;Ljava/util/Date;Ljava/util/Date;ILjava/lang/String;Ljava/util/UUID;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Double;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Lio/sentry/Session$State;Ljava/util/Date;Ljava/util/Date;ILjava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Long;Ljava/lang/Double;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Lio/sentry/protocol/User;Ljava/lang/String;Ljava/lang/String;)V
public fun clone ()Lio/sentry/Session;
public synthetic fun clone ()Ljava/lang/Object;
Expand All @@ -3292,7 +3292,7 @@ public final class io/sentry/Session : io/sentry/JsonSerializable, io/sentry/Jso
public fun getIpAddress ()Ljava/lang/String;
public fun getRelease ()Ljava/lang/String;
public fun getSequence ()Ljava/lang/Long;
public fun getSessionId ()Ljava/util/UUID;
public fun getSessionId ()Ljava/lang/String;
public fun getStarted ()Ljava/util/Date;
public fun getStatus ()Lio/sentry/Session$State;
public fun getTimestamp ()Ljava/util/Date;
Expand Down
24 changes: 11 additions & 13 deletions sentry/src/main/java/io/sentry/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -38,7 +37,7 @@ public enum State {
private final @Nullable String distinctId;

/** the SessionId, sid */
private final @Nullable UUID sessionId;
private final @Nullable String sessionId;

/** The session init flag */
private @Nullable Boolean init;
Expand Down Expand Up @@ -79,7 +78,7 @@ public Session(
final @Nullable Date timestamp,
final int errorCount,
final @Nullable String distinctId,
final @Nullable UUID sessionId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should write this down in the changelog as breaking change.

final @Nullable String sessionId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to apply some validation still that this is compliant with the uuid format?

final @Nullable Boolean init,
final @Nullable Long sequence,
final @Nullable Double duration,
Expand Down Expand Up @@ -115,7 +114,7 @@ public Session(
DateUtils.getCurrentDateTime(),
0,
distinctId,
UUID.randomUUID(),
SentryUUID.generateSentryId(),
true,
null,
null,
Expand All @@ -142,7 +141,7 @@ public boolean isTerminated() {
return distinctId;
}

public @Nullable UUID getSessionId() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be on the changelog as breaking change.

public @Nullable String getSessionId() {
return sessionId;
}

Expand Down Expand Up @@ -366,7 +365,7 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
throws IOException {
writer.beginObject();
if (sessionId != null) {
writer.name(JsonKeys.SID).value(sessionId.toString());
writer.name(JsonKeys.SID).value(sessionId);
}
if (distinctId != null) {
writer.name(JsonKeys.DID).value(distinctId);
Expand Down Expand Up @@ -435,7 +434,7 @@ public static final class Deserializer implements JsonDeserializer<Session> {
Date timestamp = null;
Integer errorCount = null; // @NotNull
String distinctId = null;
UUID sessionId = null;
String sessionId = null;
Boolean init = null;
State status = null; // @NotNull
Long sequence = null;
Expand All @@ -451,12 +450,11 @@ public static final class Deserializer implements JsonDeserializer<Session> {
final String nextName = reader.nextName();
switch (nextName) {
case JsonKeys.SID:
String sidString = null;
try {
sidString = reader.nextStringOrNull();
sessionId = UUID.fromString(sidString);
} catch (IllegalArgumentException e) {
logger.log(SentryLevel.ERROR, "%s sid is not valid.", sidString);
String sid = reader.nextStringOrNull();
if (sid != null && (sid.length() == 36 || sid.length() == 32)) {
sessionId = sid;
} else {
logger.log(SentryLevel.ERROR, "%s sid is not valid.", sid);
}
break;
case JsonKeys.DID:
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/main/java/io/sentry/cache/CacheStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -242,7 +241,7 @@ private boolean isValidSession(final @NotNull Session session) {
return false;
}

final UUID sessionId = session.getSessionId();
final String sessionId = session.getSessionId();

return sessionId != null;
}
Expand Down
23 changes: 11 additions & 12 deletions sentry/src/test/java/io/sentry/CombinedScopeViewTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.mockito.kotlin.same
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.lang.RuntimeException
import java.util.UUID
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -933,17 +932,17 @@ class CombinedScopeViewTest {
@Test
fun `retrieves last event id from global scope`() {
val combined = fixture.getSut()
fixture.scope.lastEventId = SentryId(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2dc"))
fixture.isolationScope.lastEventId = SentryId(UUID.fromString("d81d4e2e-bcf2-11e6-869b-7df92533d2dd"))
fixture.globalScope.lastEventId = SentryId(UUID.fromString("e81d4e2e-bcf2-11e6-869b-7df92533d2de"))
fixture.scope.lastEventId = SentryId("c81d4e2e-bcf2-11e6-869b-7df92533d2dc")
fixture.isolationScope.lastEventId = SentryId("d81d4e2e-bcf2-11e6-869b-7df92533d2dd")
fixture.globalScope.lastEventId = SentryId("e81d4e2e-bcf2-11e6-869b-7df92533d2de")

assertEquals("e81d4e2ebcf211e6869b7df92533d2de", combined.lastEventId.toString())
}

@Test
fun `sets last event id on all scopes`() {
val combined = fixture.getSut()
combined.lastEventId = SentryId(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2db"))
combined.lastEventId = SentryId("c81d4e2e-bcf2-11e6-869b-7df92533d2db")

assertEquals("c81d4e2ebcf211e6869b7df92533d2db", fixture.scope.lastEventId.toString())
assertEquals("c81d4e2ebcf211e6869b7df92533d2db", fixture.isolationScope.lastEventId.toString())
Expand All @@ -953,9 +952,9 @@ class CombinedScopeViewTest {
@Test
fun `retrieves propagation context from default scope`() {
val combined = fixture.getSut()
fixture.scope.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2dc")) }
fixture.isolationScope.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("d81d4e2e-bcf2-11e6-869b-7df92533d2dd")) }
fixture.globalScope.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("e81d4e2e-bcf2-11e6-869b-7df92533d2de")) }
fixture.scope.propagationContext = PropagationContext().also { it.traceId = SentryId("c81d4e2e-bcf2-11e6-869b-7df92533d2dc") }
fixture.isolationScope.propagationContext = PropagationContext().also { it.traceId = SentryId("d81d4e2e-bcf2-11e6-869b-7df92533d2dd") }
fixture.globalScope.propagationContext = PropagationContext().also { it.traceId = SentryId("e81d4e2e-bcf2-11e6-869b-7df92533d2de") }

assertEquals(ScopeType.ISOLATION, fixture.options.defaultScopeType)
assertEquals("d81d4e2ebcf211e6869b7df92533d2dd", combined.propagationContext.traceId.toString())
Expand All @@ -965,7 +964,7 @@ class CombinedScopeViewTest {
fun `sets propagation context on default scope`() {
val combined = fixture.getSut()

combined.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2db")) }
combined.propagationContext = PropagationContext().also { it.traceId = SentryId("c81d4e2e-bcf2-11e6-869b-7df92533d2db") }

assertEquals(ScopeType.ISOLATION, fixture.options.defaultScopeType)
assertNotEquals("c81d4e2ebcf211e6869b7df92533d2db", fixture.scope.propagationContext.traceId.toString())
Expand All @@ -976,9 +975,9 @@ class CombinedScopeViewTest {
@Test
fun `withPropagationContext uses default scope`() {
val combined = fixture.getSut()
fixture.scope.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2dc")) }
fixture.isolationScope.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("d81d4e2e-bcf2-11e6-869b-7df92533d2dd")) }
fixture.globalScope.propagationContext = PropagationContext().also { it.traceId = SentryId(UUID.fromString("e81d4e2e-bcf2-11e6-869b-7df92533d2de")) }
fixture.scope.propagationContext = PropagationContext().also { it.traceId = SentryId("c81d4e2e-bcf2-11e6-869b-7df92533d2dc") }
fixture.isolationScope.propagationContext = PropagationContext().also { it.traceId = SentryId("d81d4e2e-bcf2-11e6-869b-7df92533d2dd") }
fixture.globalScope.propagationContext = PropagationContext().also { it.traceId = SentryId("e81d4e2e-bcf2-11e6-869b-7df92533d2de") }

var capturedPropagationContext: PropagationContext? = null
combined.withPropagationContext { propagationContext ->
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/test/java/io/sentry/JsonObjectSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.util.Calendar
import java.util.Currency
import java.util.Locale
import java.util.TimeZone
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicIntegerArray

Expand Down Expand Up @@ -240,7 +239,7 @@ internal class JsonObjectSerializerTest {

@Test
fun `serializing UUID`() {
fixture.getSUT().serialize(fixture.writer, fixture.logger, UUID.fromString("828900a5-15dc-413f-8c17-6ef04d74e074"))
fixture.getSUT().serialize(fixture.writer, fixture.logger, "828900a5-15dc-413f-8c17-6ef04d74e074")
verify(fixture.writer).value("828900a5-15dc-413f-8c17-6ef04d74e074")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.net.URI
import java.util.Calendar
import java.util.Currency
import java.util.Locale
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicIntegerArray
import kotlin.test.assertEquals
Expand Down Expand Up @@ -318,7 +317,7 @@ class JsonReflectionObjectSerializerTest {

@Test
fun `UUID is serialized`() {
val actual = fixture.getSut().serialize(UUID.fromString("828900a5-15dc-413f-8c17-6ef04d74e074"), fixture.logger)
val actual = fixture.getSut().serialize("828900a5-15dc-413f-8c17-6ef04d74e074", fixture.logger)
assertEquals("828900a5-15dc-413f-8c17-6ef04d74e074", actual)
}

Expand Down
19 changes: 15 additions & 4 deletions sentry/src/test/java/io/sentry/JsonSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ class JsonSerializerTest {
assertSessionData(expectedSession)
}

@Test
fun `session deserializes 32 character id`() {
val sessionId = "c81d4e2ebcf211e6869b7df92533d2db"
val session = createSessionMockData("c81d4e2ebcf211e6869b7df92533d2db")
val jsonSession = serializeToString(session)
// reversing, so we can assert values and not a json string
val expectedSession = fixture.serializer.deserialize(StringReader(jsonSession), Session::class.java)

assertSessionData(expectedSession, "c81d4e2ebcf211e6869b7df92533d2db")
}

@Test
fun `When deserializing an Envelope, all the values should be set to the SentryEnvelope object`() {
val jsonEnvelope = FileFromResources.invoke("envelope_session.txt")
Expand Down Expand Up @@ -1248,9 +1259,9 @@ class JsonSerializerTest {
assertEquals(replayRecording, deserializedRecording)
}

private fun assertSessionData(expectedSession: Session?) {
private fun assertSessionData(expectedSession: Session?, expectedSessionId: String = "c81d4e2e-bcf2-11e6-869b-7df92533d2db") {
assertNotNull(expectedSession)
assertEquals(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2db"), expectedSession.sessionId)
assertEquals(expectedSessionId, expectedSession.sessionId)
assertEquals("123", expectedSession.distinctId)
assertTrue(expectedSession.init!!)
assertEquals("2020-02-07T14:16:00.000Z", DateUtils.getTimestamp(expectedSession.started!!))
Expand Down Expand Up @@ -1280,14 +1291,14 @@ class JsonSerializerTest {
private fun generateEmptySentryEvent(date: Date = Date()): SentryEvent =
SentryEvent(date)

private fun createSessionMockData(): Session =
private fun createSessionMockData(sessionId: String = "c81d4e2e-bcf2-11e6-869b-7df92533d2db"): Session =
Session(
Session.State.Ok,
DateUtils.getDateTime("2020-02-07T14:16:00.000Z"),
DateUtils.getDateTime("2020-02-07T14:16:00.000Z"),
2,
"123",
UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2db"),
sessionId,
true,
123456.toLong(),
6000.toDouble(),
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/test/java/io/sentry/OutboxSenderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import java.io.FileNotFoundException
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Date
import java.util.UUID
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
Expand Down Expand Up @@ -74,7 +73,7 @@ class OutboxSenderTest {
@Test
fun `when parser is EnvelopeReader and serializer returns SentryEvent, event captured, file is deleted `() {
fixture.envelopeReader = EnvelopeReader(JsonSerializer(fixture.options))
val expected = SentryEvent(SentryId(UUID.fromString("9ec79c33-ec99-42ab-8353-589fcb2e04dc")), Date())
val expected = SentryEvent(SentryId("9ec79c33-ec99-42ab-8353-589fcb2e04dc"), Date())
whenever(fixture.serializer.deserialize(any(), eq(SentryEvent::class.java))).thenReturn(expected)
val sut = fixture.getSut()
val path = getTempEnvelope()
Expand Down
Loading
Loading