application_insights 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +6 -14
  2. data/.travis.yml +21 -9
  3. data/CONTRIBUTING.md +30 -0
  4. data/Gemfile +4 -4
  5. data/LICENSE.txt +11 -11
  6. data/README.md +13 -14
  7. data/Rakefile +14 -14
  8. data/application_insights.gemspec +28 -29
  9. data/lib/application_insights.rb +9 -9
  10. data/lib/application_insights/channel/asynchronous_queue.rb +58 -51
  11. data/lib/application_insights/channel/asynchronous_sender.rb +132 -123
  12. data/lib/application_insights/channel/contracts/application.rb +14 -53
  13. data/lib/application_insights/channel/contracts/cloud.rb +14 -0
  14. data/lib/application_insights/channel/contracts/data.rb +14 -48
  15. data/lib/application_insights/channel/contracts/data_point.rb +24 -130
  16. data/lib/application_insights/channel/contracts/data_point_type.rb +7 -16
  17. data/lib/application_insights/channel/contracts/dependency_kind.rb +9 -19
  18. data/lib/application_insights/channel/contracts/dependency_source_type.rb +9 -19
  19. data/lib/application_insights/channel/contracts/device.rb +28 -257
  20. data/lib/application_insights/channel/contracts/envelope.rb +40 -266
  21. data/lib/application_insights/channel/contracts/event_data.rb +28 -77
  22. data/lib/application_insights/channel/contracts/exception_data.rb +37 -140
  23. data/lib/application_insights/channel/contracts/exception_details.rb +28 -129
  24. data/lib/application_insights/channel/contracts/internal.rb +14 -53
  25. data/lib/application_insights/channel/contracts/json_serializable.rb +59 -59
  26. data/lib/application_insights/channel/contracts/location.rb +16 -36
  27. data/lib/application_insights/channel/contracts/message_data.rb +24 -77
  28. data/lib/application_insights/channel/contracts/metric_data.rb +27 -60
  29. data/lib/application_insights/channel/contracts/operation.rb +19 -121
  30. data/lib/application_insights/channel/contracts/page_view_data.rb +30 -111
  31. data/lib/application_insights/channel/contracts/remote_dependency_data.rb +56 -260
  32. data/lib/application_insights/channel/contracts/request_data.rb +36 -176
  33. data/lib/application_insights/channel/contracts/session.rb +15 -70
  34. data/lib/application_insights/channel/contracts/severity_level.rb +13 -25
  35. data/lib/application_insights/channel/contracts/stack_frame.rb +17 -94
  36. data/lib/application_insights/channel/contracts/user.rb +19 -104
  37. data/lib/application_insights/channel/event.rb +68 -64
  38. data/lib/application_insights/channel/queue_base.rb +65 -62
  39. data/lib/application_insights/channel/sender_base.rb +79 -72
  40. data/lib/application_insights/channel/synchronous_queue.rb +45 -39
  41. data/lib/application_insights/channel/synchronous_sender.rb +17 -15
  42. data/lib/application_insights/channel/telemetry_channel.rb +120 -102
  43. data/lib/application_insights/channel/telemetry_context.rb +85 -68
  44. data/lib/application_insights/rack/track_request.rb +87 -84
  45. data/lib/application_insights/telemetry_client.rb +229 -217
  46. data/lib/application_insights/unhandled_exception.rb +49 -47
  47. data/lib/application_insights/version.rb +3 -3
  48. data/test/application_insights.rb +8 -9
  49. data/test/application_insights/channel/contracts/test_application.rb +44 -44
  50. data/test/application_insights/channel/contracts/test_cloud.rb +44 -0
  51. data/test/application_insights/channel/contracts/test_data.rb +44 -44
  52. data/test/application_insights/channel/contracts/test_data_point.rb +109 -109
  53. data/test/application_insights/channel/contracts/test_device.rb +200 -200
  54. data/test/application_insights/channel/contracts/test_envelope.rb +209 -209
  55. data/test/application_insights/channel/contracts/test_event_data.rb +62 -62
  56. data/test/application_insights/channel/contracts/test_exception_data.rb +111 -111
  57. data/test/application_insights/channel/contracts/test_exception_details.rb +106 -106
  58. data/test/application_insights/channel/contracts/test_internal.rb +44 -44
  59. data/test/application_insights/channel/contracts/test_location.rb +70 -31
  60. data/test/application_insights/channel/contracts/test_message_data.rb +66 -66
  61. data/test/application_insights/channel/contracts/test_metric_data.rb +50 -50
  62. data/test/application_insights/channel/contracts/test_operation.rb +109 -96
  63. data/test/application_insights/channel/contracts/test_page_view_data.rb +88 -88
  64. data/test/application_insights/channel/contracts/test_remote_dependency_data.rb +209 -209
  65. data/test/application_insights/channel/contracts/test_request_data.rb +153 -153
  66. data/test/application_insights/channel/contracts/test_session.rb +57 -57
  67. data/test/application_insights/channel/contracts/test_stack_frame.rb +83 -83
  68. data/test/application_insights/channel/contracts/test_user.rb +96 -83
  69. data/test/application_insights/channel/test_asynchronous_queue.rb +47 -47
  70. data/test/application_insights/channel/test_asynchronous_sender.rb +80 -80
  71. data/test/application_insights/channel/test_event.rb +52 -52
  72. data/test/application_insights/channel/test_queue_base.rb +88 -88
  73. data/test/application_insights/channel/test_sender_base.rb +87 -87
  74. data/test/application_insights/channel/test_synchronous_queue.rb +27 -27
  75. data/test/application_insights/channel/test_synchronous_sender.rb +10 -10
  76. data/test/application_insights/channel/test_telemetry_channel.rb +126 -102
  77. data/test/application_insights/channel/test_telemetry_context.rb +82 -74
  78. data/test/application_insights/mock_sender.rb +37 -37
  79. data/test/application_insights/rack/test_track_request.rb +142 -139
  80. data/test/application_insights/test_telemetry_client.rb +133 -123
  81. data/test/application_insights/test_unhandled_exception.rb +23 -24
  82. metadata +23 -33
