nexus_semantic_logger 1.8.0 → 1.9.0
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 +4 -4
- data/lib/nexus_semantic_logger/application.rb +2 -0
- data/lib/nexus_semantic_logger/datadog_singleton.rb +15 -5
- data/lib/nexus_semantic_logger/logger_metrics_subscriber.rb +36 -0
- data/lib/nexus_semantic_logger/version.rb +2 -2
- data/lib/nexus_semantic_logger.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71ea65404e5b4980ffa32eda0d91588142cd2571252117f1f651f566f506bb98
|
4
|
+
data.tar.gz: ade58c1fcc429f832d26ed23786d859068cefb6e33a1f7b5b32d2627de999c91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d488c447d1e7f14c49a0c33ff0ee79ff512346ea17557c68a91e4b204dd37d9bdafb04383ed4db1c7c2c71d15273a9375c49c1e031a9a710e2345b34f143db9
|
7
|
+
data.tar.gz: 3712bf027d2fc5668c3a593d8cbd79457aef86d69a19e5602bfe4929ba301e14f6ce9006680acfbf4ce777ba5ae42f18ee45cdb6fded3a3fa4d1e0f8c284479b
|
@@ -39,6 +39,8 @@ module NexusSemanticLogger
|
|
39
39
|
|
40
40
|
NexusSemanticLogger::DatadogTracer.new(service)
|
41
41
|
|
42
|
+
SemanticLogger.on_log(NexusSemanticLogger::LoggerMetricsSubscriber.new)
|
43
|
+
|
42
44
|
logger.info('SemanticLogger initialised.', level: config.log_level)
|
43
45
|
|
44
46
|
config.after_initialize do
|
@@ -17,7 +17,7 @@ module NexusSemanticLogger
|
|
17
17
|
# @param [String] metric Metric name.
|
18
18
|
# @param [Array<String>] tags Additional tags.
|
19
19
|
def increment(metric, tags: [])
|
20
|
-
statsd&.increment(metric, tags:
|
20
|
+
statsd&.increment(metric, tags: combine_tags(tags))
|
21
21
|
flush
|
22
22
|
end
|
23
23
|
|
@@ -25,7 +25,7 @@ module NexusSemanticLogger
|
|
25
25
|
# @param [String] metric Metric name.
|
26
26
|
# @param [Array<String>] tags Additional tags.
|
27
27
|
def decrement(metric, tags: [])
|
28
|
-
statsd&.decrement(metric, tags:
|
28
|
+
statsd&.decrement(metric, tags: combine_tags(tags))
|
29
29
|
flush
|
30
30
|
end
|
31
31
|
|
@@ -34,7 +34,7 @@ module NexusSemanticLogger
|
|
34
34
|
# @param [Integer] ms Timing in milliseconds.
|
35
35
|
# @param [Array<String>] tags Additional tags.
|
36
36
|
def timing(metric, ms, tags: [])
|
37
|
-
statsd&.timing(metric, ms, tags:
|
37
|
+
statsd&.timing(metric, ms, tags: combine_tags(tags))
|
38
38
|
flush
|
39
39
|
end
|
40
40
|
|
@@ -43,7 +43,7 @@ module NexusSemanticLogger
|
|
43
43
|
# @param [Numeric] value Distribution value.
|
44
44
|
# @param [Array<String>] tags Additional tags.
|
45
45
|
def distribution(metric, value, tags: [])
|
46
|
-
statsd&.distribution(metric, value, tags:
|
46
|
+
statsd&.distribution(metric, value, tags: combine_tags(tags))
|
47
47
|
flush
|
48
48
|
end
|
49
49
|
|
@@ -52,8 +52,18 @@ module NexusSemanticLogger
|
|
52
52
|
# @param [Numeric] value Gauge value.
|
53
53
|
# @param [Array<String>] tags Additional tags.
|
54
54
|
def gauge(metric, value, tags: [])
|
55
|
-
statsd&.gauge(metric, value, tags:
|
55
|
+
statsd&.gauge(metric, value, tags: combine_tags(tags))
|
56
56
|
flush
|
57
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Safely combine the global tags with the supplied tags.
|
62
|
+
def combine_tags(tags)
|
63
|
+
final_tags = []
|
64
|
+
final_tags += global_tags unless global_tags.nil?
|
65
|
+
final_tags += tags unless tags.nil?
|
66
|
+
final_tags
|
67
|
+
end
|
58
68
|
end
|
59
69
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'semantic_logger'
|
3
|
+
|
4
|
+
module NexusSemanticLogger
|
5
|
+
# Sends SemanticLogger metrics to statsd.
|
6
|
+
# This is a candidate to move into the nexus_semantic_logger gem if it becomes widely useful.
|
7
|
+
# See https://logger.rocketjob.io/metrics.html
|
8
|
+
# Based on https://github.com/reidmorrison/semantic_logger/blob/master/lib/semantic_logger/metric/statsd.rb
|
9
|
+
class LoggerMetricsSubscriber < SemanticLogger::Subscriber
|
10
|
+
def call(log)
|
11
|
+
log(log) if should_log?(log)
|
12
|
+
end
|
13
|
+
|
14
|
+
def log(log)
|
15
|
+
metric = log.metric
|
16
|
+
tags = log.payload.nil? ? nil : []
|
17
|
+
log.payload&.each_pair { |key, value| tags << "#{key}:#{value}" }
|
18
|
+
if (duration = log.duration)
|
19
|
+
NexusSemanticLogger.metrics.timing(metric, duration, tags: tags)
|
20
|
+
else
|
21
|
+
amount = (log.metric_amount || 1).round
|
22
|
+
if amount.negative?
|
23
|
+
NexusSemanticLogger.metrics.decrement(metric, tags: tags)
|
24
|
+
else
|
25
|
+
NexusSemanticLogger.metrics.increment(metric, tags: tags)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Only forward log entries that contain metrics.
|
31
|
+
def should_log?(log)
|
32
|
+
# Does not support metrics with dimensions.
|
33
|
+
log.metric && !log.dimensions && meets_log_level?(log) && !filtered?(log)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module NexusSemanticLogger
|
3
|
-
# Leave this as 1.
|
4
|
-
VERSION = '1.
|
3
|
+
# Leave this as 1.9.0 in order for CI process to replace with the tagged version.
|
4
|
+
VERSION = '1.9.0'
|
5
5
|
end
|
@@ -4,6 +4,7 @@ require 'nexus_semantic_logger/application'
|
|
4
4
|
require 'nexus_semantic_logger/datadog_formatter'
|
5
5
|
require 'nexus_semantic_logger/datadog_singleton'
|
6
6
|
require 'nexus_semantic_logger/datadog_tracer'
|
7
|
+
require 'nexus_semantic_logger/logger_metrics_subscriber'
|
7
8
|
|
8
9
|
module NexusSemanticLogger
|
9
10
|
# Get application wide object for sending metrics.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johnathon Harris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/nexus_semantic_logger/datadog_singleton.rb
|
113
113
|
- lib/nexus_semantic_logger/datadog_tracer.rb
|
114
114
|
- lib/nexus_semantic_logger/extensions/action_dispatch/debug_exceptions.rb
|
115
|
+
- lib/nexus_semantic_logger/logger_metrics_subscriber.rb
|
115
116
|
- lib/nexus_semantic_logger/sneakers_metrics.rb
|
116
117
|
- lib/nexus_semantic_logger/version.rb
|
117
118
|
- nexus_semantic_logger.gemspec
|