From 88a49aba2926df40d16c523df33bfac77596da6b Mon Sep 17 00:00:00 2001 From: Jing Li Date: Thu, 26 Feb 2015 15:05:17 -0800 Subject: [PATCH 1/2] Fix sdk version; Drop failed messages; --- lib/application_insights/channel/sender_base.rb | 9 --------- .../channel/telemetry_channel.rb | 3 ++- .../application_insights/channel/test_sender_base.rb | 2 +- .../channel/test_telemetry_channel.rb | 2 +- test/application_insights/test_telemetry_client.rb | 12 ++++++------ 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/application_insights/channel/sender_base.rb b/lib/application_insights/channel/sender_base.rb index 39c60c7..da7e3a3 100644 --- a/lib/application_insights/channel/sender_base.rb +++ b/lib/application_insights/channel/sender_base.rb @@ -55,15 +55,6 @@ module ApplicationInsights http.verify_mode = OpenSSL::SSL::VERIFY_NONE end response = http.request(request) - - case response - when Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPBadRequest - return - else - data_to_send.each do |item| - @queue.push item - end - end end private diff --git a/lib/application_insights/channel/telemetry_channel.rb b/lib/application_insights/channel/telemetry_channel.rb index 3b02b09..7474c02 100644 --- a/lib/application_insights/channel/telemetry_channel.rb +++ b/lib/application_insights/channel/telemetry_channel.rb @@ -7,6 +7,7 @@ require_relative 'synchronous_sender' require_relative 'contracts/envelope' require_relative 'contracts/data' require_relative 'contracts/internal' +require_relative '../../application_insights/version' module ApplicationInsights module Channel @@ -77,7 +78,7 @@ module ApplicationInsights def get_tags(context) hash = {} internal_context_attributes = { - :sdk_version => 'rb:0.1.0' + :sdk_version => 'rb:' + ApplicationInsights::VERSION } internal_context = Contracts::Internal.new internal_context_attributes contexts = [ internal_context, context.application, context.device, context.user, context.session, context.location, context.operation ] diff --git a/test/application_insights/channel/test_sender_base.rb b/test/application_insights/channel/test_sender_base.rb index eb5db2b..1b12dca 100644 --- a/test/application_insights/channel/test_sender_base.rb +++ b/test/application_insights/channel/test_sender_base.rb @@ -51,7 +51,7 @@ class TestSenderBase < Test::Unit::TestCase sender.queue = [] sender.send([1, 2]) thread.join - assert_equal [1, 2], sender.queue + assert_equal [], sender.queue end def execute_server(code) diff --git a/test/application_insights/channel/test_telemetry_channel.rb b/test/application_insights/channel/test_telemetry_channel.rb index 0bfa61e..aaaf5b4 100644 --- a/test/application_insights/channel/test_telemetry_channel.rb +++ b/test/application_insights/channel/test_telemetry_channel.rb @@ -66,7 +66,7 @@ class TestTelemetryChannel < Test::Unit::TestCase assert_equal 'instrumentation key', actual.i_key assert_not_nil actual.tags assert_equal 1, actual.tags.count - assert_equal 'rb:0.1.0', actual.tags['ai.internal.sdkVersion'] + assert_equal 'rb:'+ ApplicationInsights::VERSION, actual.tags['ai.internal.sdkVersion'] assert_not_nil actual.data assert_equal 'MockTelemetryItemData', actual.data.base_type assert_same expected, actual.data.base_data diff --git a/test/application_insights/test_telemetry_client.rb b/test/application_insights/test_telemetry_client.rb index e953bb9..9155af6 100644 --- a/test/application_insights/test_telemetry_client.rb +++ b/test/application_insights/test_telemetry_client.rb @@ -34,7 +34,7 @@ class TestTelemetryClient < Test::Unit::TestCase client, sender = self.create_client client.track_page_view 'test', 'http://tempuri.org' client.flush - expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.PageView","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"PageViewData","baseData":{"ver":2,"url":"http://tempuri.org","name":"test"}}}]' + expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.PageView","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:__version__"},"data":{"baseType":"PageViewData","baseData":{"ver":2,"url":"http://tempuri.org","name":"test"}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) sender.data_to_send[0].time = 'TIME_PLACEHOLDER' actual = sender.data_to_send.to_json assert_equal expected, actual @@ -48,7 +48,7 @@ class TestTelemetryClient < Test::Unit::TestCase client.track_exception e end client.flush - expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"ExceptionData","baseData":{"ver":2,"handledAt":"UserCode","exceptions":[{"id":1,"outerId":0,"typeName":"ArgumentError","message":"Some error","hasFullStack":true,"stack":"STACK_PLACEHOLDER"}]}}}]' + expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Exception","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:__version__"},"data":{"baseType":"ExceptionData","baseData":{"ver":2,"handledAt":"UserCode","exceptions":[{"id":1,"outerId":0,"typeName":"ArgumentError","message":"Some error","hasFullStack":true,"stack":"STACK_PLACEHOLDER"}]}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) assert_equal 'UserCode', sender.data_to_send[0].data.base_data.handled_at assert_operator sender.data_to_send[0].data.base_data.exceptions[0].parsed_stack.count, :>, 0 assert_equal 'test_track_exception_works_as_expected', sender.data_to_send[0].data.base_data.exceptions[0].parsed_stack[0].method @@ -64,7 +64,7 @@ class TestTelemetryClient < Test::Unit::TestCase client, sender = self.create_client client.track_event 'test' client.flush - expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Event","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"EventData","baseData":{"ver":2,"name":"test"}}}]' + expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Event","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:__version__"},"data":{"baseType":"EventData","baseData":{"ver":2,"name":"test"}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) sender.data_to_send[0].time = 'TIME_PLACEHOLDER' actual = sender.data_to_send.to_json assert_equal expected, actual @@ -74,7 +74,7 @@ class TestTelemetryClient < Test::Unit::TestCase client, sender = self.create_client client.track_metric 'test', 42 client.flush - expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Metric","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"MetricData","baseData":{"ver":2,"metrics":[{"name":"test","kind":1,"value":42}]}}}]' + expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Metric","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:__version__"},"data":{"baseType":"MetricData","baseData":{"ver":2,"metrics":[{"name":"test","kind":1,"value":42}]}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) sender.data_to_send[0].time = 'TIME_PLACEHOLDER' actual = sender.data_to_send.to_json assert_equal expected, actual @@ -84,7 +84,7 @@ class TestTelemetryClient < Test::Unit::TestCase client, sender = self.create_client client.track_trace 'test', Channel::Contracts::SeverityLevel::WARNING client.flush - expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"test","severityLevel":2}}}]' + expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Message","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:__version__"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"test","severityLevel":2}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) sender.data_to_send[0].time = 'TIME_PLACEHOLDER' actual = sender.data_to_send.to_json assert_equal expected, actual @@ -94,7 +94,7 @@ class TestTelemetryClient < Test::Unit::TestCase client, sender = self.create_client client.track_request 'test', '2015-01-24T23:10:22.7411910-08:00', '0:00:00:02.0000000','200', true client.flush - expected = '[{"ver":1,"name":"Microsoft.ApplicationInsights.Request","time":"TIME_PLACEHOLDER","sampleRate":100.0,"tags":{"ai.internal.sdkVersion":"rb:0.1.0"},"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":true}}}]' + 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":true}}}]'.gsub!(/__version__/, ApplicationInsights::VERSION) sender.data_to_send[0].time = 'TIME_PLACEHOLDER' actual = sender.data_to_send.to_json assert_equal expected, actual From 56d5791d72b09d7a697832c8c4f8abd7d90fe5ac Mon Sep 17 00:00:00 2001 From: Jing Li Date: Thu, 26 Feb 2015 17:40:05 -0800 Subject: [PATCH 2/2] increase gem version to 0.5.2 --- lib/application_insights/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/application_insights/version.rb b/lib/application_insights/version.rb index 82e5256..1fb305d 100644 --- a/lib/application_insights/version.rb +++ b/lib/application_insights/version.rb @@ -1,3 +1,3 @@ module ApplicationInsights - VERSION = '0.5.1' + VERSION = '0.5.2' end