From 33bf3c572c8950c44e1722154f9ee42177baea50 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 5 Dec 2024 12:59:15 +0000 Subject: [PATCH] Log deserialization errors in MockApmServer --- .../Controllers/IntakeV2EventsController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/Elastic.Apm.Tests.MockApmServer/Controllers/IntakeV2EventsController.cs b/test/Elastic.Apm.Tests.MockApmServer/Controllers/IntakeV2EventsController.cs index 5f93d950b..dce2a7f2d 100644 --- a/test/Elastic.Apm.Tests.MockApmServer/Controllers/IntakeV2EventsController.cs +++ b/test/Elastic.Apm.Tests.MockApmServer/Controllers/IntakeV2EventsController.cs @@ -107,8 +107,18 @@ private async Task ParsePayload() private async Task ParsePayloadLineAndAddToReceivedData(string line) { var foundDto = false; - var payload = JsonSerializer - .Deserialize(line, JsonSerializerOptions) ?? throw new ArgumentException("Deserialization failed"); + + PayloadLineDto payload; + try + { + payload = JsonSerializer.Deserialize(line, JsonSerializerOptions) + ?? throw new ArgumentException("Deserialization failed"); + } + catch (JsonException ex) + { + _logger?.Error()?.LogException(ex, "Failed to deserialize '{Line}'", line); + throw; + } await HandleParsed(nameof(payload.Error), payload.Error, _mockApmServer.ReceivedData.Errors, _mockApmServer.AddError); await HandleParsed(nameof(payload.Metadata), payload.Metadata, _mockApmServer.ReceivedData.Metadata, _mockApmServer.AddMetadata);