From a60f44793bdfcdb0d02f4b685229aac92bcc0724 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 5 Jul 2017 16:09:02 +0200 Subject: [PATCH] When a failed request is sent, the "success" field is set to "false" and this causes the field is omitted from the JSON. The backed does not accept the message because the "success" field is missing though. Updating to include fields in the JSON even when they are false. --- .../channel/contracts/json_serializable.rb | 2 +- test/application_insights/test_telemetry_client.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/application_insights/channel/contracts/json_serializable.rb b/lib/application_insights/channel/contracts/json_serializable.rb index 22c1414..fb8b29c 100644 --- a/lib/application_insights/channel/contracts/json_serializable.rb +++ b/lib/application_insights/channel/contracts/json_serializable.rb @@ -41,7 +41,7 @@ module ApplicationInsights private def visit(object) - return unless object + return if object.nil? if object.is_a? Array object.map { |e| visit e } diff --git a/test/application_insights/test_telemetry_client.rb b/test/application_insights/test_telemetry_client.rb index 9155af6..1356ad4 100644 --- a/test/application_insights/test_telemetry_client.rb +++ b/test/application_insights/test_telemetry_client.rb @@ -100,6 +100,16 @@ class TestTelemetryClient < Test::Unit::TestCase assert_equal expected, actual end + def test_track_request_view_works_as_expected_when_request_is_failed + client, sender = self.create_client + client.track_request 'test', '2015-01-24T23:10:22.7411910-08:00', '0:00:00:02.0000000','200', false + client.flush + expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Request","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:__version__"},"data":{"baseType":"RequestData","baseData":{"ver":2,"id":"test","startTime":"2015-01-24T23:10:22.7411910-08:00","duration":"0:00:00:02.0000000","responseCode":"200","success":false}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) + sender.data_to_send[0].time = 'TIME_PLACEHOLDER' + actual = sender.data_to_send.to_json + assert_equal expected, actual + end + def create_client sender = MockTelemetryClientSender.new queue = Channel::SynchronousQueue.new sender