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..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 @@ -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: -> { @@ -101,10 +107,30 @@ 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'}], ]}, + ], [ + {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!'}], + [{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'}, ]]}}, ]