@@ -1,129 +1,28 @@
1
- require_relative 'json_serializable'
2
-
3
- module ApplicationInsights
4
- module Channel
5
- module Contracts
6
- # Data contract class for type ExceptionDetails.
7
- class ExceptionDetails < JsonSerializable
8
- # Initializes a new instance of the ExceptionDetails class.
9
- def initialize(options={})
10
- defaults = {
11
- 'id' => nil,
12
- 'outerId' => nil,
13
- 'typeName' => nil,
14
- 'message' => nil,
15
- 'hasFullStack' => true,
16
- 'stack' => nil,
17
- 'parsedStack' => []
18
- }
19
- values = {
20
- 'typeName' => nil,
21
- 'message' => nil,
22
- 'hasFullStack' => true
23
- }
24
- super defaults, values, options
25
- end
26
-
27
- # Gets the id property.
28
- def id
29
- @values.fetch('id') {
30
- @values['id'] = nil
31
- }
32
- end
33
-
34
- # Sets the id property.
35
- def id=(value)
36
- if value == @defaults['id']
37
- @values.delete 'id' if @values.key? 'id'
38
- else
39
- @values['id'] = value
40
- end
41
- end
42
-
43
- # Gets the outer_id property.
44
- def outer_id
45
- @values.fetch('outerId') {
46
- @values['outerId'] = nil
47
- }
48
- end
49
-
50
- # Sets the outer_id property.
51
- def outer_id=(value)
52
- if value == @defaults['outerId']
53
- @values.delete 'outerId' if @values.key? 'outerId'
54
- else
55
- @values['outerId'] = value
56
- end
57
- end
58
-
59
- # Gets the type_name property.
60
- def type_name
61
- @values['typeName']
62
- end
63
-
64
- # Sets the type_name property.
65
- def type_name=(value)
66
- @values['typeName'] = value
67
- end
68
-
69
- # Gets the message property.
70
- def message
71
- @values['message']
72
- end
73
-
74
- # Sets the message property.
75
- def message=(value)
76
- @values['message'] = value
77
- end
78
-
79
- # Gets the has_full_stack property.
80
- def has_full_stack
81
- @values.fetch('hasFullStack') {
82
- @values['hasFullStack'] = true
83
- }
84
- end
85
-
86
- # Sets the has_full_stack property.
87
- def has_full_stack=(value)
88
- if value == @defaults['hasFullStack']
89
- @values.delete 'hasFullStack' if @values.key? 'hasFullStack'
90
- else
91
- @values['hasFullStack'] = value
92
- end
93
- end
94
-
95
- # Gets the stack property.
96
- def stack
97
- @values.fetch('stack') {
98
- @values['stack'] = nil
99
- }
100
- end
101
-
102
- # Sets the stack property.
103
- def stack=(value)
104
- if value == @defaults['stack']
105
- @values.delete 'stack' if @values.key? 'stack'
106
- else
107
- @values['stack'] = value
108
- end
109
- end
110
-
111
- # Gets the parsed_stack property.
112
- def parsed_stack
113
- @values.fetch('parsedStack') {
114
- @values['parsedStack'] = []
115
- }
116
- end
117
-
118
- # Sets the parsed_stack property.
119
- def parsed_stack=(value)
120
- if value == @defaults['parsedStack']
121
- @values.delete 'parsedStack' if @values.key? 'parsedStack'
122
- else
123
- @values['parsedStack'] = value
124
- end
125
- end
126
- end
127
- end
128
- end
129
- end
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class ExceptionDetails
5
+ include JsonSerializable
6
+
7
+ attr_accessor :id, :outer_id, :type_name, :message, :has_full_stack, :stack,
8
+ :parsed_stack
9
+
10
+ attribute_mapping(
11
+ id: 'id',
12
+ outer_id: 'outerId',
13
+ type_name: 'typeName',
14
+ message: 'message',
15
+ has_full_stack: 'hasFullStack',
16
+ stack: 'stack',
17
+ parsed_stack: 'parsedStack'
18
+ )
19
+
20
+ def has_full_stack
21
+ @has_full_stack.nil? ? true : @has_full_stack
22
+ end
23
+
24
+ def parsed_stack
25
+ @parsed_stack ||= []
26
+ end
27
+ end
28
+ end
@@ -1,53 +1,14 @@
1
- require_relative 'json_serializable'
2
-
3
- module ApplicationInsights
4
- module Channel
5
- module Contracts
6
- # Data contract class for type Internal.
7
- class Internal < JsonSerializable
8
- # Initializes a new instance of the Internal class.
9
- def initialize(options={})
10
- defaults = {
11
- 'ai.internal.sdkVersion' => nil,
12
- 'ai.internal.agentVersion' => nil
13
- }
14
- values = {
15
- }
16
- super defaults, values, options
17
- end
18
-
19
- # Gets the sdk_version property.
20
- def sdk_version
21
- @values.fetch('ai.internal.sdkVersion') {
22
- @values['ai.internal.sdkVersion'] = nil
23
- }
24
- end
25
-
26
- # Sets the sdk_version property.
27
- def sdk_version=(value)
28
- if value == @defaults['ai.internal.sdkVersion']
29
- @values.delete 'ai.internal.sdkVersion' if @values.key? 'ai.internal.sdkVersion'
30
- else
31
- @values['ai.internal.sdkVersion'] = value
32
- end
33
- end
34
-
35
- # Gets the agent_version property.
36
- def agent_version
37
- @values.fetch('ai.internal.agentVersion') {
38
- @values['ai.internal.agentVersion'] = nil
39
- }
40
- end
41
-
42
- # Sets the agent_version property.
43
- def agent_version=(value)
44
- if value == @defaults['ai.internal.agentVersion']
45
- @values.delete 'ai.internal.agentVersion' if @values.key? 'ai.internal.agentVersion'
46
- else
47
- @values['ai.internal.agentVersion'] = value
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Internal
5
+ include JsonSerializable
6
+
7
+ attr_accessor :sdk_version, :agent_version
8
+
9
+ attribute_mapping(
10
+ sdk_version: 'ai.internal.sdkVersion',
11
+ agent_version: 'ai.internal.agentVersion'
12
+ )
13
+ end
14
+ end
@@ -1,59 +1,59 @@
1
- require 'json'
2
-
3
- module ApplicationInsights
4
- module Channel
5
- module Contracts
6
- class JsonSerializable
7
- def initialize(defaults, values, options)
8
- @defaults = defaults
9
- @values = values
10
- if options != nil
11
- options.each do |key, value|
12
- self.send key.to_s + '=', value
13
- end
14
- end
15
- end
16
-
17
- def to_h
18
- output = {}
19
- @defaults.each do |key, default|
20
- if @values.key? key
21
- value = @values[key]
22
- value = default if value == nil
23
- elsif default
24
- value = default
25
- else
26
- next
27
- end
28
-
29
- if value.class == Array
30
- value_copy = []
31
- value.each do |item|
32
- item.respond_to?(:to_h) ? value_copy.push(item.to_h) : value_copy.push(item)
33
- end
34
- output[key] = value_copy if value_copy.length > 0
35
- elsif value.class == Hash
36
- value_copy = {}
37
- value.each do |item_key, item_value|
38
- (item_value.respond_to? :to_h) ? value_copy[item_key] = item_value.to_h : value_copy[item_key] = item_value
39
- end
40
- output[key] = value_copy if value_copy.length > 0
41
- elsif value.respond_to? :to_h
42
- value_copy = value.to_h
43
- output[key] = value_copy if value_copy.length > 0
44
- else
45
- output[key] = value
46
- end
47
- end
48
- output
49
- end
50
-
51
- def to_json(*)
52
- hash = self.to_h
53
- hash.to_json
54
- end
55
- end
56
- end
57
- end
58
- end
59
-
1
+ require 'json'
2
+
3
+ module ApplicationInsights
4
+ module Channel
5
+ module Contracts
6
+ module JsonSerializable
7
+ module ClassMethods
8
+ attr_reader :json_mappings
9
+
10
+ def attribute_mapping(mappings)
11
+ @json_mappings = mappings
12
+ end
13
+ end
14
+
15
+ def self.included(klass)
16
+ klass.extend JsonSerializable::ClassMethods
17
+ end
18
+
19
+ def initialize(attributes = {})
20
+ attributes.each { |k, v| send(:"#{k}=", v) }
21
+ end
22
+
23
+ def to_h
24
+ output = {}
25
+ klass = self.class
26
+
27
+ klass.json_mappings.each do |attr, name|
28
+ value = visit self.send(attr)
29
+ is_empty = value.respond_to?(:empty?) && value.empty?
30
+
31
+ output[name] = value unless value.nil? || is_empty
32
+ end
33
+
34
+ output
35
+ end
36
+
37
+ def to_json(args = {})
38
+ JSON.generate self.to_h, args
39
+ end
40
+
41
+ private
42
+
43
+ def visit(object)
44
+ return if object.nil?
45
+
46
+ if object.is_a? Array
47
+ object.map { |e| visit e }
48
+ elsif object.is_a? Hash
49
+ Hash[object.map { |k, v| [k, visit(v)] }]
50
+ elsif object.respond_to? :to_h
51
+ object.to_h
52
+ else
53
+ object
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,36 +1,16 @@
1
- require_relative 'json_serializable'
2
-
3
- module ApplicationInsights
4
- module Channel
5
- module Contracts
6
- # Data contract class for type Location.
7
- class Location < JsonSerializable
8
- # Initializes a new instance of the Location class.
9
- def initialize(options={})
10
- defaults = {
11
- 'ai.location.ip' => nil
12
- }
13
- values = {
14
- }
15
- super defaults, values, options
16
- end
17
-
18
- # Gets the ip property.
19
- def ip
20
- @values.fetch('ai.location.ip') {
21
- @values['ai.location.ip'] = nil
22
- }
23
- end
24
-
25
- # Sets the ip property.
26
- def ip=(value)
27
- if value == @defaults['ai.location.ip']
28
- @values.delete 'ai.location.ip' if @values.key? 'ai.location.ip'
29
- else
30
- @values['ai.location.ip'] = value
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Location
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ip, :country, :province, :city
8
+
9
+ attribute_mapping(
10
+ ip: 'ai.location.ip',
11
+ country: 'ai.location.country',
12
+ province: 'ai.location.province',
13
+ city: 'ai.location.city'
14
+ )
15
+ end
16
+ end
@@ -1,77 +1,24 @@
1
- require_relative 'json_serializable'
2
-
3
- module ApplicationInsights
4
- module Channel
5
- module Contracts
6
- # Data contract class for type MessageData.
7
- class MessageData < JsonSerializable
8
- # Initializes a new instance of the MessageData class.
9
- def initialize(options={})
10
- defaults = {
11
- 'ver' => 2,
12
- 'message' => nil,
13
- 'severityLevel' => nil,
14
- 'properties' => {}
15
- }
16
- values = {
17
- 'ver' => 2,
18
- 'message' => nil
19
- }
20
- super defaults, values, options
21
- end
22
-
23
- # Gets the ver property.
24
- def ver
25
- @values['ver']
26
- end
27
-
28
- # Sets the ver property.
29
- def ver=(value)
30
- @values['ver'] = value
31
- end
32
-
33
- # Gets the message property.
34
- def message
35
- @values['message']
36
- end
37
-
38
- # Sets the message property.
39
- def message=(value)
40
- @values['message'] = value
41
- end
42
-
43
- # Gets the severity_level property.
44
- def severity_level
45
- @values.fetch('severityLevel') {
46
- @values['severityLevel'] = nil
47
- }
48
- end
49
-
50
- # Sets the severity_level property.
51
- def severity_level=(value)
52
- if value == @defaults['severityLevel']
53
- @values.delete 'severityLevel' if @values.key? 'severityLevel'
54
- else
55
- @values['severityLevel'] = value
56
- end
57
- end
58
-
59
- # Gets the properties property.
60
- def properties
61
- @values.fetch('properties') {
62
- @values['properties'] = {}
63
- }
64
- end
65
-
66
- # Sets the properties property.
67
- def properties=(value)
68
- if value == @defaults['properties']
69
- @values.delete 'properties' if @values.key? 'properties'
70
- else
71
- @values['properties'] = value
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class MessageData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :message, :severity_level, :properties
8
+
9
+ attribute_mapping(
10
+ ver: 'ver',
11
+ message: 'message',
12
+ severity_level: 'severityLevel',
13
+ properties: 'properties'
14
+ )
15
+
16
+ def ver
17
+ @ver ||= 2
18
+ end
19
+
20
+ def properties
21
+ @properties ||= {}
22
+ end
23
+ end
24
+ end