ecs_log_rails 0.1.2 → 0.1.3

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: cd1b34b42d808de7704a6bc3fcd5240589b8564eb2f352e2b4ab57b8198919da
4
- data.tar.gz: bcfc234ba61e9f281719da5b3e2db82dcba3f23b4e75fea51e964e1d5c2b692a
3
+ metadata.gz: 28a63bf2598536867a77136433f3f9e44985b62615bcd309fc531b91e41c3bb5
4
+ data.tar.gz: 1da522e5fba13277f146e84ca3feafaf0de91be4548ae9ed040a3f21bad7360f
5
5
  SHA512:
6
- metadata.gz: 346417ab21c86105bce5f6a1dd8bda4de0c31126d70418b5142f6c99c31c7f1e9f992c3c21162233826a2410f32578b0b7f4c5fc9b890c93c8af3842a8dec3ae
7
- data.tar.gz: 2fa28ac0d4ad163d9dd9336a9ec705b1713f4e3395453252a0f869e2be2af6c5c35a22eab52ce40b2b3fefdde044ce9e050d73452a9cb4b0e7dca7288889adc6
6
+ metadata.gz: 2cffef1b4fbf4bc502648b47e9b9df98582b26ec07303b39efa76b8767be1eaa4e9dfac14f36d12d8d4a32303afb44ccd5e7a6df779bf2cd23d33d85553f3795
7
+ data.tar.gz: 712e02233731889aba67e39d16414508c5ae7b2de3d924e8700c2ccc6848a90be9af45925108d33e40d0797197eeef4e3d0ff6b610969c84162f490dae64b88a
@@ -26,6 +26,7 @@ class EcsFormatter
26
26
  add_source
27
27
  add_destination
28
28
  add_service
29
+ add_apm_trace
29
30
  add_rails
30
31
  add_error
31
32
  add_custom_payload
@@ -84,6 +85,20 @@ class EcsFormatter
84
85
  })
85
86
  end
86
87
 
88
+ def add_apm_trace
89
+ ecs_add(:trace, {
90
+ id: data[:apm_trace_id]
91
+ })
92
+
93
+ ecs_add(:transaction, {
94
+ id: data[:apm_transaction_id]
95
+ })
96
+
97
+ ecs_add(:span, {
98
+ id: data[:apm_span_id]
99
+ })
100
+ end
101
+
87
102
  def add_rails
88
103
  ecs_add(:rails, {
89
104
  controller: data[:controller],
@@ -10,6 +10,7 @@ module EcsLogRails
10
10
  config.ecs_log_rails.log_file = File.join("log", "ecs_log_rails.log")
11
11
  config.ecs_log_rails.service_env = Rails.env
12
12
  config.ecs_log_rails.service_type = "rails"
13
+ config.ecs_log_rails.log_correlation = false
13
14
 
14
15
  config.after_initialize do |app|
15
16
  app.config.ecs_log_rails.service_name ||= Rails.application.class.module_parent.name
@@ -1,3 +1,3 @@
1
1
  module EcsLogRails
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
data/lib/ecs_log_rails.rb CHANGED
@@ -8,6 +8,7 @@ module EcsLogRails
8
8
 
9
9
  def setup(app)
10
10
  self.application = app
11
+ validate_log_correlation!
11
12
  setup_lograge
12
13
  setup_custom_payload
13
14
  setup_logger
@@ -19,7 +20,7 @@ module EcsLogRails
19
20
  application.config.lograge.keep_original_rails_log = ecs_log_rails_config.keep_original_rails_log
20
21
  # custom options
21
22
  application.config.lograge.custom_options = ->(event) do
22
- {
23
+ options = {
23
24
  original_url: event.payload[:request]&.original_url,
24
25
  remote_ip: event.payload[:request]&.remote_ip,
25
26
  ip: event.payload[:request]&.ip,
@@ -29,6 +30,18 @@ module EcsLogRails
29
30
  exception: event.payload[:exception],
30
31
  exception_object: event.payload[:exception_object]
31
32
  }
33
+
34
+ if ecs_log_rails_config.log_correlation
35
+ # Note: ElasticAPM.log_ids can yield nil values, or an empty string if called without a block,
36
+ # when there's no active transaction/span. We use this signature to have more control.
37
+ ElasticAPM.log_ids do |transaction_id, span_id, trace_id|
38
+ options[:apm_transaction_id] = transaction_id if transaction_id
39
+ options[:apm_span_id] = span_id if span_id
40
+ options[:apm_trace_id] = trace_id if trace_id
41
+ end
42
+ end
43
+
44
+ options
32
45
  end
33
46
  Lograge.setup(application)
34
47
  end
@@ -71,5 +84,14 @@ module EcsLogRails
71
84
  def ecs_log_rails_config
72
85
  application.config.ecs_log_rails
73
86
  end
87
+
88
+ def validate_log_correlation!
89
+ return unless ecs_log_rails_config.log_correlation
90
+
91
+ unless defined?(ElasticAPM)
92
+ raise "EcsLogRails log_correlation is enabled but ElasticAPM is not defined. " \
93
+ "Please add 'elastic-apm' gem to your Gemfile to be able to use log_correlation."
94
+ end
95
+ end
74
96
  end
75
97
  require "ecs_log_rails/railtie" if defined?(Rails)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_log_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Coda Zabetta
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-06-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: lograge
@@ -55,7 +54,6 @@ homepage: https://github.com/vicvega/ecs_log_rails
55
54
  licenses:
56
55
  - MIT
57
56
  metadata: {}
58
- post_install_message:
59
57
  rdoc_options: []
60
58
  require_paths:
61
59
  - lib
@@ -70,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
68
  - !ruby/object:Gem::Version
71
69
  version: '0'
72
70
  requirements: []
73
- rubygems_version: 3.4.10
74
- signing_key:
71
+ rubygems_version: 4.0.6
75
72
  specification_version: 4
76
73
  summary: Elastic Common Schema for rails' logs
77
74
  test_files: []