nexus_semantic_logger 1.12 → 1.12.1

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: 70e0537b45679788fc9dc6ce2c5e6ae6698e840735039bfc8d55ac324e03d062
4
- data.tar.gz: 6a489153ff7db8a3d2bca5696a3ceec917014f9e10416f3a04f5446114a0514b
3
+ metadata.gz: 903718bb8acb37308fee8d2b0739ae7a708538a6372029d50f198229646cca93
4
+ data.tar.gz: 4c40fdfa07c84b82938b4ca185aec63840d35f86222fdd3cdf058a0e4c453c27
5
5
  SHA512:
6
- metadata.gz: 25f789b5449465c5466d74c780cfb6401e4c5f4df493b40d616f55de5d986366d3d677b69ea1ce51f20e7c94ce71c7e896ec3c61470969db96c213a5c8ad26d8
7
- data.tar.gz: a28d97cf7fa44c87511388145e38f2132e1787f711995523226ce388c5c4260ae59c5a975e52daa072bc11273f5fb6698b10ee5ebec3e21b43479b3f59bbfd33
6
+ metadata.gz: 7d30a09cc0440a01ea89fc0cc48e04e883ec955e05749c5b7b406dd2b1013dc540f1e9a2e2a95befba6f8248b2f970440bdb53ab28dce572fb6f2c45794cd3d1
7
+ data.tar.gz: 15ae5d8e3bfad2eab8f81649a27b2755a302f04e00eea1248738edba543ab2824d56bd6298608c13a1a7eb8953eac6bf88183fe8530fa6eacb753a351a4583eb
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSemanticLogger
3
- # Leave this as 1.12 in order for CI process to replace with the tagged version.
4
- VERSION = '1.12'
3
+ # Leave this as 1.12.1 in order for CI process to replace with the tagged version.
4
+ VERSION = '1.12.1'
5
5
  end
@@ -2,40 +2,12 @@
2
2
  require 'puma'
3
3
  require 'puma/plugin'
4
4
  require 'socket'
5
- require 'nexus_semantic_logger/datadog_singleton'
5
+ require 'nexus_semantic_logger'
6
6
 
7
7
  # Forked from puma-plugin-statsd.
8
8
  # Uses the same datadog settings as nexus_semantic_logger.
9
9
  # To use, add to puma.rb:
10
10
  # plugin :nexus_puma_statsd
11
- class StatsdConnector
12
- STATSD_TYPES = { count: 'c', gauge: 'g' }
13
- METRIC_DELIMETER = "."
14
-
15
- attr_reader :host, :port
16
-
17
- def initialize
18
- @host = ENV.fetch('DD_AGENT_HOST', '127.0.0.1')
19
- @port = ENV.fetch('DD_STATSD_PORT', 8125)
20
- @socket_path = ENV.fetch('DD_STATSD_SOCKET_PATH', '')
21
- end
22
-
23
- def send(metric_name:, value:, type:, tags: nil)
24
- data = "#{metric_name}:#{value}|#{STATSD_TYPES.fetch(type)}"
25
- data = "#{data}|##{tags}" unless tags.nil?
26
-
27
- if @socket_path.to_s.strip.empty?
28
- socket = UDPSocket.new
29
- socket.send(data, 0, host, port)
30
- else
31
- socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM)
32
- socket.connect(Socket.pack_sockaddr_un(@socket_path))
33
- socket.sendmsg_nonblock(data)
34
- end
35
- ensure
36
- socket.close
37
- end
38
- end
39
11
 
40
12
  # Wrap puma's stats in a safe API
41
13
  class PumaStats
@@ -111,14 +83,7 @@ Puma::Plugin.create do
111
83
  @launcher.events
112
84
  end
113
85
 
114
- @statsd = ::StatsdConnector.new
115
- @log_writer.debug("statsd: enabled (host: #{@statsd.host})")
116
-
117
- # Fetch global metric prefix from env variable
118
- @metric_prefix = ENV.fetch('DD_STATSD_METRIC_PREFIX', nil)
119
- if @metric_prefix && !@metric_prefix.end_with?(::StatsdConnector::METRIC_DELIMETER)
120
- @metric_prefix += ::StatsdConnector::METRIC_DELIMETER
121
- end
86
+ @log_writer.debug('statsd: enabled')
122
87
 
