lenjador 2.1.0 → 2.2.0

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: 5d96edbeff69ee13444e45a5924d8fedd4907725831f9ce62fd2f3280b48b244
4
- data.tar.gz: b7e501d6a7dba6b7461df12e72530796900a4241700dd676c48d6e6f8341e0b2
3
+ metadata.gz: f6196d724a25318d7d37585d8240aeadf4539730a3d2456852e99f00a703ad60
4
+ data.tar.gz: aefd0d89ad20ed8f1decdd5e084adee315fdc6dbc14702fc26747f83b81274ec
5
5
  SHA512:
6
- metadata.gz: b1142e4a26fb13f3ba2d880de8c3b58e18eacc77de055d36b10c3a9783c6c1d597a50aab94f1611a43fc17f8490f6598049da6f5d4c9ed73af77be2fa5ccb26e
7
- data.tar.gz: 6f6d29354c80eae57485fc2f3fa5f6e0643aad692763957ab43c8ba3041a8f5d9cbba6fb3e9453a121c6634d5e7e776d82df0286a966b97613d03c437b602827
6
+ metadata.gz: 74e4d77b7bbe1867605dac6cd7edfa7e5b7ff5fdf7d2699422c49a0bd6168d531174d7f4c2f594b104afb4e90eaf5d0926c595d5543f3c56bea16d156465a283
7
+ data.tar.gz: 1bb069818e94912e408cd7cd95fa09db743336dd3242ebccd1b0029cb887b3dcf223cc4aa207ee2f543dac9044b38e6549ace8efe24453a4aae8f1380c898ccc
data/lenjador.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = 'lenjador'
8
- gem.version = '2.1.0'
8
+ gem.version = '2.2.0'
9
9
  gem.authors = ['Salemove']
10
10
  gem.email = ['support@salemove.com']
11
11
  gem.description = "It's lenjadoric"
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
23
23
 
24
24
  gem.add_development_dependency 'benchmark-ips'
25
25
  gem.add_development_dependency 'bundler'
26
+ gem.add_development_dependency 'opentelemetry-api'
26
27
  gem.add_development_dependency 'pry'
27
28
  gem.add_development_dependency 'rake'
28
29
  gem.add_development_dependency 'rspec'
@@ -5,7 +5,6 @@ class Lenjador
5
5
  class StdoutJsonAdapter
6
6
  def initialize(service_name)
7
7
  @application_name = Utils.application_name(service_name)
8
- @mutex = Mutex.new if RUBY_ENGINE == 'jruby'
9
8
  end
10
9
 
11
10
  def log(level, metadata = {})
@@ -20,10 +19,6 @@ class Lenjador
20
19
  def print_line(str)
21
20
  $stdout.puts(str)
22
21
  end
23
- elsif RUBY_ENGINE == 'jruby'
24
- def print_line(str)
25
- @mutex.synchronize { $stdout.write("#{str}\n") }
26
- end
27
22
  else
28
23
  def print_line(str)
29
24
  $stdout.write("#{str}\n")
@@ -63,17 +63,37 @@ class Lenjador
63
63
  word
64
64
  end
65
65
 
66
- # Tracing information
67
- #
68
- # Tracing information is included only if OpenTracing is defined and if it
69
- # supports method called `active_span` (version >= 0.4.1). We use
70
- # SpanContext#trace_id and SpanContext#span_id methods to retrieve tracing
71
- # information. These methods are not yet supported by the OpenTracing API,
72
- # so we first check if these methods exist. Popular tracing libraries
73
- # already implement them. These methods are likely to be added to the API
74
- # very soon: https://github.com/opentracing/specification/blob/master/rfc/trace_identifiers.md
75
66
  def self.tracing_information
76
- return NO_TRACE_INFORMATION if !defined?(OpenTracing) || !OpenTracing.respond_to?(:active_span)
67
+ tracing_information_from_opentelemetry ||
68
+ tracing_information_from_opentracing ||
69
+ NO_TRACE_INFORMATION
70
+ end
71
+ private_class_method :tracing_information
72
+
73
+ def self.tracing_information_from_opentelemetry
74
+ return nil unless defined?(OpenTelemetry)
75
+
76
+ current_span_context = OpenTelemetry::Trace.current_span.context
77
+ return nil unless current_span_context.valid?
78
+
79
+ {
80
+ trace_id: current_span_context.hex_trace_id,
81
+ span_id: current_span_context.hex_span_id
82
+ }
83
+ end
84
+ private_class_method :tracing_information_from_opentelemetry
85
+
86
+ # Tracing information is included only if OpenTracing supports method
87
+ # called `active_span` (version >= 0.4.1). We use SpanContext#trace_id and
88
+ # SpanContext#span_id methods to retrieve tracing information. These
89
+ # methods are not yet supported by the OpenTracing API, so we first check
90
+ # if these methods exist. Popular tracing libraries already implement them.
91
+ # These methods are likely to be added to the API very soon:
92
+ # https://github.com/opentracing/specification/blob/master/rfc/trace_identifiers.md
93
+ #
94
+ # @deprecated Use OpenTelemetry instead
95
+ def self.tracing_information_from_opentracing
96
+ return nil if !defined?(OpenTracing) || !OpenTracing.respond_to?(:active_span)
77
97
 
78
98
  context = OpenTracing.active_span&.context
79
99
  if context && context.respond_to?(:trace_id) && context.respond_to?(:span_id)
@@ -81,10 +101,8 @@ class Lenjador
81
101
  trace_id: context.trace_id,
82
102
  span_id: context.span_id
83
103
  }
84
- else
85
- NO_TRACE_INFORMATION
86
104
  end
87
105
  end
88
- private_class_method :tracing_information
106
+ private_class_method :tracing_information_from_opentracing
89
107
  end
90
108
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
+ require 'opentelemetry-api'
4
5
 
5
6
  describe Lenjador::Utils do
6
7
  let(:now) { Time.utc(2015, 10, 11, 23, 10, 21, 123_456) }
@@ -46,6 +47,27 @@ describe Lenjador::Utils do
46
47
  end
47
48
  end
48
49
 
50
+ context 'when OpenTelemetry is defined' do
51
+ it 'includes trace information' do
52
+ provider = OpenTelemetry.tracer_provider
53
+
54
+ tracer = provider.tracer('my_app', '1.0')
55
+ recorded_event = tracer.in_span('my_task') do |_task_span|
56
+ event
57
+ end
58
+
59
+ expect(recorded_event).to include(
60
+ trace_id: instance_of(String),
61
+ span_id: instance_of(String)
62
+ )
63
+ end
64
+
65
+ it 'does not include trace information if span is invalid' do
66
+ expect(OpenTelemetry::Trace.current_span.context).not_to be_valid
67
+ expect(event).not_to include(:trace_id, :span_id)
68
+ end
69
+ end
70
+
49
71
  context 'when OpenTracing is defined' do # rubocop:disable RSpec/MultipleMemoizedHelpers
50
72
  let(:trace_id) { 'trace-id' }
51
73
  let(:span_id) { 'span-id' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lenjador
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-21 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: opentelemetry-api
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement