@@ -1028,6 +1028,73 @@ func TestMakeSerializationSafe(t *testing.T) {
10281028 }
10291029 })
10301030
1031+ t .Run ("pre-serializes User when Data is empty" , func (t * testing.T ) {
1032+ event := & Event {
1033+ Extra : map [string ]interface {}{"key" : "value" },
1034+ User : User {ID : "1" , Email : "user@example.com" },
1035+ }
1036+ event .MakeSerializationSafe ()
1037+
1038+ if event .serializedUser == nil {
1039+ t .Fatal ("serializedUser should be set" )
1040+ }
1041+
1042+ jsonData , err := json .Marshal (event )
1043+ if err != nil {
1044+ t .Fatalf ("marshal failed: %v" , err )
1045+ }
1046+
1047+ var got map [string ]interface {}
1048+ if err := json .Unmarshal (jsonData , & got ); err != nil {
1049+ t .Fatalf ("unmarshal failed: %v" , err )
1050+ }
1051+
1052+ user , ok := got ["user" ].(map [string ]interface {})
1053+ if ! ok {
1054+ t .Fatalf ("expected user field in JSON, got %s" , jsonData )
1055+ }
1056+ if user ["id" ] != "1" {
1057+ t .Errorf ("expected user.id=1, got %v" , user ["id" ])
1058+ }
1059+ if user ["email" ] != "user@example.com" {
1060+ t .Errorf ("expected user.email=user@example.com, got %v" , user ["email" ])
1061+ }
1062+ })
1063+
1064+ t .Run ("pre-serializes transaction spans" , func (t * testing.T ) {
1065+ event := & Event {
1066+ Type : transactionType ,
1067+ Contexts : map [string ]Context {
1068+ "trace" : TraceContext {
1069+ TraceID : TraceIDFromHex ("90d57511038845dcb4164a70fc3a7fdb" ),
1070+ SpanID : SpanIDFromHex ("f7f3fd754a9040eb" ),
1071+ }.Map (),
1072+ },
1073+ Spans : []* Span {{
1074+ TraceID : TraceIDFromHex ("90d57511038845dcb4164a70fc3a7fdb" ),
1075+ SpanID : SpanIDFromHex ("4aaf45ea7db94520" ),
1076+ StartTime : time .Unix (1 , 0 ).UTC (),
1077+ EndTime : time .Unix (2 , 0 ).UTC (),
1078+ }},
1079+ }
1080+ event .MakeSerializationSafe ()
1081+
1082+ jsonData , err := json .Marshal (event )
1083+ if err != nil {
1084+ t .Fatalf ("marshal failed: %v" , err )
1085+ }
1086+
1087+ var got map [string ]interface {}
1088+ if err := json .Unmarshal (jsonData , & got ); err != nil {
1089+ t .Fatalf ("unmarshal failed: %v" , err )
1090+ }
1091+
1092+ spans , ok := got ["spans" ].([]interface {})
1093+ if ! ok || len (spans ) != 1 {
1094+ t .Fatalf ("expected one span in JSON, got %s" , jsonData )
1095+ }
1096+ })
1097+
10311098 t .Run ("marshaled output matches original event" , func (t * testing.T ) {
10321099 event := & Event {
10331100 EventID : "12345678901234567890123456789012" ,
0 commit comments