Skip to content

Commit 9dae6ab

Browse files
committed
fix sentry id
1 parent 3a12ed7 commit 9dae6ab

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
import 'package:meta/meta.dart';
22
import 'package:uuid/uuid.dart';
33

4-
/// Hexadecimal string representing a uuid4 value
4+
/// Hexadecimal string representing a uuid4 value.
5+
/// The length is exactly 32
6+
/// characters. Dashes are not allowed. Has to be lowercase.
57
@immutable
68
class SentryId {
7-
static final SentryId _emptyId =
8-
SentryId.fromId('00000000-0000-0000-0000-000000000000');
9-
109
/// The ID Sentry.io assigned to the submitted event for future reference.
1110
final String _id;
1211

1312
static final Uuid _uuidGenerator = Uuid();
1413

15-
SentryId._internal({String? id}) : _id = id ?? _uuidGenerator.v4();
14+
SentryId._internal({String? id})
15+
: _id =
16+
id?.replaceAll('-', '') ?? _uuidGenerator.v4().replaceAll('-', '');
1617

1718
/// Generates a new SentryId
18-
factory SentryId.newId() => SentryId._internal();
19+
SentryId.newId() : this._internal();
1920

2021
/// Generates a SentryId with the given UUID
21-
factory SentryId.fromId(String id) => SentryId._internal(id: id);
22+
SentryId.fromId(String id) : this._internal(id: id);
2223

2324
/// SentryId with an empty UUID
24-
factory SentryId.empty() => _emptyId;
25+
const SentryId.empty() : _id = '00000000000000000000000000000000';
26+
27+
@override
28+
String toString() => _id;
29+
30+
@override
31+
int get hashCode => _id.hashCode;
2532

2633
@override
27-
String toString() => _id.replaceAll('-', '');
34+
bool operator ==(o) {
35+
if (o is SentryId) {
36+
return o._id == _id;
37+
}
38+
return false;
39+
}
2840
}

dart/test/sentry_id_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:sentry/src/protocol/sentry_id.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
test('empty id', () {
6+
expect(SentryId.empty().toString(), '00000000000000000000000000000000');
7+
});
8+
9+
test('empty id equals from empty id', () {
10+
expect(
11+
SentryId.empty(),
12+
SentryId.fromId('00000000000000000000000000000000'),
13+
);
14+
});
15+
16+
test('uuid format with dashes', () {
17+
expect(
18+
SentryId.fromId('00000000-0000-0000-0000-000000000000'),
19+
SentryId.empty(),
20+
);
21+
});
22+
23+
test('empty id equality', () {
24+
expect(SentryId.empty(), SentryId.empty());
25+
});
26+
27+
test('id roundtrip', () {
28+
final id = SentryId.newId();
29+
expect(id, SentryId.fromId(id.toString()));
30+
});
31+
32+
test('newId should not be equal to newId', () {
33+
expect(SentryId.newId() == SentryId.newId(), false);
34+
});
35+
}

dart/test/transport/http_transport_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void main() {
9292
SentryEnvelope.fromEvent(sentryEvent, fixture.options.sdk);
9393
final eventId = await sut.send(envelope);
9494

95-
expect(eventId.toString(), SentryId.empty().toString());
95+
expect(eventId, SentryId.empty());
9696
expect(httpCalled, false);
9797
});
9898
});

0 commit comments

Comments
 (0)