fluent-plugin-application-insights 0.1.0 → 0.2.0

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: f77dfcd3f36125b8dc0a3fd720db0c4303274c54
4
- data.tar.gz: 3129c6bc54acac8cbfb71fe821e5e3675f35728a
3
+ metadata.gz: bfa9d92dcee9f67b521133f83b7381e1a73d6b35
4
+ data.tar.gz: c8a69e7f304425e4f915dd17e8ad979399333af9
5
5
  SHA512:
6
- metadata.gz: da8c5a97877de1e48c507c586fbb352dfd7aa9a0e092edb4a9d883a1f07d861fa64e953c6761030bbb0a5b6ffa58230755194ade69443eb6b6798700dc3d4318
7
- data.tar.gz: 49d85bf6fc2822ebf417ca85536d501be120f887e517dd3aff44fc1d454a6abe70042059db5010bfda1ae7a7711f3d6aeff3f2cd5a66d2fb30bd0174fd777bb7
6
+ metadata.gz: 6794875d0ae52ea3f9d97da680958902c20dd187471312d6332b889148c7c00f0c20102b5f6e75ba4532a0ab282e12c95bfb188410abc4de70fcb8816c3566a8
7
+ data.tar.gz: ed67f84b150d180cbb43e6301c93b9031a004f4515184203575f3678190f98967be764ba44ee0bef15e7e24a97ce1591b46ba5fcdac27035a9c20a80e4a02df4
@@ -0,0 +1,33 @@
1
+ # Development
2
+ ## Build Gem
3
+ Run ```gem build fluent-plugin-application-insights.gemspec```.
4
+
5
+ ## Run Test
6
+ Make sure you have bundler installed, you can install it by ```sudo gem install bundler```. And run ```bundler install``` once to install all dependencies.
7
+
8
+ Run ```rake test```.
9
+
10
+ ## Release
11
+ If you are the current maintainer of this plugin:
12
+ 1. Ensure all tests passed
13
+ 2. Bump up version in ```fluent-plugin-application-insights.gemspec```
14
+ 3. Build the gem, install it locally and test it
15
+ 4. Create a PR with whatever changes needed before releasing, e.g., version bump up, documentation
16
+ 5. Tag and push: ```git tag vx.xx.xx; git push --tags```
17
+ 6. Create a github release with the pushed tag
18
+ 7. Push to rubygems.org: ```gem push fluent-plugin-application-insights-<version>.gem```
19
+
20
+ # Contributing
21
+
22
+ This project welcomes contributions and suggestions. Most contributions require you to
23
+ agree to a Contributor License Agreement (CLA) declaring that you have the right to,
24
+ and actually do, grant us the rights to use your contribution. For details, visit
25
+ https://cla.microsoft.com.
26
+
27
+ When you submit a pull request, a CLA-bot will automatically determine whether you need
28
+ to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
29
+ instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
30
+
31
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
32
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
33
+ or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # fluent-plugin-application-insights
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-application-insights.svg)](https://badge.fury.io/rb/fluent-plugin-application-insights)
4
+ [![Build Status](https://travis-ci.org/Microsoft/fluent-plugin-application-insights.svg?branch=master)](https://travis-ci.org/Microsoft/fluent-plugin-application-insights)
5
+
2
6
  This is the [Fluentd](https://fluentd.org/) output plugin for [Azure Application Insights](https://docs.microsoft.com/azure/application-insights/)
3
7
 
4
8
  Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms.
@@ -30,18 +34,20 @@ Here is the configuration options for this plugin:
30
34
  * `standard_schema` - The parameter indicating whether the record is in standard schema. i.e., the format that is recognized by Application Insights backend (default `false`).
31
35
  If the record is not in standard schema, it will be tracked as Application Insights trace telemetry. Otherwise, the record is just forwarded to the backend. See [Standard Schema](#standard-schema) for more info.
32
36
  * `message_property` - The property name for the trace message (default `message`).
33
- * `time_property` - The property name for the timestamp (default `nil`). Fluentd input plugin will assign a timestamp for each emitted record, and this timestamp is used as the telemetry creation time by default. Set the `time_property` if you want to use the value of this property instead of the one assigned by the input plugin.
37
+ * `time_property` - The property name for the timestamp (default `nil`).
38
+ Fluentd input plugin will assign a timestamp for each emitted record, and this timestamp is used as the telemetry creation time by default. Set the `time_property` if you want to use the value of this property instead of the one assigned by the input plugin.
34
39
  * `severity_property` - The property name for severity level (default `severity`). If the severity property doesn't exist, the record will be treated as information level. See [Severity Level](https://docs.microsoft.com/azure/application-insights/application-insights-data-model-trace-telemetry#severity-level) for more info.
35
40
  * `severity_level_verbose` - The value of severity property that maps to Application Insights' verbose severity level (default `verbose`).
36
41
  * `severity_level_information` - The value of severity property that maps to Application Insights' information severity level (default `information`).
37
42
  * `severity_level_warning` - The value of severity property that maps to Application Insights' warning severity level (default `warning`).
38
43
  * `severity_level_error` - The value of severity property that maps to Application Insights' error severity level (default `error`).
39
44
  * `severity_level_critical` - The value of severity property that maps to Application Insights' critical severity level (default `critical`).
40
- * `context_tag_sources` - The dictionary that instructs the Application Insights plugin to set Application Insights context tags using record properties. In this dictionary keys are Application Insights context tags to set, and values are names of properties to use as source of data. For example:
45
+ * `context_tag_sources` - The dictionary that instructs the Application Insights plugin to set Application Insights context tags using record properties.
46
+ In this dictionary keys are Application Insights context tags to set, and values are the source properties that are used to set the context tags value. For the source property, you can specify the property name or jsonpath like syntax for nested property, see [record_accessor syntax](https://docs.fluentd.org/v1.0/articles/api-plugin-helper-record_accessor#syntax) for more info. For example:
41
47
  ```
42
48
  context_tag_sources {
43
49
  "ai.cloud.role": "kubernetes_container_name",
44
- "ai.cloud.roleInstance": "kubernetes_pod_name"
50
+ "ai.cloud.roleInstance": "$.docker.container_id"
45
51
  }
46
52
  ```
47
53
  Here is the list of all [context tag keys](https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/Schema/PublicSchema/ContextTagKeys.bond)
@@ -74,36 +80,9 @@ Below is an example of a Request telemetry in standard schema format. `name`, `t
74
80
  }
75
81
  ```
76
82
 
77
- ## Development
78
- ### Build Gem
79
- Run ```gem build fluent-plugin-application-insights.gemspec```.
80
-
81
- ### Run Test
82
- Make sure you have bundler installed, you can install it by ```sudo gem install bundler```. And run ```bundler install``` once to install all dependencies.
83
-
84
- Run ```rake test```.
85
-
86
- ### Release
87
- If you are the current maintainer of this plugin:
88
- 1. Ensure all tests passed
89
- 2. Bump up version in ```fluent-plugin-application-insights.gemspec```
90
- 3. Build the gem, install it locally and test it
91
- 4. Create a PR with whatever changes needed before releasing, e.g., version bump up, documentation
92
- 5. Tag and push: ```git tag vx.xx.xx; git push --tags```
93
- 6. Create a github release with the pushed tag
94
- 7. Push to rubygems.org: ```gem push fluent-plugin-application-insights-<version>.gem```
95
-
96
83
  ## Contributing
97
-
98
- This project welcomes contributions and suggestions. Most contributions require you to
99
- agree to a Contributor License Agreement (CLA) declaring that you have the right to,
100
- and actually do, grant us the rights to use your contribution. For details, visit
101
- https://cla.microsoft.com.
102
-
103
- When you submit a pull request, a CLA-bot will automatically determine whether you need
104
- to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
105
- instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
84
+ Refer to [Contributing Guide](CONTRIBUTING.md).
106
85
 
107
86
  This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
108
- For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
109
- or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
87
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
88
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
@@ -3,18 +3,13 @@ $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.1.0"
6
+ spec.version = "0.2.0"
7
7
  spec.authors = ["Microsoft Corporation"]
8
8
  spec.email = ["ctdiagcore@microsoft.com"]
9
9
 
10
10
  spec.summary = "This is the fluentd output plugin for Azure Application Insights."
11
- spec.description = <<-eos
12
- Fluentd output plugin for Azure Application Insights.
13
- Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms.
14
- Use it to monitor your live web application. It will automatically detect performance anomalies. It includes powerful analytics
15
- tools to help you diagnose issues and to understand what users actually do with your app.
16
- It's designed to help you continuously improve performance and usability.
17
- eos
11
+ spec.description = "Fluentd output plugin for Azure Application Insights."
12
+
18
13
  spec.homepage = "https://github.com/Microsoft/fluent-plugin-application-insights"
19
14
  spec.license = "MIT"
20
15
 
@@ -29,6 +24,6 @@ eos
29
24
  spec.add_development_dependency "bundler", "~> 1.14"
30
25
  spec.add_development_dependency "rake", "~> 12.0"
31
26
  spec.add_development_dependency "test-unit", "~> 3.0"
32
- spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
27
+ spec.add_runtime_dependency "fluentd", [">= 1.0", "< 2"]
33
28
  spec.add_runtime_dependency "application_insights", "~> 0.5.5"
34
29
  end
@@ -11,6 +11,8 @@ module Fluent::Plugin
11
11
 
12
12
  attr_accessor :tc
13
13
 
14
+ helpers :record_accessor
15
+
14
16
  # The Application Insights instrumentation key
15
17
  config_param :instrumentation_key, :string
16
18
  # The batch size to send data to Application Insights service.
@@ -59,8 +61,11 @@ module Fluent::Plugin
59
61
  context_tag_keys.concat Channel::Contracts::Session.json_mappings.values
60
62
  context_tag_keys.concat Channel::Contracts::User.json_mappings.values
61
63
 
62
- context_tag_sources.keys.each do |tag|
64
+ @context_tag_accessors = {}
65
+ context_tag_sources.each do |tag, property_path|
63
66
  raise ArgumentError.new("Context tag '#{tag}' is invalid!") unless context_tag_keys.include?(tag)
67
+
68
+ @context_tag_accessors[tag] = record_accessor_create(property_path)
64
69
  end
65
70
  end
66
71
 
@@ -136,9 +141,9 @@ module Fluent::Plugin
136
141
  return if @context_tag_sources.length == 0
137
142
 
138
143
  record["tags"] = record["tags"] || {}
139
- @context_tag_sources.each do |context_tag, source_property|
140
- context_value = record.delete source_property
141
- record["tags"][context_tag] = context_value if context_value
144
+ @context_tag_accessors.each do |tag, accessor|
145
+ tag_value = accessor.call(record)
146
+ record["tags"][tag] = tag_value if !tag_value.nil?
142
147
  end
143
148
  end
144
149
 
@@ -164,16 +169,16 @@ module Fluent::Plugin
164
169
  context.instrumentation_key = @instrumentation_key
165
170
  return context if @context_tag_sources.length == 0
166
171
 
167
- @context_tag_sources.each do |context_tag, source_property|
168
- if record[source_property]
169
- set_context_tag context, context_tag, record[source_property]
170
- end
172
+ @context_tag_accessors.each do |tag, accessor|
173
+ set_context_tag context, tag, accessor.call(record)
171
174
  end
172
175
 
173
176
  return context
174
177
  end
175
178
 
176
179
  def set_context_tag(context, tag_name, tag_value)
180
+ return if tag_value.nil?
181
+
177
182
  context_set = [context.application, context.cloud, context.device, context.location, context.operation, context.session, context.user]
178
183
  context_set.each do |c|
179
184
  c.class.json_mappings.each do |attr, name|
@@ -153,13 +153,42 @@ class ApplicationInsightsOutputTest < Test::Unit::TestCase
153
153
  assert_nil envelope.data["baseData"]["properties"]
154
154
  end
155
155
 
156
+ test 'context tag source is nested property path' do
157
+ config = %[
158
+ instrumentation_key ikey
159
+ standard_schema true
160
+ context_tag_sources {
161
+ "ai.cloud.role": "$.kubernetes.container_name",
162
+ "ai.cloud.roleInstance": "$.kubernetes.not_exist"
163
+ }
164
+ ]
165
+ d = create_driver config
166
+
167
+ time = event_time("2011-01-02 13:14:15 UTC")
168
+ d.run(default_tag: 'test', shutdown: false) do
169
+ d.feed(time, {
170
+ "name" => "telemetry name",
171
+ "data" => { "baseType" => "RequestData", "baseData" => {} },
172
+ "kubernetes" => {
173
+ "container_name" => "frontend",
174
+ "container_id" => "c42c557e1615511dd3a3cb1d6e8f14984464bb0f"
175
+ }
176
+ })
177
+ end
178
+
179
+ envelope = d.instance.tc.channel.queue[0]
180
+ assert_not_nil envelope.tags
181
+ assert_equal "frontend", envelope.tags["ai.cloud.role"]
182
+ assert_nil envelope.tags["ai.cloud.roleInstance"]
183
+ end
184
+
156
185
  test 'multiple context tag keys' do
157
186
  config = %[
158
187
  instrumentation_key ikey
159
188
  standard_schema true
160
189
  context_tag_sources {
161
190
  "ai.cloud.role": "kubernetes_container_name",
162
- "ai.cloud.roleInstance": "kubernetes_container_id"
191
+ "ai.cloud.roleInstance": "$.docker.container_id"
163
192
  }
164
193
  ]
165
194
  d = create_driver config
@@ -169,8 +198,10 @@ class ApplicationInsightsOutputTest < Test::Unit::TestCase
169
198
  d.feed(time, {
170
199
  "name" => "telemetry name",
171
200
  "data" => { "baseType" => "RequestData", "baseData" => {} },
172
- "kubernetes_container_name" => "frontend",
173
- "kubernetes_container_id" => "c42c557e1615511dd3a3cb1d6e8f14984464bb0f"
201
+ "docker" => {
202
+ "container_id" => "c42c557e1615511dd3a3cb1d6e8f14984464bb0f"
203
+ },
204
+ "kubernetes_container_name" => "frontend"
174
205
  })
175
206
  end
176
207
 
@@ -353,12 +384,40 @@ class ApplicationInsightsOutputTest < Test::Unit::TestCase
353
384
  assert_not_nil envelope.data.base_data.properties["other_prop"]
354
385
  end
355
386
 
387
+ test 'context tag source is nested property path' do
388
+ config = %[
389
+ instrumentation_key ikey
390
+ context_tag_sources {
391
+ "ai.cloud.role": "$.kubernetes.container_name",
392
+ "ai.cloud.roleInstance": "$.kubernetes.not_exist"
393
+ }
394
+ ]
395
+ d = create_driver config
396
+
397
+ time = event_time("2011-01-02 13:14:15 UTC")
398
+ d.run(default_tag: 'test', shutdown: false) do
399
+ d.feed(time, {
400
+ "name" => "telemetry name",
401
+ "data" => { "baseType" => "RequestData", "baseData" => {} },
402
+ "kubernetes" => {
403
+ "container_name" => "frontend",
404
+ "container_id" => "c42c557e1615511dd3a3cb1d6e8f14984464bb0f"
405
+ }
406
+ })
407
+ end
408
+
409
+ envelope = d.instance.tc.channel.queue[0]
410
+ assert_not_nil envelope.tags
411
+ assert_equal "frontend", envelope.tags["ai.cloud.role"]
412
+ assert_nil envelope.tags["ai.cloud.roleInstance"]
413
+ end
414
+
356
415
  test 'multiple context tag keys' do
357
416
  config = %[
358
417
  instrumentation_key ikey
359
418
  context_tag_sources {
360
419
  "ai.cloud.role": "kubernetes_container_name",
361
- "ai.cloud.roleInstance": "kubernetes_container_id"
420
+ "ai.cloud.roleInstance": "$.docker.container_id"
362
421
  }
363
422
  ]
364
423
  d = create_driver config
@@ -367,8 +426,10 @@ class ApplicationInsightsOutputTest < Test::Unit::TestCase
367
426
  d.run(default_tag: 'test', shutdown: false) do
368
427
  d.feed(time, {
369
428
  "message" => "my message",
370
- "kubernetes_container_name" => "frontend",
371
- "kubernetes_container_id" => "c42c557e1615511dd3a3cb1d6e8f14984464bb0f"
429
+ "docker" => {
430
+ "container_id" => "c42c557e1615511dd3a3cb1d6e8f14984464bb0f"
431
+ },
432
+ "kubernetes_container_name" => "frontend"
372
433
  })
373
434
  end
374
435
 
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.1.0
4
+ version: 0.2.0
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-03 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.14.10
61
+ version: '1.0'
62
62
  - - "<"
63
63
  - !ruby/object:Gem::Version
64
64
  version: '2'
@@ -68,7 +68,7 @@ dependencies:
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: 0.14.10
71
+ version: '1.0'
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2'
@@ -86,12 +86,7 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.5.5
89
- description: |2
90
- Fluentd output plugin for Azure Application Insights.
91
- Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms.
92
- Use it to monitor your live web application. It will automatically detect performance anomalies. It includes powerful analytics
93
- tools to help you diagnose issues and to understand what users actually do with your app.
94
- It's designed to help you continuously improve performance and usability.
89
+ description: Fluentd output plugin for Azure Application Insights.
95
90
  email:
96
91
  - ctdiagcore@microsoft.com
97
92
  executables: []
@@ -100,6 +95,7 @@ extra_rdoc_files: []
100
95
  files:
101
96
  - ".gitignore"
102
97
  - ".travis.yml"
98
+ - CONTRIBUTING.md
103
99
  - Gemfile
104
100
  - LICENSE
105
101
  - README.md