researchable_loggable 1.0.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +71 -1
- data/README.md +11 -1
- data/lib/loggable/opentelemetry_config.rb +19 -0
- data/lib/loggable/railtie.rb +11 -1
- data/lib/loggable/version.rb +1 -1
- data/lib/researchable_loggable.rb +1 -0
- data/node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb +1 -1
- metadata +49 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb2f10f55fe229b5aa4fa37200b4938d1f2bfca095bea3445cc02e45257cb36
|
4
|
+
data.tar.gz: e0929bdc0b5db11fc17a5515ef06582eab0b4ff8581c42b3c9f6f2bc45adaa25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc20b8d6d7952f11f8d735e6ebccf4d5ecb3b36daaa70e913df3f9e79bcd70c74d83cd0955c6dd432dec7126c510db9462afc1136f70eabed577e71e11903bcf
|
7
|
+
data.tar.gz: f184d1792cc43b07c01f878083767e65ba8f891961c8cafd0b7e531abd140718c6bb9bfd22ea03b800f48bfe66d02d0db2c7e966bb79acc4d1df43d6234ee81d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# [1.2.0](https://gitlab.com/researchable/general/gems/loggable/compare/v1.1.0...v1.2.0) (2024-09-03)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* add OpenTelemetry ([1dc8d60](https://gitlab.com/researchable/general/gems/loggable/commit/1dc8d60bfc736f2e24c76cb8ece35c0f9f81ac74))
|
7
|
+
|
8
|
+
|
9
|
+
### Reverts
|
10
|
+
|
11
|
+
* **config:** set loggable production_like back to [secure] ([68c1ec1](https://gitlab.com/researchable/general/gems/loggable/commit/68c1ec11f25d6b58e38ee1c36aa479e63ee1b9eb))
|
12
|
+
|
13
|
+
# [1.1.0](https://gitlab.com/researchable/general/gems/loggable/compare/v1.0.2...v1.1.0) (2023-07-06)
|
14
|
+
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* **config:** Support other current_user_method ([e5797ba](https://gitlab.com/researchable/general/gems/loggable/commit/e5797ba6cc7f2a3e589895cf05ba2f4a109b10e1))
|
19
|
+
|
1
20
|
## [1.0.2](https://gitlab.com/researchable/general/gems/loggable/compare/v1.0.1...v1.0.2) (2023-06-27)
|
2
21
|
|
3
22
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
researchable_loggable (1.0
|
4
|
+
researchable_loggable (1.1.0)
|
5
5
|
ecs-logging (~> 1.0)
|
6
6
|
lograge
|
7
7
|
logstash-event
|
8
|
+
opentelemetry-api
|
9
|
+
opentelemetry-exporter-otlp
|
10
|
+
opentelemetry-instrumentation-rails
|
11
|
+
opentelemetry-sdk
|
8
12
|
|
9
13
|
GEM
|
10
14
|
remote: https://rubygems.org/
|
@@ -28,12 +32,18 @@ GEM
|
|
28
32
|
minitest (>= 5.1)
|
29
33
|
tzinfo (~> 2.0)
|
30
34
|
ast (2.4.2)
|
35
|
+
bigdecimal (3.1.8)
|
31
36
|
builder (3.2.4)
|
32
37
|
concurrent-ruby (1.2.0)
|
33
38
|
crass (1.0.6)
|
34
39
|
diff-lcs (1.5.0)
|
35
40
|
ecs-logging (1.0.0)
|
36
41
|
erubi (1.12.0)
|
42
|
+
google-protobuf (4.27.4-x86_64-linux)
|
43
|
+
bigdecimal
|
44
|
+
rake (>= 13)
|
45
|
+
googleapis-common-protos-types (1.15.0)
|
46
|
+
google-protobuf (>= 3.18, < 5.a)
|
37
47
|
i18n (1.12.0)
|
38
48
|
concurrent-ruby (~> 1.0)
|
39
49
|
lograge (0.12.0)
|
@@ -49,6 +59,62 @@ GEM
|
|
49
59
|
minitest (5.17.0)
|
50
60
|
nokogiri (1.14.1-x86_64-linux)
|
51
61
|
racc (~> 1.4)
|
62
|
+
opentelemetry-api (1.3.0)
|
63
|
+
opentelemetry-common (0.21.0)
|
64
|
+
opentelemetry-api (~> 1.0)
|
65
|
+
opentelemetry-exporter-otlp (0.28.1)
|
66
|
+
google-protobuf (>= 3.18)
|
67
|
+
googleapis-common-protos-types (~> 1.3)
|
68
|
+
opentelemetry-api (~> 1.1)
|
69
|
+
opentelemetry-common (~> 0.20)
|
70
|
+
opentelemetry-sdk (~> 1.2)
|
71
|
+
opentelemetry-semantic_conventions
|
72
|
+
opentelemetry-instrumentation-action_mailer (0.1.0)
|
73
|
+
opentelemetry-api (~> 1.0)
|
74
|
+
opentelemetry-instrumentation-active_support (~> 0.1)
|
75
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
76
|
+
opentelemetry-instrumentation-action_pack (0.9.0)
|
77
|
+
opentelemetry-api (~> 1.0)
|
78
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
79
|
+
opentelemetry-instrumentation-rack (~> 0.21)
|
80
|
+
opentelemetry-instrumentation-action_view (0.7.3)
|
81
|
+
opentelemetry-api (~> 1.0)
|
82
|
+
opentelemetry-instrumentation-active_support (~> 0.6)
|
83
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
84
|
+
opentelemetry-instrumentation-active_job (0.7.7)
|
85
|
+
opentelemetry-api (~> 1.0)
|
86
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
87
|
+
opentelemetry-instrumentation-active_record (0.7.4)
|
88
|
+
opentelemetry-api (~> 1.0)
|
89
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
90
|
+
opentelemetry-instrumentation-active_support (0.6.0)
|
91
|
+
opentelemetry-api (~> 1.0)
|
92
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
93
|
+
opentelemetry-instrumentation-base (0.22.6)
|
94
|
+
opentelemetry-api (~> 1.0)
|
95
|
+
opentelemetry-common (~> 0.21)
|
96
|
+
opentelemetry-registry (~> 0.1)
|
97
|
+
opentelemetry-instrumentation-rack (0.24.6)
|
98
|
+
opentelemetry-api (~> 1.0)
|
99
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
100
|
+
opentelemetry-instrumentation-rails (0.31.2)
|
101
|
+
opentelemetry-api (~> 1.0)
|
102
|
+
opentelemetry-instrumentation-action_mailer (~> 0.1.0)
|
103
|
+
opentelemetry-instrumentation-action_pack (~> 0.9.0)
|
104
|
+
opentelemetry-instrumentation-action_view (~> 0.7.0)
|
105
|
+
opentelemetry-instrumentation-active_job (~> 0.7.0)
|
106
|
+
opentelemetry-instrumentation-active_record (~> 0.7.0)
|
107
|
+
opentelemetry-instrumentation-active_support (~> 0.6.0)
|
108
|
+
opentelemetry-instrumentation-base (~> 0.22.1)
|
109
|
+
opentelemetry-registry (0.3.1)
|
110
|
+
opentelemetry-api (~> 1.1)
|
111
|
+
opentelemetry-sdk (1.5.0)
|
112
|
+
opentelemetry-api (~> 1.1)
|
113
|
+
opentelemetry-common (~> 0.20)
|
114
|
+
opentelemetry-registry (~> 0.2)
|
115
|
+
opentelemetry-semantic_conventions
|
116
|
+
opentelemetry-semantic_conventions (1.10.1)
|
117
|
+
opentelemetry-api (~> 1.0)
|
52
118
|
parallel (1.22.1)
|
53
119
|
parser (3.2.1.1)
|
54
120
|
ast (~> 2.4.1)
|
@@ -129,6 +195,10 @@ DEPENDENCIES
|
|
129
195
|
ecs-logging (~> 1.0)
|
130
196
|
lograge
|
131
197
|
logstash-event
|
198
|
+
opentelemetry-api
|
199
|
+
opentelemetry-exporter-otlp
|
200
|
+
opentelemetry-instrumentation-rails
|
201
|
+
opentelemetry-sdk
|
132
202
|
rake (~> 13.0)
|
133
203
|
researchable_loggable!
|
134
204
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -61,7 +61,11 @@ If loggable detects the presence of this gem, it will inject `transaction.id`, `
|
|
61
61
|
For a brand new Rails application, adding this gem to the Gemfile should be all the configuration that is needed. This
|
62
62
|
gem will automatically configure the Rails logger and lograge to follow the Researchable standard.
|
63
63
|
|
64
|
-
|
64
|
+
|
65
|
+
### Parameters
|
66
|
+
This are the parameters that can be configured in the `config.loggable` namespace:
|
67
|
+
|
68
|
+
`production_like`. By default loggable will only
|
65
69
|
modify how the logs look on production. This is because the format that this gem enforces is slightly less
|
66
70
|
human readable (in favour of machine readability and compatibility with the Elastic Common Schema) than the default
|
67
71
|
Rails one. For development, the more human readable format is preferred. However, if you want to override this and
|
@@ -71,6 +75,12 @@ are developing against this gem) then you may add the following to your `config/
|
|
71
75
|
config.loggable.production_like = true
|
72
76
|
```
|
73
77
|
|
78
|
+
`current_user_method`. This is the name of the method that will be called on the controller to get the current user. By default this is set to `current_user`. If you want to override this, you may add the following to your `config/application.rb` file:
|
79
|
+
```ruby
|
80
|
+
config.loggable.current_user_method = :my_current_user_method
|
81
|
+
```
|
82
|
+
This method is used for ECS logging, if the method is not found, the user.id field will be set to nil.
|
83
|
+
|
74
84
|
No other configuration options are provided because this gem seeks to enforce consistency across all applications.
|
75
85
|
|
76
86
|
For applications that already had some level of log customization, some cleanup might be needed:
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'opentelemetry/sdk'
|
4
|
+
require 'opentelemetry/instrumentation/all'
|
5
|
+
|
6
|
+
module Loggable
|
7
|
+
# The OpenTelemetryConfig module provides a method to configure OpenTelemetry for Rails applications.
|
8
|
+
# It sets up the instrumentation and tracing with a specified service name, relying on environment
|
9
|
+
# variables for exporter configuration, such as sending traces to a remote backend like Grafana Cloud.
|
10
|
+
module OpenTelemetryConfig
|
11
|
+
# Configures OpenTelemetry for the application
|
12
|
+
def self.configure(service_name)
|
13
|
+
::OpenTelemetry::SDK.configure do |c|
|
14
|
+
c.use_all
|
15
|
+
c.service_name = service_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/loggable/railtie.rb
CHANGED
@@ -9,15 +9,19 @@ module Loggable
|
|
9
9
|
# We add a new loggable namespace to the config object, to keep all the configuration related to this gem organized
|
10
10
|
config.loggable = ActiveSupport::OrderedOptions.new
|
11
11
|
config.loggable.production_like = false
|
12
|
+
config.loggable.current_user_method = :current_user
|
12
13
|
|
13
14
|
# Initializer runs before initialize_logger (found in Bootstrap) so from the very beginning we are logging using
|
14
15
|
# the ecs format, even during the initialization process
|
16
|
+
# rubocop:disable Metrics/BlockLength
|
15
17
|
initializer :loggable_web, before: :initialize_logger do
|
16
18
|
Rails.application.configure do
|
17
19
|
production_like = Rails.env.production? || config.loggable.production_like
|
18
20
|
if production_like
|
19
21
|
Rails.logger = ::EcsLogging::Logger.new($stdout)
|
20
22
|
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase || 'INFO')
|
23
|
+
|
24
|
+
Loggable::OpenTelemetryConfig.configure(Rails.application.class.module_parent_name.underscore.dasherize)
|
21
25
|
end
|
22
26
|
|
23
27
|
# lograge configuration
|
@@ -25,10 +29,13 @@ module Loggable
|
|
25
29
|
config.lograge.base_controller_class = 'ApplicationController'
|
26
30
|
config.lograge.custom_payload do |controller|
|
27
31
|
response_code = controller.response.code
|
32
|
+
if controller.respond_to?(config.loggable.current_user_method)
|
33
|
+
user_id = controller.send(config.loggable.current_user_method).try(:id)
|
34
|
+
end
|
28
35
|
{
|
29
36
|
ecs: {
|
30
37
|
'source.ip': controller.request.ip,
|
31
|
-
'user.id':
|
38
|
+
'user.id': user_id,
|
32
39
|
'http.code': response_code
|
33
40
|
},
|
34
41
|
status: response_code
|
@@ -41,6 +48,7 @@ module Loggable
|
|
41
48
|
config.lograge.formatter = Loggable::Lograge::Formatter.new if production_like
|
42
49
|
end
|
43
50
|
end
|
51
|
+
# rubocop:enable Metrics/BlockLength
|
44
52
|
|
45
53
|
initializer :loggable_worker, before: :initializer_logger do
|
46
54
|
Rails.application.configure do
|
@@ -48,6 +56,8 @@ module Loggable
|
|
48
56
|
if Rails.env.production? || config.loggable.production_like
|
49
57
|
Delayed::Worker.logger = ::EcsLogging::Logger.new($stdout)
|
50
58
|
Delayed::Worker.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase || 'INFO')
|
59
|
+
Loggable::OpenTelemetryConfig.configure("#{Rails.application.class.module_parent_name.underscore.dasherize}
|
60
|
+
-worker")
|
51
61
|
else
|
52
62
|
Delayed::Worker.logger = Logger.new($stdout)
|
53
63
|
Delayed::Worker.logger.level = Logger::DEBUG
|
data/lib/loggable/version.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'loggable/version'
|
4
4
|
require_relative 'loggable/railtie' if defined?(Rails::Railtie)
|
5
|
+
require_relative 'loggable/opentelemetry_config'
|
5
6
|
require_relative 'loggable/ecs_logging/formatter_monkey_patch'
|
6
7
|
require_relative 'loggable/lograge/formatter'
|
7
8
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: researchable_loggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Researchable
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecs-logging
|
@@ -52,6 +52,48 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: opentelemetry-exporter-otlp
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.28'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.28'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: opentelemetry-instrumentation-all
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.63'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.63'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: opentelemetry-sdk
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.5'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.5'
|
55
97
|
description: |2
|
56
98
|
Researchable's Loggable relies on lograge and elastic's ecs format to log events in a way that is easy to ingest by
|
57
99
|
logstash. This enables log correlation with traces across multiple services.
|
@@ -74,6 +116,7 @@ files:
|
|
74
116
|
- Rakefile
|
75
117
|
- lib/loggable/ecs_logging/formatter_monkey_patch.rb
|
76
118
|
- lib/loggable/lograge/formatter.rb
|
119
|
+
- lib/loggable/opentelemetry_config.rb
|
77
120
|
- lib/loggable/railtie.rb
|
78
121
|
- lib/loggable/version.rb
|
79
122
|
- lib/researchable_loggable.rb
|
@@ -81,13 +124,13 @@ files:
|
|
81
124
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/prerelease/lib/test-gem/version.rb
|
82
125
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb
|
83
126
|
- sig/loggable.rbs
|
84
|
-
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0
|
127
|
+
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.2.0/README.md
|
85
128
|
licenses:
|
86
129
|
- MIT
|
87
130
|
metadata:
|
88
|
-
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0
|
131
|
+
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.2.0/README.md
|
89
132
|
source_code_uri: https://gitlab.com/researchable/general/gems/loggable
|
90
|
-
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.0
|
133
|
+
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.2.0/CHANGELOG.md
|
91
134
|
post_install_message:
|
92
135
|
rdoc_options: []
|
93
136
|
require_paths:
|
@@ -103,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
146
|
- !ruby/object:Gem::Version
|
104
147
|
version: '0'
|
105
148
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.5.11
|
107
150
|
signing_key:
|
108
151
|
specification_version: 4
|
109
152
|
summary: Researchable's gem to standardize logging on all Rails applications.
|