123
88
  register_hooks
124
89
  end
@@ -137,8 +102,6 @@ Puma::Plugin.create do
137
102
  # Examples: simple-tag-0 tag-key-1:tag-value-1
138
103
  #
139
104
  tags = []
140
- global_tags = NexusSemanticLogger::DatadogSingleton.instance.global_tags
141
- tags += global_tags unless global_tags.nil?
142
105
 
143
106
  if ENV.key?('HOSTNAME')
144
107
  tags << "pod_name:#{ENV['HOSTNAME']}"
@@ -179,15 +142,9 @@ Puma::Plugin.create do
179
142
  tags << "dd.internal.entity_id:#{ENV['DD_ENTITY_ID']}"
180
143
  end
181
144
 
182
- # Return nil if we have no environment variable tags. This way we don't
183
- # send an unnecessary '|' on the end of each stat
184
145
  return nil if tags.empty?
185
146
 
186
- tags.join(",")
187
- end
188
-
189
- def prefixed_metric_name(puma_metric)
190
- "#{@metric_prefix}#{puma_metric}"
147
+ tags
191
148
  end
192
149
 
193
150
  # Send data to statsd every few seconds
@@ -196,24 +153,19 @@ Puma::Plugin.create do
196
153
 
197
154
  sleep(5)
198
155
  loop do
199
- @log_writer.debug("statsd: notify statsd")
156
+ @log_writer.debug('statsd: notify statsd')
200
157
  begin
201
158
  stats = ::PumaStats.new(Puma.stats_hash)
202
- @statsd.send(metric_name: prefixed_metric_name("puma.workers"), value: stats.workers, type: :gauge, tags: tags)
203
- @statsd.send(metric_name: prefixed_metric_name("puma.booted_workers"), value: stats.booted_workers,
204
- type: :gauge, tags: tags)
205
- @statsd.send(metric_name: prefixed_metric_name("puma.old_workers"), value: stats.old_workers, type: :gauge,
206
- tags: tags)
207
- @statsd.send(metric_name: prefixed_metric_name("puma.running"), value: stats.running, type: :gauge, tags: tags)
208
- @statsd.send(metric_name: prefixed_metric_name("puma.backlog"), value: stats.backlog, type: :gauge, tags: tags)
209
- @statsd.send(metric_name: prefixed_metric_name("puma.pool_capacity"), value: stats.pool_capacity, type: :gauge,
210
- tags: tags)
211
- @statsd.send(metric_name: prefixed_metric_name("puma.max_threads"), value: stats.max_threads, type: :gauge,
212
- tags: tags)
213
- @statsd.send(metric_name: prefixed_metric_name("puma.requests_count"), value: stats.requests_count,
214
- type: :gauge, tags: tags)
159
+ NexusSemanticLogger.metrics.gauge('puma.workers', stats.workers, tags: tags)
160
+ NexusSemanticLogger.metrics.gauge('puma.booted_workers', stats.booted_workers, tags: tags)
161
+ NexusSemanticLogger.metrics.gauge('puma.old_workers', stats.old_workers, tags: tags)
162
+ NexusSemanticLogger.metrics.gauge('puma.running', stats.running, tags: tags)
163
+ NexusSemanticLogger.metrics.gauge('puma.backlog', stats.backlog, tags: tags)
164
+ NexusSemanticLogger.metrics.gauge('puma.pool_capacity', stats.pool_capacity, tags: tags)
165
+ NexusSemanticLogger.metrics.gauge('puma.max_threads', stats.max_threads, tags: tags)
166
+ NexusSemanticLogger.metrics.gauge('puma.requests_count', stats.requests_count, tags: tags)
215
167
  rescue StandardError => e
216
- @log_writer.unknown_error(e, nil, "! statsd: notify stats failed")
168
+ @log_writer.unknown_error(e, nil, '! statsd: notify stats failed')
217
169
  ensure
218
170
  sleep(2)
219
171
  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'
4
+ version: 1.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris