loga 2.7.0 → 2.8.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: 8a97eae050b9e31ef0ddb1e6f327563c4e0f54eb1a42ea7bb53b03e22c8fb9c9
4
- data.tar.gz: 771373253651884fead19e93038d5c7e31827d3c562d2cd748e0acd66f31124e
3
+ metadata.gz: dc1346e981871beb7504038280a989df0b08f8758de0aafbc2ad6353bf15b37b
4
+ data.tar.gz: 7cca9a16fd0d79616445d8b497d28064b4e62c5b9ec075594787e069020d031c
5
5
  SHA512:
6
- metadata.gz: 28d17a44bf2c8c0a919916438c8935a4033e14176185ca87ff69987ee03507dee5ae854c2887ff89d174c78fd0fa846b8d8237392b6705eb552365202f2f7680
7
- data.tar.gz: 45bf838fa85c9a3a01ba1134034b2ab2e577cd9f9c28ecceaf175935ff69627f156856dc8e383b5212829636934657ee4fb0c40f5e5e992a54eb1027ee47d74f
6
+ metadata.gz: 9b644025cbf6f8ff20b5980d8c261146a3832b2ea0e18eec3efabd1c8d7fbb75b540591fe5eb480a3475c8e646a85fd274a2352c9ed95baebf84ec01c29c8a8b
7
+ data.tar.gz: 5b5b9ae15e5383bb6b8b48e2a990b340134c2e77391fef261a275ae47e41b95538a9ba95553820d335634bdd8cbd1530f839bae8dade08b8bfd57af18dfd15aa
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [2.8.0] - 2023-11-14
8
+ ### Added
9
+ - Support open-telemetry and add trace_id and span_id to logs events
10
+
7
11
  ## [2.7.0] - 2023-03-28
8
12
  ### Added
9
13
  - Support for sidekiq 7
@@ -39,12 +39,7 @@ module Loga
39
39
  private
40
40
 
41
41
  def build_event(time, message)
42
- event = case message
43
- when Loga::Event
44
- message
45
- else
46
- Loga::Event.new(message: message)
47
- end
42
+ event = message.is_a?(Loga::Event) ? message : Loga::Event.new(message: message)
48
43
 
49
44
  event.timestamp ||= time
50
45
  # Overwrite sidekiq_context data anything manually specified
@@ -54,6 +49,7 @@ module Loga
54
49
  hash.merge! compute_type(event.type)
55
50
  # Overwrite hash with Loga's additional fields
56
51
  hash.merge! loga_additional_fields
52
+ hash.merge! open_telemetry_fields
57
53
  end
58
54
  event
59
55
  end
@@ -103,6 +99,17 @@ module Loga
103
99
  }
104
100
  end
105
101
 
102
+ def open_telemetry_fields
103
+ return {} unless defined?(::OpenTelemetry::Trace)
104
+
105
+ span = ::OpenTelemetry::Trace.current_span
106
+
107
+ {
108
+ trace_id: span.context.hex_trace_id,
109
+ span_id: span.context.hex_span_id,
110
+ }
111
+ end
112
+
106
113
  def sidekiq_context
107
114
  return {} unless defined?(::Sidekiq::Context)
108
115
 
data/lib/loga/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Loga
2
- VERSION = '2.7.0'.freeze
2
+ VERSION = '2.8.0'.freeze
3
3
  end
@@ -209,6 +209,29 @@ describe Loga::Formatters::GELFFormatter do
209
209
  end
210
210
  end
211
211
 
212
+ context 'when working with additional fields via otel' do
213
+ let(:options) { { message: 'Wooden house' } }
214
+ let(:message) { Loga::Event.new(options) }
215
+ let(:trace_context) { { hex_trace_id: '123', hex_span_id: '456' } }
216
+
217
+ before do
218
+ klass = Class.new do
219
+ class << self
220
+ attr_accessor :current_span
221
+ end
222
+ end
223
+ klass.current_span = OpenStruct.new(context: OpenStruct.new(trace_context))
224
+ stub_const('::OpenTelemetry::Trace', klass)
225
+ end
226
+
227
+ it 'includes the trace_id and span_id' do
228
+ expect(json['_trace_id']).to eq('123')
229
+ expect(json['_span_id']).to eq('456')
230
+ end
231
+
232
+ include_examples 'valid GELF message'
233
+ end
234
+
212
235
  {
213
236
  'DEBUG' => 7,
214
237
  'INFO' => 6,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loga
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Funding Circle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-03 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport