epsagon 0.0.23 → 0.0.24

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: 9067624373427de33a82ba42e8b58bcf6d102ed85b8aaf24c69f511e628f2329
4
- data.tar.gz: 2532583c2fb18426b046df27fca70adeff280c9ca6178e5188b905e6e17caa06
3
+ metadata.gz: 4f90417afae2709a9a4dbc88f2edab85cea49ff77577048808401f981cba0a96
4
+ data.tar.gz: '0811d976ea61bce684d2da4322fb2493b37b58af0c269b1ff785cdede6b5fad2'
5
5
  SHA512:
6
- metadata.gz: e1b93087e00032717588067013467eacc613418e20792aa86c36d2840d6fc13052971793d34bf4c8c47a83e677a174adfd2d6f45e150de058910214e19596799
7
- data.tar.gz: 2711a7e340eb7bc768970de0cb88112dd743ecbc843285c1d3daaf4e437b6cec30550dea24f8232dce008209d78a9d05ed42b9cc2f70eca8eb3315011ce48f9f
6
+ metadata.gz: 560b2ea93192ed4502f261433728983544f3696378c846df19734602187335f6a155b52bbbaf7c424aca161727b09b37477b7f5a25b2d0711045a9a6c61b40dd
7
+ data.tar.gz: 5f3a848235508e9adc51555d6ebf2c107dcedde0aba4a0da37d961e37fa143064968cceca46170e9bdd92fc3bcbd8f980f4b7cbf9d7503eb2b77659e98d976fe
data/lib/epsagon.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
-
2
+ require 'json'
3
3
  require 'rubygems'
4
4
  require 'net/http'
5
5
  require 'bundler/setup'
6
6
  require 'opentelemetry/sdk'
7
7
  require 'opentelemetry/exporter/otlp'
8
+ require 'opentelemetry/instrumentation/sidekiq'
8
9
 
9
10
  require_relative 'instrumentation/sinatra'
10
11
  require_relative 'instrumentation/net_http'
@@ -55,8 +56,7 @@ module Epsagon
55
56
  configurator.use 'EpsagonFaradayInstrumentation', { epsagon: @@epsagon_config }
56
57
  configurator.use 'EpsagonAwsSdkInstrumentation', { epsagon: @@epsagon_config }
57
58
  configurator.use 'EpsagonRailsInstrumentation', { epsagon: @@epsagon_config }
58
- # configurator.use 'OpenTelemetry::Instrumentation::Sidekiq'
59
-
59
+ configurator.use 'OpenTelemetry::Instrumentation::Sidekiq', { epsagon: @@epsagon_config }
60
60
 
61
61
  if @@epsagon_config[:debug]
62
62
  configurator.add_span_processor OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
@@ -105,7 +105,69 @@ module SpanExtension
105
105
  end
106
106
  end
107
107
 
