nexus_semantic_logger 1.12.9 → 1.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abb0bba8e622134aa67ef31d848a73d3481c09e256bd57e55c561f07762ccc6f
4
- data.tar.gz: f25e7ea4e596735b7fe70846043f47624fccb537f5e2c602770a2b2aa9a6c0ee
3
+ metadata.gz: 562ce2a80e027294d0fa28aed717b1328abb49fa273c99c04c86f693e1f6d20f
4
+ data.tar.gz: a39448a49120379ce921247ba97411fd2200e62189e7a9cacc25ca6c546651dc
5
5
  SHA512:
6
- metadata.gz: a88e716e7a0938dac222e04f351135dadb3b367ba5b5e2de48d020178a95078a19bedca6ce740d2426ffa19daf33371176dcbeca658d2dd578d2cb72342aa6bf
7
- data.tar.gz: 77b046e8770670ff7f06982fdfffd49fb3cca9fedcaee396210d61c949c6c2d15db2b223715464a7890b4e6424a254ef7dd8e3232d9bcc8a2b4f54a56ae70c2a
6
+ metadata.gz: a2501384e077d2d88940b3f22d78acac6ffcc50377a1fb9250498abf099b28fc13a395a7c170da317773ac8a813df24338abd87de7a5f7441b97014553ae0853
7
+ data.tar.gz: a5690e95153d831570b4b1f4e2ae695b34ab2900c54bf65a2c0abae48a5761bed05f7f8c36717901927e05a477b60c603918b0fba5d7c992e6ee67e641faa7fc
data/README.md CHANGED
@@ -10,6 +10,7 @@ As well as providing a semantic logger, this gem handles datadog telemetry assoc
10
10
  * traces
11
11
  * metrics
12
12
  * statsd is automatically attached to datadog runtime metrics and may also be used for custom metrics.
13
+ * `ResponseCodeStatsMiddleware` is included to capture response code metrics from rack applications
13
14
 
14
15
  ### Customise log level per logger
15
16
 
@@ -60,6 +61,13 @@ For example, to increment a count:
60
61
  NexusSemanticLogger.metrics.increment('nexus.users.registration.complete')
61
62
  ```
62
63
 
64
+ ### Rack response code metrics
65
+ This can be configured with a middleware in application.rb
66
+
67
+ ```
68
+ config.middleware.use ResponseCodeStatsMiddleware
69
+ ```
70
+
63
71
  # Local gem development
64
72
 
65
73
  Steps to run this gem from local sources in one the nexus 'staged build' rails components:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSemanticLogger
3
- # Leave this as 1.12.9 in order for CI process to replace with the tagged version.
4
- VERSION = '1.12.9'
3
+ # Leave this as 1.12.10 in order for CI process to replace with the tagged version.
4
+ VERSION = '1.12.10'
5
5
  end
@@ -163,7 +163,15 @@ Puma::Plugin.create do
163
163
  NexusSemanticLogger.metrics.gauge('puma.backlog', stats.backlog, tags: tags)
164
164
  NexusSemanticLogger.metrics.gauge('puma.pool_capacity', stats.pool_capacity, tags: tags)
165
165
  NexusSemanticLogger.metrics.gauge('puma.max_threads', stats.max_threads, tags: tags)
166
- NexusSemanticLogger.metrics.gauge('puma.requests_count', stats.requests_count, tags: tags)
166
+ NexusSemanticLogger.metrics.increment('puma.requests_count', stats.requests_count, tags: tags)
167
+
168
+ ResponseCodeStatsMiddleware.read_and_reset_metrics.each do |code, count|
169
+ NexusSemanticLogger.metrics.increment(
170
+ "puma.rack.response.status",
171
+ count,
172
+ tags: tags + ["response_status:#{code}"]
173
+ )
174
+ end
167
175
  rescue StandardError => e
168
176
  @log_writer.unknown_error(e, nil, '! statsd: notify stats failed')
169
177
  ensure
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # noinspection RubyClassVariableUsageInspection
4
+ class ResponseCodeStatsMiddleware
5
+ def initialize(app)
6
+ @app = app
7
+ @@code_metrics = {}
8
+ end
9
+
10
+ def call(env)
11
+ status, headers, response = @app.call(env)
12
+
13
+ @@code_metrics[status] ||= 0
14
+ @@code_metrics[status] += 1
15
+
16
+ [status, headers, response]
17
+ end
18
+
19
+ def self.read_and_reset_metrics
20
+ metrics = @@code_metrics.dup
21
+ @@code_metrics.clear
22
+ metrics
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.9
4
+ version: 1.12.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris
@@ -132,6 +132,7 @@ files:
132
132
  - lib/nexus_semantic_logger/version.rb
133
133
  - lib/puma/plugin/README.md
134
134
  - lib/puma/plugin/nexus_puma_statsd.rb
135
+ - lib/rack/response_code_stats_middleware.rb
135
136
  - nexus_semantic_logger.gemspec
136
137
  homepage:
137
138
  licenses: []