@@ -16,7 +16,7 @@ pub const InstrumentationScope = struct {
16
16
pub fn hash (_ : HashContext , self : Self ) u64 {
17
17
const hashContext = Attributes.HashContext {};
18
18
19
- const attributesHash = hashContext .hash (Attributes .with (self .attributes ));
19
+ const attributesHash = hashContext .hash (Attributes .with (self .attributes )) catch @panic ( "Failed to hash attributes" ) ;
20
20
21
21
var h = std .hash .Wyhash .init (0 );
22
22
@@ -91,3 +91,21 @@ test "InstrumentationScope should equal correctly" {
91
91
92
92
try std .testing .expect (hashContext .eql (first , second ));
93
93
}
94
+
95
+ test "InstrumentationScope hash should be consistent regardless of attribute order" {
96
+ const allocator = std .testing .allocator ;
97
+
98
+ const attrs1 = try Attributes .from (allocator , .{ @as ([]const u8 , "key1" ), @as (u64 , 42 ), @as ([]const u8 , "key2" ), true , @as ([]const u8 , "key3" ), @as ([]const u8 , "value3" ) });
99
+ defer allocator .free (attrs1 .? );
100
+
101
+ const attrs2 = try Attributes .from (allocator , .{ @as ([]const u8 , "key3" ), @as ([]const u8 , "value3" ), @as ([]const u8 , "key1" ), @as (u64 , 42 ), @as ([]const u8 , "key2" ), true });
102
+ defer allocator .free (attrs2 .? );
103
+
104
+ const scope1 : InstrumentationScope = .{ .name = "testScope" , .attributes = attrs1 };
105
+ const scope2 : InstrumentationScope = .{ .name = "testScope" , .attributes = attrs2 };
106
+
107
+ const hashContext = InstrumentationScope.HashContext {};
108
+
109
+ try std .testing .expectEqual (hashContext .hash (scope1 ), hashContext .hash (scope2 ));
110
+ try std .testing .expect (hashContext .eql (scope1 , scope2 ));
111
+ }
0 commit comments