From 04f6e7ee4e785b287a90f611ea88d14409070f3a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 26 Nov 2024 12:06:09 -0500 Subject: [PATCH 1/3] DEBUG-2334 add new_record flag to AR model custom serializer --- lib/datadog/di/contrib/active_record.rb | 1 + .../serializer_active_record_spec.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/datadog/di/contrib/active_record.rb b/lib/datadog/di/contrib/active_record.rb index d929cde49ed..87e8618d7a0 100644 --- a/lib/datadog/di/contrib/active_record.rb +++ b/lib/datadog/di/contrib/active_record.rb @@ -5,6 +5,7 @@ # steep:ignore:start value_to_serialize = { attributes: value.attributes, + new_record: value.new_record?, } serializer.serialize_value(value_to_serialize, depth: depth ? depth - 1 : nil, type: value.class) # steep:ignore:end diff --git a/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb b/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb index df6cf17f317..27a45c5b4d2 100644 --- a/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb +++ b/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb @@ -78,6 +78,9 @@ def mysql_connection_string expected: {type: "SerializerRailsSpecTestEmptyModel", entries: [[ {type: 'Symbol', value: 'attributes'}, {type: 'Hash', entries: [[{type: 'String', value: 'id'}, {type: 'NilClass', isNull: true}]]}, + ], [ + {type: 'Symbol', value: 'new_record'}, + {type: 'TrueClass', value: 'true'}, ]]}}, {name: "AR model with empty attributes", input: -> { SerializerRailsSpecTestBasicModel.new }, @@ -89,6 +92,9 @@ def mysql_connection_string [{type: 'String', value: 'created_at'}, {type: 'NilClass', isNull: true}], [{type: 'String', value: 'updated_at'}, {type: 'NilClass', isNull: true}], ]}, + ], [ + {type: 'Symbol', value: 'new_record'}, + {type: 'TrueClass', value: 'true'}, ]]}}, {name: "AR model with filled out attributes", input: -> { @@ -105,6 +111,28 @@ def mysql_connection_string [{type: 'String', value: 'created_at'}, {type: 'Time', value: '2020-01-02T00:00:00Z'}], [{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}], ]}, + ], [ + {type: 'Symbol', value: 'new_record'}, + {type: 'TrueClass', value: 'true'}, + ]]}}, + {name: "AR model with filled out attributes and persisted", + input: -> { + SerializerRailsSpecTestBasicModel.create!( + title: 'Hello, world!', created_at: Time.utc(2020, 1, 2), updated_at: Time.utc(2020, 1, 3) + ) + }, + expected: {type: "SerializerRailsSpecTestBasicModel", entries: [[ + {type: 'Symbol', value: 'attributes'}, + {type: 'Hash', entries: [ + [{type: 'String', value: 'id'}, {type: 'Integer', value: '1'}], + [{type: 'String', value: 'title'}, {type: 'String', value: 'Hello, world!'}], + # TODO serialize Time, Date, DateTime types + [{type: 'String', value: 'created_at'}, {type: 'Time', value: '2020-01-02T00:00:00Z'}], + [{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}], + ]}, + ], [ + {type: 'Symbol', value: 'new_record'}, + {type: 'FalseClass', value: 'false'}, ]]}}, ] From 20193575f255e157e28b0b151d93e8e99de4db19 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 26 Nov 2024 12:13:40 -0500 Subject: [PATCH 2/3] standard --- .../serializer_active_record_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb b/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb index 27a45c5b4d2..725912dee27 100644 --- a/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb +++ b/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb @@ -79,8 +79,8 @@ def mysql_connection_string {type: 'Symbol', value: 'attributes'}, {type: 'Hash', entries: [[{type: 'String', value: 'id'}, {type: 'NilClass', isNull: true}]]}, ], [ - {type: 'Symbol', value: 'new_record'}, - {type: 'TrueClass', value: 'true'}, + {type: 'Symbol', value: 'new_record'}, + {type: 'TrueClass', value: 'true'}, ]]}}, {name: "AR model with empty attributes", input: -> { SerializerRailsSpecTestBasicModel.new }, @@ -93,8 +93,8 @@ def mysql_connection_string [{type: 'String', value: 'updated_at'}, {type: 'NilClass', isNull: true}], ]}, ], [ - {type: 'Symbol', value: 'new_record'}, - {type: 'TrueClass', value: 'true'}, + {type: 'Symbol', value: 'new_record'}, + {type: 'TrueClass', value: 'true'}, ]]}}, {name: "AR model with filled out attributes", input: -> { @@ -112,8 +112,8 @@ def mysql_connection_string [{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}], ]}, ], [ - {type: 'Symbol', value: 'new_record'}, - {type: 'TrueClass', value: 'true'}, + {type: 'Symbol', value: 'new_record'}, + {type: 'TrueClass', value: 'true'}, ]]}}, {name: "AR model with filled out attributes and persisted", input: -> { @@ -131,8 +131,8 @@ def mysql_connection_string [{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}], ]}, ], [ - {type: 'Symbol', value: 'new_record'}, - {type: 'FalseClass', value: 'false'}, + {type: 'Symbol', value: 'new_record'}, + {type: 'FalseClass', value: 'false'}, ]]}}, ] From 35b0afdfbbd72f92c298b444a3767f6028eb1a87 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 26 Nov 2024 12:15:03 -0500 Subject: [PATCH 3/3] all time types are serialized --- .../di/contrib/active_record/serializer_active_record_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb b/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb index 725912dee27..807731cf8b1 100644 --- a/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb +++ b/spec/datadog/di/contrib/active_record/serializer_active_record_spec.rb @@ -107,7 +107,6 @@ def mysql_connection_string {type: 'Hash', entries: [ [{type: 'String', value: 'id'}, {type: 'NilClass', isNull: true}], [{type: 'String', value: 'title'}, {type: 'String', value: 'Hello, world!'}], - # TODO serialize Time, Date, DateTime types [{type: 'String', value: 'created_at'}, {type: 'Time', value: '2020-01-02T00:00:00Z'}], [{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}], ]}, @@ -126,7 +125,6 @@ def mysql_connection_string {type: 'Hash', entries: [ [{type: 'String', value: 'id'}, {type: 'Integer', value: '1'}], [{type: 'String', value: 'title'}, {type: 'String', value: 'Hello, world!'}], - # TODO serialize Time, Date, DateTime types [{type: 'String', value: 'created_at'}, {type: 'Time', value: '2020-01-02T00:00:00Z'}], [{type: 'String', value: 'updated_at'}, {type: 'Time', value: '2020-01-03T00:00:00Z'}], ]},