108
+ module SidekiqClientMiddlewareExtension
109
+
110
+ def call(_worker_class, job, _queue, _redis_pool)
111
+ config = OpenTelemetry::Instrumentation::Sidekiq::Instrumentation.instance.config[:epsagon] || {}
112
+ attributes = {
113
+ 'operation' => job['at'] ? 'perform_at' : 'perform_async',
114
+ 'messaging.system' => 'sidekiq',
115
+ 'messaging.sidekiq.job_class' => job['wrapped']&.to_s || job['class'],
116
+ 'messaging.message_id' => job['jid'],
117
+ 'messaging.destination' => job['queue'],
118
+ 'messaging.destination_kind' => 'queue',
119
+ 'messaging.sidekiq.redis_url' => Sidekiq.options['url'] || Util.redis_default_url
120
+ }
121
+ unless config[:metadata_only]
122
+ attributes.merge!({
123
+ 'messaging.sidekiq.args' => JSON.dump(job['args'])
124
+ })
125
+ end
126
+ tracer.in_span(
127
+ job['queue'],
128
+ attributes: attributes,
129
+ kind: :producer
130
+ ) do |span|
131
+ OpenTelemetry.propagation.text.inject(job)
132
+ span.add_event('created_at', timestamp: job['created_at'])
133
+ Util.untraced {yield}
134
+ end
135
+ end
136
+ end
137
+
138
+ module SidekiqServerMiddlewareExtension
139
+ def call(_worker, msg, _queue)
140
+ config = OpenTelemetry::Instrumentation::Sidekiq::Instrumentation.instance.config[:epsagon] || {}
141
+ parent_context = OpenTelemetry.propagation.text.extract(msg)
142
+ attributes = {
143
+ 'operation' => 'perform',
144
+ 'messaging.system' => 'sidekiq',
145
+ 'messaging.sidekiq.job_class' => msg['wrapped']&.to_s || msg['class'],
146
+ 'messaging.message_id' => msg['jid'],
147
+ 'messaging.destination' => msg['queue'],
148
+ 'messaging.destination_kind' => 'queue',
149
+ 'messaging.sidekiq.redis_url' => Sidekiq.options['url'] || Util.redis_default_url
150
+ }
151
+ unless config[:metadata_only]
152
+ attributes.merge!({
153
+ 'messaging.sidekiq.args' => JSON.dump(msg['args'])
154
+ })
155
+ end
156
+ tracer.in_span(
157
+ msg['queue'],
158
+ attributes: attributes,
159
+ with_parent: parent_context,
160
+ kind: :consumer
161
+ ) do |span|
162
+ span.add_event('created_at', timestamp: msg['created_at'])
163
+ span.add_event('enqueued_at', timestamp: msg['enqueued_at'])
164
+ yield
165
+ end
166
+ end
167
+ end
168
+
108
169
  # monkey patch to include epsagon confs
170
+
109
171
  module OpenTelemetry
110
172
  # monkey patch inner SDK module
111
173
  module SDK
@@ -122,4 +184,35 @@ module OpenTelemetry
122
184
  end
123
185
  end
124
186
  end
187
+ module Instrumentation
188
+ module Sidekiq
189
+ class Instrumentation
190
+ def add_server_middleware
191
+ ::Sidekiq.configure_server do |config|
192
+ config.server_middleware do |chain|
193
+ chain.add Middlewares::Server::TracerMiddleware
194
+ end
195
+ end
196
+
197
+ if defined?(::Sidekiq::Testing) # rubocop:disable Style/GuardClause
198
+ ::Sidekiq::Testing.server_middleware do |chain|
199
+ chain.add Middlewares::Server::TracerMiddleware
200
+ end
201
+ end
202
+ end
203
+ end
204
+ module Middlewares
205
+ module Client
206
+ class TracerMiddleware
207
+ prepend SidekiqClientMiddlewareExtension
208
+ end
209
+ end
210
+ module Server
211
+ class TracerMiddleware
212
+ prepend SidekiqServerMiddlewareExtension
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
125
218
  end
@@ -1,3 +1,3 @@
1
1
  module EpsagonConstants
2
- VERSION = '0.0.23'
2
+ VERSION = '0.0.24'
3
3
  end
File without changes
data/lib/util.rb CHANGED
@@ -30,4 +30,13 @@ module Util
30
30
  value
31
31
  end
32
32
  end
33
+
34
+ def self.redis_default_url
35
+ @@redis_default_url ||= "#{Redis::Client::DEFAULTS[:scheme]}://#{Redis::Client::DEFAULTS[:host]}:#{Redis::Client::DEFAULTS[:port]}/#{Redis::Client::DEFAULTS[:db]}"
36
+ end
37
+
38
+ def self.untraced(&block)
39
+ OpenTelemetry::Trace.with_span(OpenTelemetry::Trace::Span.new, &block)
40
+ end
41
+
33
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epsagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Epsagon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -100,6 +100,7 @@ files:
100
100
  - lib/instrumentation/net_http.rb
101
101
  - lib/instrumentation/rails.rb
102
102
  - lib/instrumentation/sinatra.rb
103
+ - lib/instrumentation/version.rb
103
104
  - lib/util.rb
104
105
  homepage: https://github.com/epsagon/epsagon-ruby
105
106
  licenses: