fluent-plugin-application-insights 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16cd7a0fed351fcf6f1c5c9030454658ea2bb1e6
4
- data.tar.gz: '08af822420fb65b336283d29cd4fb23800aa3b10'
3
+ metadata.gz: fccdd3499c752fcd05f6dd4706e8e155b918ec7d
4
+ data.tar.gz: '07914eb737903feb35c708d8307162eb9f7aea05'
5
5
  SHA512:
6
- metadata.gz: 73ff2242c21c5be630d7a10e15e406e9f517856261be253fa055fcd02dc66674b0f4d42882676d0612f17fef820612fccc5a22f2507675b6e68122c047b64071
7
- data.tar.gz: e0933edfcbd3ff4f4c56185a166f506ddf47e7e74d107acb3f72051484f18546f2c943c8f0242e42b6af05232d1e4b3b04b536147a79d06522baab8f89f75f38
6
+ metadata.gz: 3b08ba753839bf9588a377085b8494644c1fdb9c69eeb2c0d6467b60f205f7982324902e949de4f11c3a52e8d3a614b7d3b901eede5c54327a9f2bc71e81c193
7
+ data.tar.gz: 0efaa1e0a4f3b9d3e4fec263e493de73e803e7174665602c9a70982d8d1c89ca2fa4e73932a25cbc7179ad30e1bb838624a0a41361643d7155809453eaf88559
data/README.md CHANGED
@@ -56,7 +56,7 @@ If the record is not in standard schema, it will be tracked as Application Insig
56
56
 
57
57
  The standard schema for Application Insights telemetry is defined [here](https://github.com/Microsoft/ApplicationInsights-Home/tree/master/EndpointSpecs/Schemas/Bond).
58
58
 
59
- Below is an example of a Request telemetry in standard schema format. `name`, `time`, `data`, `data.baseType` and `data.baseData` are required properties. Different telemetry types will have different properties associated with the `baseData` object.
59
+ Below is an example of a Request telemetry in standard schema format. `data`, `data.baseType` and `data.baseData` are required properties. Different telemetry types will have different properties associated with the `baseData` object.
60
60
 
61
61
  ```
62
62
  {
@@ -3,9 +3,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-application-insights"
6
- spec.version = "0.2.1"
6
+ spec.version = "0.2.2"
7
7
  spec.authors = ["Microsoft Corporation"]
8
- spec.email = ["ctdiagcore@microsoft.com"]
8
+ spec.email = ["azure-tools@microsoft.com"]
9
9
 
10
10
  spec.summary = "This is the fluentd output plugin for Azure Application Insights."
11
11
  spec.description = "Fluentd output plugin for Azure Application Insights."
@@ -26,15 +26,15 @@ module Fluent::Plugin
26
26
  # The property name for severity level. It will be ignored if the record is in standard schema.
27
27
  config_param :severity_property, :string, default: 'severity'
28
28
  # The value of severity property that maps to Application Insights' verbose severity level.
29
- config_param :severity_level_verbose, :string, default: 'verbose'
29
+ config_param :severity_level_verbose, :array, value_type: :string, default: ['verbose']
30
30
  # The value of severity property that maps to Application Insights' information severity level.
31
- config_param :severity_level_information, :string, default: 'information'
31
+ config_param :severity_level_information, :array, value_type: :string, default: ['information']
32
32
  # The value of severity property that maps to Application Insights' warning severity level.
33
- config_param :severity_level_warning, :string, default: 'warning'
33
+ config_param :severity_level_warning, :array, value_type: :string, default: ['warning']
34
34
  # The value of severity property that maps to Application Insights' error severity level.
35
- config_param :severity_level_error, :string, default: 'error'
35
+ config_param :severity_level_error, :array, value_type: :string, default: ['error']
36
36
  # The value of severity property that maps to Application Insights' critical severity level.
37
- config_param :severity_level_critical, :string, default: 'critical'
37
+ config_param :severity_level_critical, :array, value_type: :string, default: ['critical']
38
38
  # The dictionary that instructs the Application Insights plugin to set Application Insights context tags using record properties.
39
39
  # In this dictionary keys are Application Insights context tags to set, and values are names of properties to use as source of data.
40
40
  config_param :context_tag_sources, :hash, default: {}, value_type: :string
@@ -45,11 +45,11 @@ module Fluent::Plugin
45
45
  super
46
46
 
47
47
  @severity_level_mapping = {}
48
- @severity_level_mapping[@severity_level_verbose.downcase] = Channel::Contracts::SeverityLevel::VERBOSE
49
- @severity_level_mapping[@severity_level_information.downcase] = Channel::Contracts::SeverityLevel::INFORMATION
50
- @severity_level_mapping[@severity_level_warning.downcase] = Channel::Contracts::SeverityLevel::WARNING
51
- @severity_level_mapping[@severity_level_error.downcase] = Channel::Contracts::SeverityLevel::ERROR
52
- @severity_level_mapping[@severity_level_critical.downcase] = Channel::Contracts::SeverityLevel::CRITICAL
48
+ @severity_level_verbose.each { |l| @severity_level_mapping[l.downcase] = Channel::Contracts::SeverityLevel::VERBOSE }
49
+ @severity_level_information.each { |l| @severity_level_mapping[l.downcase] = Channel::Contracts::SeverityLevel::INFORMATION }
50
+ @severity_level_warning.each { |l| @severity_level_mapping[l.downcase] = Channel::Contracts::SeverityLevel::WARNING }
51
+ @severity_level_error.each { |l| @severity_level_mapping[l.downcase] = Channel::Contracts::SeverityLevel::ERROR }
52
+ @severity_level_critical.each { |l| @severity_level_mapping[l.downcase] = Channel::Contracts::SeverityLevel::CRITICAL }
53
53
 
54
54
  context_tag_keys = []
55
55
  context_tag_keys.concat Channel::Contracts::Application.json_mappings.values
@@ -112,13 +112,14 @@ module Fluent::Plugin
112
112
  end
113
113
 
114
114
  def process_standard_schema_log(record, time)
115
- if record["name"] && record["data"] && record["data"].is_a?(Hash) && record["data"]["baseType"] && record["data"]["baseData"]
115
+ if record["data"] && record["data"].is_a?(Hash) && record["data"]["baseType"] && record["data"]["baseData"]
116
116
  base_type = record["data"]["baseType"]
117
117
 
118
118
  if TELEMETRY_TYPES.include? base_type
119
119
  # If the record is processed by json parser plugin, e.g., in_http use it by default, the time property will be removed. Add it back in this case.
120
120
  record["time"] ||= time.iso8601(7)
121
121
  record["iKey"] = @instrumentation_key
122
+ set_name_property(record) if !record["name"]
122
123
  set_context_standard_schema record
123
124
 
124
125
  envelope = Channel::Contracts::Envelope.new
@@ -132,15 +133,22 @@ module Fluent::Plugin
132
133
 
133
134
  @tc.channel.queue.push(envelope)
134
135
  else
135
- log.warn "Unknown telemetry type #{base_type}. Event will be treated as as non standard schema event."
136
+ log.debug "Unknown telemetry type #{base_type}. Event will be treated as as non standard schema event."
136
137
  process_non_standard_schema_log record, time
137
138
  end
138
139
  else
139
- log.warn "The event does not meet the standard schema of Application Insights output. Missing name, data, baseType or baseData property. Event will be treated as as non standard schema event."
140
+ log.debug "The event does not meet the standard schema of Application Insights output. Missing data, baseType or baseData property. Event will be treated as as non standard schema event."
140
141
  process_non_standard_schema_log record, time
141
142
  end
142
143
  end
143
144
 
145
+ def set_name_property(record)
146
+ normalizedIKey = @instrumentation_key.gsub("-", "")
147
+ normalizedIKey = normalizedIKey.empty? ? "" : normalizedIKey + "."
148
+ type = record["data"]["baseType"][0..-5]
149
+ record["name"] = "Microsoft.ApplicationInsights.#{normalizedIKey}#{type}"
150
+ end
151
+
144
152
  def set_context_standard_schema(record)
145
153
  return if @context_tag_sources.length == 0
146
154
 
@@ -58,28 +58,66 @@ class ApplicationInsightsOutputTest < Test::Unit::TestCase
58
58
 
59
59
  test 'event missing required properties is treated as non standard schema' do
60
60
  time = event_time("2011-01-02 13:14:15 UTC")
61
+ @d.instance.log.level = "debug"
61
62
  @d.run(default_tag: 'test', shutdown: false) do
62
- @d.feed(time, {"data" => {"baseType" => "RequestData", "baseData" => "data"}})
63
- @d.feed(time, {"name" => "telemetry name"})
64
- @d.feed(time, {"name" => "telemetry name", "data" => 2})
65
- @d.feed(time, {"name" => "telemetry name", "data" => {}})
66
- @d.feed(time, {"name" => "telemetry name", "data" => {"someprop" => "value"}})
67
- @d.feed(time, {"name" => "telemetry name", "data" => {"baseType" => "type"}})
68
- @d.feed(time, {"name" => "telemetry name", "data" => {"baseData" => "data"}})
63
+ @d.feed(time, {})
64
+ @d.feed(time, {"data" => 2})
65
+ @d.feed(time, {"data" => {}})
66
+ @d.feed(time, {"data" => {"someprop" => "value"}})
67
+ @d.feed(time, {"data" => {"baseType" => "type"}})
68
+ @d.feed(time, {"data" => {"baseData" => "data"}})
69
69
  end
70
70
 
71
71
  logs = @d.instance.log.out.logs
72
- assert_equal 7, logs.length
73
- assert_true logs.all?{ |log| log.include?("The event does not meet the standard schema of Application Insights output. Missing name, data, baseType or baseData property.") }
72
+ assert_equal 6, logs.length
73
+ assert_true logs.all?{ |log| log.include?("The event does not meet the standard schema of Application Insights output. Missing data, baseType or baseData property.") }
74
+ end
75
+
76
+ test 'event of standard schema will fill in the name property if it is empty' do
77
+ config = %[
78
+ instrumentation_key 000-000-000
79
+ standard_schema true
80
+ ]
81
+ d = create_driver config
82
+
83
+ time = event_time("2011-01-02 13:14:15 UTC")
84
+ d.run(default_tag: 'test', shutdown: false) do
85
+ d.feed(time, {
86
+ "data" => { "baseType" => "RequestData", "baseData" => {} }
87
+ })
88
+ end
89
+
90
+ envelope = d.instance.tc.channel.queue[0]
91
+ assert_equal "Microsoft.ApplicationInsights.000000000.Request", envelope.name
92
+ end
93
+
94
+ test 'event of standard schema will fill in the name property if it is empty and instrumentation key is empty' do
95
+ config = %[
96
+ instrumentation_key ""
97
+ standard_schema true
98
+ ]
99
+ d = create_driver config
100
+
101
+ time = event_time("2011-01-02 13:14:15 UTC")
102
+ d.run(default_tag: 'test', shutdown: false) do
103
+ d.feed(time, {
104
+ "data" => { "baseType" => "RequestData", "baseData" => {} }
105
+ })
106
+ end
107
+
108
+ envelope = d.instance.tc.channel.queue[0]
109
+ assert_equal "Microsoft.ApplicationInsights.Request", envelope.name
74
110
  end
75
111
 
76
112
  test 'event with unknown data type is treated as non standard schema' do
77
113
  time = event_time("2011-01-02 13:14:15 UTC")
114
+ @d.instance.log.level = "debug"
78
115
  @d.run(default_tag: 'test', shutdown: false) do
79
116
  @d.feed(time, {"name" => "telemetry name", "data" => {"baseType" => "unknown", "baseData" => {}}})
80
117
  end
81
118
 
82
119
  logs = @d.instance.log.out.logs
120
+ assert_true logs.length > 0
83
121
  assert_true logs.all?{ |log| log.include?("Unknown telemetry type unknown") }
84
122
  end
85
123
 
@@ -317,6 +355,37 @@ class ApplicationInsightsOutputTest < Test::Unit::TestCase
317
355
  assert_equal ApplicationInsights::Channel::Contracts::SeverityLevel::ERROR, envelope.data.base_data.severity_level
318
356
  end
319
357
 
358
+ test 'multiple severity levels' do
359
+ config = %[
360
+ instrumentation_key ikey
361
+ severity_property custom_severity_property
362
+ severity_level_critical fatal, panic
363
+ ]
364
+ d = create_driver config
365
+
366
+ time = event_time("2011-01-02 13:14:15 UTC")
367
+ d.run(default_tag: 'test', shutdown: false) do
368
+ d.feed(time, {"custom_severity_property" => "panic", "message" => "my message"})
369
+ end
370
+
371
+ d.run(default_tag: 'test', shutdown: false) do
372
+ d.feed(time, {"custom_severity_property" => "fatal", "message" => "my message"})
373
+ end
374
+
375
+ d.run(default_tag: 'test', shutdown: false) do
376
+ d.feed(time, {"custom_severity_property" => "critical", "message" => "my message"})
377
+ end
378
+
379
+ envelope = d.instance.tc.channel.queue[0]
380
+ assert_equal ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL, envelope.data.base_data.severity_level
381
+
382
+ envelope = d.instance.tc.channel.queue[1]
383
+ assert_equal ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL, envelope.data.base_data.severity_level
384
+
385
+ envelope = d.instance.tc.channel.queue[2]
386
+ assert_not_equal ApplicationInsights::Channel::Contracts::SeverityLevel::CRITICAL, envelope.data.base_data.severity_level
387
+ end
388
+
320
389
  test 'properties are stringified' do
321
390
  d = create_driver
322
391
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-application-insights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: 0.5.5
89
89
  description: Fluentd output plugin for Azure Application Insights.
90
90
  email:
91
- - ctdiagcore@microsoft.com
91
+ - azure-tools@microsoft.com
92
92
  executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []