log_method 1.1.0 → 1.2.0

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: dd51e1c0b040a4cc45e4d687d5d856f2e7bccec8b3abc9a7805d7e8eb3e5488e
4
- data.tar.gz: 0bf8d484eb418695b4b3ce546bda78bb033124b0e9c950714cb14f90c6217815
3
+ metadata.gz: 8d10807c991e7f6c1eff009b0256157931c02cc3a08d16be9ea6d9f0024d9312
4
+ data.tar.gz: 44522431c6e794bf56295a57e4f3ef5729e47d1076d4b1f3eececb8d23a65c0d
5
5
  SHA512:
6
- metadata.gz: 3c3eb39b6bdce35dc03780555480f9e2e7ac33b0c1464b35ee0e1ba6f79ea7805cd19fee8e618b4a4b8ca044e4f82029ef943d2e13c61d10deaa77e2b04d94c4
7
- data.tar.gz: 74ceee8774b9f583dc0df50b341f4aa1f363672c3ad605e318ff736319e84b6375a164ceeceedbcd27e2e8f8dbf4ace63b5c3d23a1c6273107f314a57466454b
6
+ metadata.gz: f78bc154c16fa5a0febe3e5e0fe719ad8611acb93ae7696546acb6ea0350373b790749139e94487866d2d31a3d315c2d99d7d02da44c78dd26c6c49640089e46
7
+ data.tar.gz: b11ae0e3a527a99e5f1955b3f950066b0921d01c480ac178a1e467ef1af19c20cc9eb0413c47ff48f801d6deeeaae6070e3b6ed3f72b507a0a70a9a8fe025fc3
data/README.md CHANGED
@@ -123,7 +123,9 @@ end
123
123
  - `trace_id` - The trace id returned by `trace_id_proc`, or `nil` if that isn't configured.
124
124
  - `current_actor_id` - The value returned by; `current_actor_proc`, or `nil` if that isn't configured.
125
125
  - `log_message` - the log message passed to `log`
126
- * `current_actor_id_label` - If a current actor is logged, this is the label that will precede it in the logs
126
+
127
+ You can also pass an array of proc/lambdas and all of them will be called in order given.
128
+ * `current_actor_id_label` - If a current actor is logged, this is the label that will precede it in the logs. Default is `current_actor_id`.
127
129
  * `current_actor_proc` - Called to retrieve an identifier of the current actor executing the code, such as the current user.
128
130
  * `external_identifier_method` - If you are using external ids on your objects, this is the name of that method. If an object is passed in that responds to this method, it will be used instead of `id` when creating the log message.
129
131
  * `trace_id_proc` - returns the current request's request ID, trace ID, or cross-request ID. This is useful to tie various log messages together that were all part of a single request.
@@ -147,6 +149,37 @@ LogMethod.config do |c|
147
149
  end
