nexus_semantic_logger 1.1.0 → 1.3.1

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
  SHA256:
3
- metadata.gz: 2f12150f394b0f2c56570a19a1979c3f8cf0f58f3c622d6d2886ed6925041825
4
- data.tar.gz: 7fc2853cb92631be96b8bc17f07d97eff6057091170704d28ef0280b673ac370
3
+ metadata.gz: 1f184a3b288517782bc5d96269ae0c063ce0b339beca2e3803053cf367fa07a4
4
+ data.tar.gz: af2f852f8f3684579a66d01ee88e93bbad5f6a77ee4ad0e6d94bd960d92ffc5c
5
5
  SHA512:
6
- metadata.gz: dd9b6db086b0b1bb5f8cb760577d87a8603ae892aeeb8e01249081911f3b83068e96357ad0c13a8fa184e96a63efb9f55241bbcc1baa7aa4e513021dd713689b
7
- data.tar.gz: '084c137b346270f171132a5de282a3a2019be85fe5a83de3677cedf26290f6f7b1ced55c2ede9cbd57afe9daa6ed9d5d58ddf60ce5e7954d6e3b937753302e30'
6
+ metadata.gz: 34d4ca84e68c661233ace84517bb97c64bb7b2094ec5074806ae2f8b7e76620f2949f1ea9b0ff1a54ec3ec51d61fee5dc58d33a818cc3784deacbd1d34043a42
7
+ data.tar.gz: '019e286d210008cc459e342d2af251b8bcf175afbc5b6ca6779e263fe14645bd29751d5a11444f5392fe6007b6cb2cafec2196b5b5fdba09f77288289f6b4ef5'
data/README.md CHANGED
@@ -1,3 +1,57 @@
1
1
  # nexus_semantic_logger
2
2
 
3
3
  Configures a [semantic_logger](https://rubygems.org/gems/rails_semantic_logger) as required for NexusMods components.
4
+
5
+ ## Telemetry
6
+
7
+ As well as providing a semantic logger, this gem handles datadog telemetry associated with the logging approach:
8
+
9
+ * logs
10
+ * traces
11
+ * metrics
12
+ * statsd is automatically attached to datadog runtime metrics and may also be used for custom metrics.
13
+
14
+ ### Sending metrics
15
+
16
+ Ensure the metric name is in the format: `nexus.{component}.{major}.{minor}`
17
+
18
+ Where _major and minor_ are specific to the component logic e.g. `nexus.uploads.clamscan.pass`
19
+
20
+ For example, to increment a count:
21
+
22
+ ```
23
+ NexusSemanticLogger.metrics.increment('nexus.users.registration.complete')
24
+ ```
25
+
26
+ # Local gem development
27
+
28
+ Steps to run this gem from local sources in one the nexus 'staged build' rails components:
29
+
30
+ ## Copy gem sources to component
31
+
32
+ ```
33
+ cd ~/legacy/users
34
+ cp -r ../nexus_semantic_logger .
35
+ ```
36
+
37
+ ## Adjust component Dockerfile to include gem sources
38
+
39
+ Within stage 1, append a COPY after the Gemfile copy:
40
+
41
+ ```
42
+ COPY --chown=nexus:nexus Gemfile* ./
43
+ COPY --chown=nexus:nexus nexus_semantic_logger/ ./nexus_semantic_logger/
44
+ ```
45
+
46
+ Within stage 2, append a COPY after the bundle copy:
47
+
48
+ ```
49
+ COPY --from=stage1 /usr/local/bundle /usr/local/bundle
50
+ COPY --from=stage1 /app/nexus_semantic_logger/ /app/nexus_semantic_logger/
51
+ ```
52
+
53
+ ## Adjust Gemfile to use local path
54
+
55
+ ```
56
+ gem 'nexus_semantic_logger', :path => "/app/nexus_semantic_logger"
57
+
@@ -36,6 +36,8 @@ module NexusSemanticLogger
36
36
  dd_appender = config.semantic_logger.add_appender(io: $stdout, formatter: config.rails_semantic_logger.format)
37
37
  dd_appender.filter = NexusSemanticLogger::AppenderFilter.filter_lambda
38
38
 
39
+ NexusSemanticLogger::DatadogTracer.new(service)
40
+
39
41
  logger.info('SemanticLogger initialised.', level: config.log_level)
40
42
  end
41
43
 
@@ -48,13 +50,13 @@ module NexusSemanticLogger
48
50
  color_appender = config.semantic_logger.add_appender(io: $stdout, formatter: :color)
49
51
  color_appender.filter = NexusSemanticLogger::AppenderFilter.filter_lambda
50
52
 
51
- if ENV['DD_AGENT_HOST'].present? && ENV['DD_AGENT_PORT'].present?
53
+ if ENV['DD_AGENT_HOST'].present? && ENV['DD_AGENT_LOGGING_PORT'].present?
52
54
  # Development logs can be sent to datadog via a TCP logging endpoint on a local agent.
53
55
  # Each port is assigned a particular service.
54
56
  # See https://logger.rocketjob.io/appenders.html
55
57
  dd_appender = config.semantic_logger.add_appender(
56
58
  appender: :tcp,
57
- server: "#{ENV['DD_AGENT_HOST']}:#{ENV['DD_AGENT_PORT']}",
59
+ server: "#{ENV['DD_AGENT_HOST']}:#{ENV['DD_AGENT_LOGGING_PORT']}",
58
60
  formatter: config.rails_semantic_logger.format
59
61
  )
60
62
  dd_appender.filter = NexusSemanticLogger::AppenderFilter.filter_lambda
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require 'singleton'
3
+
4
+ module NexusSemanticLogger
5
+ # Application wide location to get datadog objects.
6
+ # dogstatsd-ruby maintains its own queue and thread for flushing, so the client code should never create its
7
+ # own statsd instance.
8
+ class DatadogSingleton
9
+ include Singleton
10
+ attr_accessor :statsd, :tags
11
+
12
+ def flush
13
+ statsd&.flush(sync: Rails.env.development?) # Force flush sync in development, speed up checks.
14
+ end
15
+
16
+ def increment(metric_name)
17
+ statsd&.increment(metric_name, tags: tags)
18
+ flush
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require 'datadog/statsd'
3
+ require 'ddtrace'
4
+
5
+ module NexusSemanticLogger
6
+ class DatadogTracer
7
+ def initialize(service)
8
+ Datadog.configure do |c|
9
+ if ENV['DD_AGENT_HOST'].present?
10
+ # To enable runtime metrics collection, set `true`. Defaults to `false`
11
+ # You can also set DD_RUNTIME_METRICS_ENABLED=true to configure this.
12
+ c.runtime_metrics.enabled = true
13
+
14
+ # Configure DogStatsD instance for sending runtime metrics.
15
+ # By default, runtime metrics from the application are sent to the Datadog Agent with DogStatsD on port 8125.
16
+ datadog_singleton = DatadogSingleton.instance
17
+ datadog_singleton.statsd = Datadog::Statsd.new(ENV['DD_AGENT_HOST'], 8125)
18
+ datadog_singleton.tags = ["env:#{Rails.env}", "service:#{service}"]
19
+ c.runtime_metrics.statsd = datadog_singleton.statsd
20
+
21
+ # Tracer requires configuration to a datadog agent via DD_AGENT_HOST.
22
+ dd_force_tracer_val = ENV.fetch('DD_FORCE_TRACER', false)
23
+ dd_force_tracer = dd_force_tracer_val.present? && dd_force_tracer_val.to_s == 'true'
24
+ c.tracer(enabled: Rails.env.production? || dd_force_tracer, env: Rails.env)
25
+ end
26
+
27
+ c.use(:rails, service_name: service)
28
+
29
+ c.logger.level = Logger::WARN # ddtrace info logging is too verbose.
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSemanticLogger
3
- # Leave this as 1.1.0 in order for CI process to replace with the tagged version.
4
- VERSION = '1.1.0'
3
+ # Leave this as 1.3.1 in order for CI process to replace with the tagged version.
4
+ VERSION = '1.3.1'
5
5
  end
@@ -2,6 +2,12 @@
2
2
  require 'nexus_semantic_logger/appender_filter'
3
3
  require 'nexus_semantic_logger/application'
4
4
  require 'nexus_semantic_logger/datadog_formatter'
5
+ require 'nexus_semantic_logger/datadog_singleton'
6
+ require 'nexus_semantic_logger/datadog_tracer'
5
7
 
6
8
  module NexusSemanticLogger
9
+ # Get application wide object for sending metrics.
10
+ def self.metrics
11
+ DatadogSingleton.instance
12
+ end
7
13
  end
@@ -16,5 +16,6 @@ Gem::Specification.new do |spec|
16
16
  spec.add_dependency('amazing_print', '~> 1.4.0')
17
17
  spec.add_dependency('rails_semantic_logger', '~> 4.10.0')
18
18
  spec.add_dependency('net_tcp_client', '~> 2.2.0') # For TCP logging.
19
+ spec.add_dependency('dogstatsd-ruby', '~> 5.4.0') # For custom application metrics.
19
20
  spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
20
21
  end
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.1.0
4
+ version: 1.3.1
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-07-06 00:00:00.000000000 Z
11
+ date: 2022-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: dogstatsd-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.4.0
55
69
  description:
56
70
  email: john.harris@nexusmods.com
57
71
  executables: []
@@ -66,6 +80,8 @@ files:
66
80
  - lib/nexus_semantic_logger/appender_filter.rb
67
81
  - lib/nexus_semantic_logger/application.rb
68
82
  - lib/nexus_semantic_logger/datadog_formatter.rb
83
+ - lib/nexus_semantic_logger/datadog_singleton.rb
84
+ - lib/nexus_semantic_logger/datadog_tracer.rb
69
85
  - lib/nexus_semantic_logger/version.rb
70
86
  - nexus_semantic_logger.gemspec
71
87
  homepage:
@@ -86,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
102
  - !ruby/object:Gem::Version
87
103
  version: '0'
88
104
  requirements: []
89
- rubygems_version: 3.3.17
105
+ rubygems_version: 3.3.21
90
106
  signing_key:
91
107
  specification_version: 4
92
108
  summary: semantic_logger usage for nexus