148
150
  ```
149
151
 
152
+ It will log the method name as the breadcrumb (truncating to avoid Bugsnag's limits) and set these attributes:
153
+
154
+ * `class` - The name of the class that logged the message
155
+ * `object_id` - The id of the object passed, based on documentation above
156
+ * `object_class` - The name of the class of the object passed
157
+ * `trace_id` - The trace id, if configured and available
158
+ * `current_actor_id` - The id of the current actor, if configured and available. Note that this will respect the `current_actor_id_label`, so if
159
+ you have that set to `user_id`, `user_id` is used here instead of `current_actor_id`.
160
+
161
+ #### OpenTelementry Events
162
+
163
+ You can use `LogMethod::OpenTelemetryAfterLog` to send each log method as a wide event to your Open Telementry provider (e.g. Honeycomb):
164
+
165
+ ```ruby
166
+ # config/initializers/log_method.rb
167
+ require "log_method/open_telemetry_after_log"
168
+ LogMethod.config do |c|
169
+ c.after_log_proc = LogMethod::OpenTelemetryAfterLog
170
+ end
171
+ ```
172
+
173
+ This will send an event whose message is the same as your log message, along with these attributes:
174
+
175
+ * `log_method.class_name` - class that logged the message
176
+ * `log_method.method_name` - method passed to `log`
177
+ * `log_method.object_id` - object ID as described above
178
+ * `log_method.object_class_name` - class name of the passed object
179
+ * `app.trace_id` - trace id, if configured and available
180
+ * `app.current_actor_id` - current actor id, if configured and available. note that if you have configured `current_actor_id_label`, that will be
181
+ used here instead, so if if you've set it to `user_id`, this attribute will be named `app.user_id`.
182
+
150
183
  #### PaperTrail whodunnit
151
184
 
152
185
  The [PaperTrail gem](https://github.com/paper-trail-gem/paper_trail) has support for storing an actor or user along with versions created on
@@ -1,11 +1,12 @@
1
1
  class LogMethod::BugsnagAfterLog
2
2
  def self.call(class_thats_logging_name, method_name, object_id, object_class_name, trace_id, current_actor_id, _log_message)
3
+ current_actor_id_attribute = LogMethod.config.current_actor_id_label.to_sym
3
4
  Bugsnag.leave_breadcrumb method_name.to_s[0..29], {
4
5
  class: class_thats_logging_name,
5
6
  object_id: object_id,
6
7
  object_class: object_class_name,
7
8
  trace_id: trace_id,
8
- admin_user_id: current_actor_id
9
+ current_actor_id_attribute => current_actor_id,
9
10
  }, Bugsnag::Breadcrumbs::LOG_BREADCRUMB_TYPE
10
11
  end
11
12
  end
@@ -1,6 +1,6 @@
1
1
  class LogMethod::Config
2
- attr_accessor :after_log_proc,
3
- :current_actor_id_label,
2
+ attr_reader :after_log_procs
3
+ attr_accessor :current_actor_id_label,
4
4
  :current_actor_proc,
5
5
  :external_identifier_method,
6
6
  :trace_id_proc
@@ -10,13 +10,17 @@ class LogMethod::Config
10
10
  end
11
11
 
12
12
  def reset!
13
- @after_log_proc = NO_OP
13
+ @after_log_procs = []
14
14
  @current_actor_id_label = "current_actor_id"
15
15
  @current_actor_proc = NO_OP
16
16
  @external_identifier_method = nil
17
17
  @trace_id_proc = NO_OP
18
18
  end
19
19
 
20
+ def after_log_proc=(proc_or_array)
21
+ @after_log_procs = Array(proc_or_array)
22
+ end
23
+
20
24
  private
21
25
 
22
26
  NO_OP = ->(*) {}
@@ -34,18 +34,19 @@ module LogMethod::Log
34
34
 
35
35
  all_args = [self.class.name, method, object_id, object_class&.name, trace_id, current_actor_id, message]
36
36
 
37
- after_log_proc = LogMethod.config.after_log_proc
38
- arity = if after_log_proc.kind_of?(Proc)
39
- after_log_proc.arity
40
- elsif after_log_proc.respond_to?(:call)
41
- after_log_proc.method(:call).arity
42
- end
43
- args_for_arity = if arity <= 0
44
- []
45
- else
46
- all_args[0..(arity-1)]
47
- end
48
- after_log_proc.(*args_for_arity)
37
+ LogMethod.config.after_log_procs.each do |after_log_proc|
38
+ arity = if after_log_proc.kind_of?(Proc)
39
+ after_log_proc.arity
40
+ elsif after_log_proc.respond_to?(:call)
41
+ after_log_proc.method(:call).arity
42
+ end
43
+ args_for_arity = if arity <= 0
44
+ []
45
+ else
46
+ all_args[0..(arity-1)]
47
+ end
48
+ after_log_proc.(*args_for_arity)
49
+ end
49
50
  end
50
51
 
51
52
  private
@@ -0,0 +1,18 @@
1
+ class LogMethod::OpenTelemetryAfterLog
2
+ def self.call(class_thats_logging_name, method_name, object_id, object_class_name, trace_id, current_actor_id, log_message)
3
+ current_actor_id_attribute = "app.#{LogMethod.config.current_actor_id_label}"
4
+
5
+ OpenTelemetry::Trace.current_span.add_event(
6
+ log_message,
7
+ attributes: {
8
+ "log_method.class_name" => class_thats_logging_name,
9
+ "log_method.method_name" => method_name,
10
+ "log_method.object_id" => object_id,
11
+ "log_method.object_class_name" => object_class_name,
12
+ "app.trace_id" => trace_id,
13
+ current_actor_id_attribute => current_actor_id,
14
+ }
15
+ )
16
+ end
17
+ end
18
+
@@ -1,3 +1,3 @@
1
1
  module LogMethod
2
- VERSION="1.1.0"
2
+ VERSION="1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Copeland
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -63,6 +63,7 @@ files:
63
63
  - lib/log_method/bugsnag_after_log.rb
64
64
  - lib/log_method/config.rb
65
65
  - lib/log_method/log.rb
66
+ - lib/log_method/open_telemetry_after_log.rb
66
67
  - lib/log_method/paper_trail_current_actor.rb
67
68
  - lib/log_method/version.rb
68
69
  - log_method.gemspec