gitlab-labkit 0.9.1 → 0.12.1

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -1
  3. data/lib/labkit/context.rb +2 -1
  4. data/lib/labkit/middleware/sidekiq.rb +2 -0
  5. data/lib/labkit/middleware/sidekiq/client.rb +13 -6
  6. data/lib/labkit/middleware/sidekiq/context.rb +14 -0
  7. data/lib/labkit/middleware/sidekiq/context/client.rb +22 -0
  8. data/lib/labkit/middleware/sidekiq/context/server.rb +21 -0
  9. data/lib/labkit/middleware/sidekiq/server.rb +13 -5
  10. data/lib/labkit/middleware/sidekiq/tracing.rb +15 -0
  11. data/lib/labkit/middleware/sidekiq/tracing/client.rb +29 -0
  12. data/lib/labkit/middleware/sidekiq/tracing/server.rb +26 -0
  13. data/lib/labkit/middleware/sidekiq/tracing/sidekiq_common.rb +23 -0
  14. data/lib/labkit/tracing.rb +4 -0
  15. data/lib/labkit/tracing/rails.rb +8 -3
  16. data/lib/labkit/tracing/rails/abstract_instrumenter.rb +46 -0
  17. data/lib/labkit/tracing/rails/action_view.rb +16 -0
  18. data/lib/labkit/tracing/rails/action_view/render_collection_instrumenter.rb +25 -0
  19. data/lib/labkit/tracing/rails/action_view/render_partial_instrumenter.rb +20 -0
  20. data/lib/labkit/tracing/rails/action_view/render_template_instrumenter.rb +20 -0
  21. data/lib/labkit/tracing/rails/action_view/subscriber.rb +31 -0
  22. data/lib/labkit/tracing/rails/active_record.rb +14 -0
  23. data/lib/labkit/tracing/rails/active_record/sql_instrumenter.rb +30 -0
  24. data/lib/labkit/tracing/rails/active_record/subscriber.rb +25 -0
  25. data/lib/labkit/tracing/rails/active_support.rb +18 -0
  26. data/lib/labkit/tracing/rails/active_support/cache_delete_instrumenter.rb +20 -0
  27. data/lib/labkit/tracing/rails/active_support/cache_fetch_hit_instrumenter.rb +20 -0
  28. data/lib/labkit/tracing/rails/active_support/cache_generate_instrumenter.rb +20 -0
  29. data/lib/labkit/tracing/rails/active_support/cache_read_instrumenter.rb +25 -0
  30. data/lib/labkit/tracing/rails/active_support/cache_write_instrumenter.rb +20 -0
  31. data/lib/labkit/tracing/rails/active_support/subscriber.rb +35 -0
  32. data/lib/labkit/tracing/rails/rails_common.rb +2 -8
  33. data/lib/labkit/tracing/redis/redis_interceptor_helper.rb +2 -1
  34. data/lib/labkit/tracing/tracing_utils.rb +17 -3
  35. metadata +25 -9
  36. data/lib/labkit/tracing/rails/action_view_subscriber.rb +0 -70
  37. data/lib/labkit/tracing/rails/active_record_subscriber.rb +0 -52
  38. data/lib/labkit/tracing/rails/active_support_subscriber.rb +0 -86
  39. data/lib/labkit/tracing/sidekiq.rb +0 -13
  40. data/lib/labkit/tracing/sidekiq/client_middleware.rb +0 -27
  41. data/lib/labkit/tracing/sidekiq/server_middleware.rb +0 -24
  42. data/lib/labkit/tracing/sidekiq/sidekiq_common.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c6a4f92530f7662034e9a67cda9b6f1587cce729502a088ef9b6777659b0bdc
4
- data.tar.gz: 1f17a19f8e2f7a0f052c4474caaaf0fd1d3a291a77de67b4184000fb12a599de
3
+ metadata.gz: 3267849e09cf37b1f72c5c7cf0f25ac43066edd06b09ff7b8a3b93f2ee5a4f45
4
+ data.tar.gz: ae8f6710ada3fc3791ae54cba82a4f8b73c5d67003782285264246032c22328e
5
5
  SHA512:
6
- metadata.gz: 2a50b5944898571c6fa9038eed5d35ec3d560c684c7363e1779aa8b4ec1363e8533e51667ae868b961562a3d3195cc9ac1f8b27e6e76204290439a735b61f5bc
7
- data.tar.gz: d96aeafefa46bb244fc7371165fed6f91e47326d60463f8d25685d50081b63a8651c2b5dee7656094d5fb87085a58dd44459aafc64621b32a083dde3eaf7180e
6
+ metadata.gz: 33ec95dfe61241476125e718e9ae3d3145ba2d76244076cfbe164dd9b61b841d1e832dc27ef71846476ca32abe1057165f35c2b44abb3ff83bd09693a354f00b
7
+ data.tar.gz: cb7abc95873cae4e981348c28533f3c894e50b696ed87822cca9b65a6db689a4e0453b83297b667eaa88c7a879e80dfc520e56e75959431a1388bc1db622aaf3
data/README.md CHANGED
@@ -18,7 +18,8 @@ The changelog is available via [**tagged release notes**](https://gitlab.com/git
18
18
 
19
19
  LabKit-Ruby provides functionality in three areas:
20
20
 
21
- 1. `Labkit::Correlation` for handling and propagating Correlation-IDs.
21
+ 1. `Labkit::Context` used for providing context information to log messages.
22
+ 1. `Labkit::Correlation` For accessing the correlation id. (Generated and propagated by `Labkit::Context`)
22
23
  1. `Labkit::Logging` for sanitizing log messages.
23
24
  1. `Labkit::Tracing` for handling and propagating distributed traces.
24
25
 
@@ -41,3 +42,16 @@ $ bundle exec rake verify
41
42
  Note that LabKit-Ruby uses the [`rufo`](https://github.com/ruby-formatter/rufo) for auto-formatting. Please run `bundle exec rake fix` to auto-format your code before pushing.
42
43
 
43
44
  Please also review the [development section of the LabKit (go) README](https://gitlab.com/gitlab-org/labkit#developing-labkit) for details of the LabKit architectural philosophy.
45
+
46
+ ### Releasing a new version
47
+
48
+ Releasing a new version can be done by pushing a new tag, or creating
49
+ it from the
50
+ [interface](https://gitlab.com/gitlab-org/labkit-ruby/-/tags).
51
+
52
+ A new changelog will automatically be added to the release on Gitlab.
53
+
54
+ The new version will automatically be published to
55
+ [rubygems](https://rubygems.org/gems/gitlab-labkit) when the pipeline
56
+ for the tag completes. It might take a few minutes before the update
57
+ is available.
@@ -21,7 +21,8 @@ module Labkit
21
21
  LOG_KEY = "meta"
22
22
  CORRELATION_ID_KEY = "correlation_id"
23
23
  RAW_KEYS = [CORRELATION_ID_KEY].freeze
24
- KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id].freeze
24
+ KNOWN_KEYS = %w[user project root_namespace subscription_plan caller_id
25
+ related_class].freeze
25
26
 
26
27
  class << self
27
28
  def with_context(attributes = {})
@@ -6,6 +6,8 @@ module Labkit
6
6
  module Sidekiq
7
7
  autoload :Client, "labkit/middleware/sidekiq/client"
8
8
  autoload :Server, "labkit/middleware/sidekiq/server"
9
+ autoload :Context, "labkit/middleware/sidekiq/context"
10
+ autoload :Tracing, "labkit/middleware/sidekiq/tracing"
9
11
  end
10
12
  end
11
13
  end
@@ -3,14 +3,21 @@
3
3
  module Labkit
4
4
  module Middleware
5
5
  module Sidekiq
6
- # This middleware for Sidekiq-client wraps scheduling jobs in a context
7
- # The context will also be added to the sidekiq job in redis so it can
8
- # be reinstantiated by Sidekiq-server when running the job.
6
+ # This is a wrapper around all the sidekiq client-middleware in labkit
7
+ # The only middleware that needs to be added to the chain in GitLab-rails
8
+ #
9
+ # It uses a new `Sidekiq::Middleware::Chain` to string multiple middlewares
10
+ # together.
9
11
  class Client
10
- def call(_worker_class, job, _queue, _redis_pool)
11
- Labkit::Context.with_context do |context|
12
- job.merge!(context.to_h)
12
+ def self.chain
13
+ @chain ||= ::Sidekiq::Middleware::Chain.new do |chain|
14
+ chain.add Labkit::Middleware::Sidekiq::Context::Client
15
+ chain.add Labkit::Middleware::Sidekiq::Tracing::Client if Labkit::Tracing.enabled?
16
+ end
17
+ end
13
18
 
19
+ def call(*args)
20
+ self.class.chain.invoke(*args) do
14
21
  yield
15
22
  end
16
23
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ # This module contains all the sidekiq middleware regarding application
7
+ # context
8
+ module Context
9
+ autoload :Client, "labkit/middleware/sidekiq/context/client"
10
+ autoload :Server, "labkit/middleware/sidekiq/context/server"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ module Context
7
+ # This middleware for Sidekiq-client wraps scheduling jobs in a context
8
+ # The context will also be added to the sidekiq job in redis so it can
9
+ # be reinstantiated by Sidekiq-server when running the job.
10
+ class Client
11
+ def call(_worker_class, job, _queue, _redis_pool)
12
+ Labkit::Context.with_context do |context|
13
+ job.merge!(context.to_h)
14
+
15
+ yield
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ module Context
7
+ # This middleware for Sidekiq-client uses the values stored on a job to
8
+ # reinstantiate a context in which the job will run.
9
+ class Server
10
+ def call(_worker_class, job, _queue)
11
+ data = job.merge(Labkit::Context.log_key(:caller_id) => job["class"])
12
+
13
+ Labkit::Context.with_context(data) do |_context|
14
+ yield
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -3,13 +3,21 @@
3
3
  module Labkit
4
4
  module Middleware
5
5
  module Sidekiq
6
- # This middleware for Sidekiq-client uses the values stored on a job to
7
- # reinstantiate a context in which the job will run.
6
+ # This is a wrapper around all the sidekiq server-middleware in labkit
7
+ # The only middleware that needs to be added to the chain in GitLab-rails
8
+ #
9
+ # It uses a new `Sidekiq::Middleware::Chain` to string multiple middlewares
10
+ # together.
8
11
  class Server
9
- def call(_worker_class, job, _queue)
10
- data = job.merge(Labkit::Context.log_key(:caller_id) => job["class"])
12
+ def self.chain
13
+ @chain ||= ::Sidekiq::Middleware::Chain.new do |chain|
14
+ chain.add Labkit::Middleware::Sidekiq::Context::Server
15
+ chain.add Labkit::Middleware::Sidekiq::Tracing::Server if Labkit::Tracing.enabled?
16
+ end
17
+ end
11
18
 
12
- Labkit::Context.with_context(data) do |_context|
19
+ def call(*args)
20
+ self.class.chain.invoke(*args) do
13
21
  yield
14
22
  end
15
23
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ # Sidekiq provides classes for instrumenting Sidekiq client and server
7
+ # functionality
8
+ module Tracing
9
+ autoload :Client, "labkit/middleware/sidekiq/tracing/client"
10
+ autoload :Server, "labkit/middleware/sidekiq/tracing/server"
11
+ autoload :SidekiqCommon, "labkit/middleware/sidekiq/tracing/sidekiq_common"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "opentracing"
4
+
5
+ module Labkit
6
+ module Middleware
7
+ module Sidekiq
8
+ module Tracing
9
+ # Client provides a sidekiq client middleware for
10
+ # instrumenting distributed tracing calls made from the client
11
+ # application
12
+ class Client
13
+ include SidekiqCommon
14
+
15
+ SPAN_KIND = "client"
16
+
17
+ def call(_worker_class, job, _queue, _redis_pool)
18
+ Labkit::Tracing::TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span|
19
+ # Inject the details directly into the job
20
+ Labkit::Tracing::TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
21
+
22
+ yield
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "opentracing"
4
+
5
+ module Labkit
6
+ module Middleware
7
+ module Sidekiq
8
+ module Tracing
9
+ # Server provides a sidekiq server middleware for
10
+ # instrumenting distributed tracing calls when they are
11
+ # executed by the Sidekiq server
12
+ class Server
13
+ include SidekiqCommon
14
+
15
+ SPAN_KIND = "server"
16
+
17
+ def call(_worker, job, _queue)
18
+ context = Labkit::Tracing::TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, job)
19
+
20
+ Labkit::Tracing::TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", child_of: context, tags: tags_from_job(job, SPAN_KIND)) { |_span| yield }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ module Tracing
7
+ # SidekiqCommon is a mixin for the sidekiq middleware components
8
+ module SidekiqCommon
9
+ def tags_from_job(job, kind)
10
+ {
11
+ "component" => "sidekiq",
12
+ "span.kind" => kind,
13
+ "sidekiq.queue" => job["queue"],
14
+ "sidekiq.jid" => job["jid"],
15
+ "sidekiq.retry" => job["retry"].to_s,
16
+ "sidekiq.args" => job["args"]&.join(", "),
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -28,6 +28,10 @@ module Labkit
28
28
  ENV["GITLAB_TRACING_URL"]
29
29
  end
30
30
 
31
+ def self.stacktrace_operations
32
+ @stacktrace_operations ||= Set.new(ENV["GITLAB_TRACING_INCLUDE_STACKTRACE"].to_s.split(",").map(&:strip))
33
+ end
34
+
31
35
  def self.tracing_url_enabled?
32
36
  enabled? && tracing_url_template.present?
33
37
  end
@@ -4,10 +4,15 @@ module Labkit
4
4
  module Tracing
5
5
  # Rails provides classes for instrumenting Rails events
6
6
  module Rails
7
- autoload :ActionViewSubscriber, "labkit/tracing/rails/action_view_subscriber"
8
- autoload :ActiveRecordSubscriber, "labkit/tracing/rails/active_record_subscriber"
9
- autoload :ActiveSupportSubscriber, "labkit/tracing/rails/active_support_subscriber"
7
+ autoload :AbstractInstrumenter, "labkit/tracing/rails/abstract_instrumenter"
8
+ autoload :ActionView, "labkit/tracing/rails/action_view"
9
+ autoload :ActiveRecord, "labkit/tracing/rails/active_record"
10
+ autoload :ActiveSupport, "labkit/tracing/rails/active_support"
10
11
  autoload :RailsCommon, "labkit/tracing/rails/rails_common"
12
+
13
+ ActionViewSubscriber = ActionView::Subscriber
14
+ ActiveRecordSubscriber = ActiveRecord::Subscriber
15
+ ActiveSupportSubscriber = ActiveSupport::Subscriber
11
16
  end
12
17
  end
13
18
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/all"
4
+
5
+ module Labkit
6
+ module Tracing
7
+ module Rails
8
+ # https://edgeapi.rubyonrails.org/classes/ActiveSupport/Notifications/Instrumenter.html#method-c-new
9
+ class AbstractInstrumenter
10
+ def start(name, id, payload)
11
+ scope = OpenTracing.start_active_span(span_name(payload))
12
+
13
+ scope_stack.push scope
14
+ end
15
+
16
+ def finish(name, id, payload)
17
+ scope = scope_stack.pop
18
+ span = scope.span
19
+
20
+ Labkit::Tracing::TracingUtils.log_common_fields_on_span(span, span_name(payload))
21
+
22
+ exception = payload[:exception]
23
+ Labkit::Tracing::TracingUtils.log_exception_on_span(span, exception) if exception
24
+
25
+ tags(payload).each do |k, v|
26
+ span.set_tag(k, v)
27
+ end
28
+
29
+ scope.close
30
+ end
31
+
32
+ def scope_stack
33
+ Thread.current[:_labkit_trace_scope_stack] ||= []
34
+ end
35
+
36
+ def span_name(payload)
37
+ raise "span_name not implemented"
38
+ end
39
+
40
+ def tags(payload)
41
+ {}
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActionView
7
+ autoload :RenderCollectionInstrumenter, "labkit/tracing/rails/action_view/render_collection_instrumenter"
8
+ autoload :RenderPartialInstrumenter, "labkit/tracing/rails/action_view/render_partial_instrumenter"
9
+ autoload :RenderTemplateInstrumenter, "labkit/tracing/rails/action_view/render_template_instrumenter"
10
+ autoload :Subscriber, "labkit/tracing/rails/action_view/subscriber"
11
+
12
+ COMPONENT_TAG = "ActionView"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActionView
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class RenderCollectionInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "render_collection"
11
+ end
12
+
13
+ def tags(payload)
14
+ {
15
+ "component" => COMPONENT_TAG,
16
+ "template.id" => payload[:identifier],
17
+ "template.count" => payload[:count] || 0,
18
+ "template.cache.hits" => payload[:cache_hits] || 0,
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActionView
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class RenderPartialInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "render_partial"
11
+ end
12
+
13
+ def tags(payload)
14
+ { "component" => COMPONENT_TAG, "template.id" => payload[:identifier] }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActionView
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class RenderTemplateInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "render_template"
11
+ end
12
+
13
+ def tags(payload)
14
+ { "component" => COMPONENT_TAG, "template.id" => payload[:identifier], "template.layout" => payload[:layout] }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActionView
7
+ # ActionView bridges action view notifications to
8
+ # the distributed tracing subsystem
9
+ class Subscriber
10
+ include RailsCommon
11
+
12
+ RENDER_TEMPLATE_NOTIFICATION_TOPIC = "render_template.action_view"
13
+ RENDER_COLLECTION_NOTIFICATION_TOPIC = "render_collection.action_view"
14
+ RENDER_PARTIAL_NOTIFICATION_TOPIC = "render_partial.action_view"
15
+
16
+ # Instruments Rails ActionView events for opentracing.
17
+ # Returns a lambda, which, when called will unsubscribe from the notifications
18
+ def self.instrument
19
+ subscriptions = [
20
+ ::ActiveSupport::Notifications.subscribe(RENDER_TEMPLATE_NOTIFICATION_TOPIC, RenderTemplateInstrumenter.new),
21
+ ::ActiveSupport::Notifications.subscribe(RENDER_COLLECTION_NOTIFICATION_TOPIC, RenderCollectionInstrumenter.new),
22
+ ::ActiveSupport::Notifications.subscribe(RENDER_PARTIAL_NOTIFICATION_TOPIC, RenderPartialInstrumenter.new),
23
+ ]
24
+
25
+ create_unsubscriber subscriptions
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveRecord
7
+ autoload :SqlInstrumenter, "labkit/tracing/rails/active_record/sql_instrumenter"
8
+ autoload :Subscriber, "labkit/tracing/rails/active_record/subscriber"
9
+
10
+ COMPONENT_TAG = "ActiveRecord"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveRecord
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class SqlInstrumenter < AbstractInstrumenter
9
+ OPERATION_NAME_PREFIX = "active_record:"
10
+ DEFAULT_OPERATION_NAME = "sqlquery"
11
+
12
+ def span_name(payload)
13
+ OPERATION_NAME_PREFIX + (payload[:name].presence || DEFAULT_OPERATION_NAME)
14
+ end
15
+
16
+ def tags(payload)
17
+ {
18
+ "component" => COMPONENT_TAG,
19
+ "span.kind" => "client",
20
+ "db.type" => "sql",
21
+ "db.connection_id" => payload[:connection_id],
22
+ "db.cached" => payload[:cached] || false,
23
+ "db.statement" => payload[:sql],
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveRecord
7
+ # ActiveRecord bridges active record notifications to
8
+ # the distributed tracing subsystem
9
+ class Subscriber
10
+ include RailsCommon
11
+
12
+ ACTIVE_RECORD_NOTIFICATION_TOPIC = "sql.active_record"
13
+
14
+ # Instruments Rails ActiveRecord events for opentracing.
15
+ # Returns a lambda, which, when called will unsubscribe from the notifications
16
+ def self.instrument
17
+ subscription = ::ActiveSupport::Notifications.subscribe(ACTIVE_RECORD_NOTIFICATION_TOPIC, SqlInstrumenter.new)
18
+
19
+ create_unsubscriber [subscription]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ autoload :CacheDeleteInstrumenter, "labkit/tracing/rails/active_support/cache_delete_instrumenter"
8
+ autoload :CacheFetchHitInstrumenter, "labkit/tracing/rails/active_support/cache_fetch_hit_instrumenter"
9
+ autoload :CacheGenerateInstrumenter, "labkit/tracing/rails/active_support/cache_generate_instrumenter"
10
+ autoload :CacheReadInstrumenter, "labkit/tracing/rails/active_support/cache_read_instrumenter"
11
+ autoload :CacheWriteInstrumenter, "labkit/tracing/rails/active_support/cache_write_instrumenter"
12
+ autoload :Subscriber, "labkit/tracing/rails/active_support/subscriber"
13
+
14
+ COMPONENT_TAG = "ActiveSupport"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class CacheDeleteInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "cache_delete"
11
+ end
12
+
13
+ def tags(payload)
14
+ { "component" => COMPONENT_TAG, "cache.key" => payload[:key] }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class CacheFetchHitInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "cache_fetch_hit"
11
+ end
12
+
13
+ def tags(payload)
14
+ { "component" => COMPONENT_TAG, "cache.key" => payload[:key] }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class CacheGenerateInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "cache_generate"
11
+ end
12
+
13
+ def tags(payload)
14
+ { "component" => COMPONENT_TAG, "cache.key" => payload[:key] }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class CacheReadInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "cache_read"
11
+ end
12
+
13
+ def tags(payload)
14
+ {
15
+ "component" => COMPONENT_TAG,
16
+ "cache.key" => payload[:key],
17
+ "cache.hit" => payload[:hit],
18
+ "cache.super_operation" => payload[:super_operation],
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
8
+ class CacheWriteInstrumenter < AbstractInstrumenter
9
+ def span_name(payload)
10
+ "cache_write"
11
+ end
12
+
13
+ def tags(payload)
14
+ { "component" => COMPONENT_TAG, "cache.key" => payload[:key] }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Tracing
5
+ module Rails
6
+ module ActiveSupport
7
+ # ActiveSupport bridges action active support notifications to
8
+ # the distributed tracing subsystem
9
+ class Subscriber
10
+ include RailsCommon
11
+
12
+ CACHE_READ_TOPIC = "cache_read.active_support"
13
+ CACHE_GENERATE_TOPIC = "cache_generate.active_support"
14
+ CACHE_FETCH_HIT_TOPIC = "cache_fetch_hit.active_support"
15
+ CACHE_WRITE_TOPIC = "cache_write.active_support"
16
+ CACHE_DELETE_TOPIC = "cache_delete.active_support"
17
+
18
+ # Instruments Rails ActiveSupport events for opentracing.
19
+ # Returns a lambda, which, when called will unsubscribe from the notifications
20
+ def self.instrument
21
+ subscriptions = [
22
+ ::ActiveSupport::Notifications.subscribe(CACHE_READ_TOPIC, CacheReadInstrumenter.new),
23
+ ::ActiveSupport::Notifications.subscribe(CACHE_GENERATE_TOPIC, CacheGenerateInstrumenter.new),
24
+ ::ActiveSupport::Notifications.subscribe(CACHE_FETCH_HIT_TOPIC, CacheFetchHitInstrumenter.new),
25
+ ::ActiveSupport::Notifications.subscribe(CACHE_WRITE_TOPIC, CacheWriteInstrumenter.new),
26
+ ::ActiveSupport::Notifications.subscribe(CACHE_DELETE_TOPIC, CacheDeleteInstrumenter.new),
27
+ ]
28
+
29
+ create_unsubscriber subscriptions
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -8,19 +8,13 @@ module Labkit
8
8
  # RailsCommon is a mixin for providing instrumentation
9
9
  # functionality for the rails instrumentation classes
10
10
  module RailsCommon
11
- extend ActiveSupport::Concern
11
+ extend ::ActiveSupport::Concern
12
12
 
13
13
  class_methods do
14
14
  def create_unsubscriber(subscriptions)
15
- -> { subscriptions.each { |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) } }
15
+ -> { subscriptions.each { |subscriber| ::ActiveSupport::Notifications.unsubscribe(subscriber) } }
16
16
  end
17
17
  end
18
-
19
- def generate_span_for_notification(operation_name, start, finish, payload, tags)
20
- exception = payload[:exception]
21
-
22
- TracingUtils.postnotify_span(operation_name, start, finish, tags: tags, exception: exception)
23
- end
24
18
  end
25
19
  end
26
20
  end
@@ -8,7 +8,7 @@ module Labkit
8
8
  # RedisInterceptorHelper is a helper for the RedisInterceptor. This is not a public API
9
9
  class RedisInterceptorHelper
10
10
  # For optimization, compile this once
11
- MASK_REDIS_RE = /^([\w-]+(?:\W+[\w-]+(?:\W+[\w-]+)?)?)(.?)/.freeze
11
+ MASK_REDIS_RE = /^([\w{}-]+(?:\W+[\w{}-]+(?:\W+[\w{}-]+)?)?)(.?)/.freeze
12
12
 
13
13
  def self.call_with_tracing(command, client)
14
14
  Labkit::Tracing::TracingUtils.with_tracing(operation_name: "redis.call", tags: tags_from_command(command, client)) do |_span|
@@ -99,6 +99,7 @@ module Labkit
99
99
  return "" if argument.empty?
100
100
 
101
101
  matches = argument.match(MASK_REDIS_RE)
102
+
102
103
  matches[2].empty? ? matches[0] : matches[0] + "*****"
103
104
  end
104
105
  private_class_method :mask_redis_arg
@@ -12,9 +12,7 @@ module Labkit
12
12
  scope = tracer.start_active_span(operation_name, child_of: child_of, tags: tags)
13
13
  span = scope.span
14
14
 
15
- # Add correlation details to the span if we have them
16
- correlation_id = Labkit::Correlation::CorrelationId.current_id
17
- span.set_tag("correlation_id", correlation_id) if correlation_id
15
+ log_common_fields_on_span(span, operation_name)
18
16
 
19
17
  begin
20
18
  yield span
@@ -35,11 +33,19 @@ module Labkit
35
33
  def self.postnotify_span(operation_name, start_time, end_time, tags: nil, child_of: nil, exception: nil)
36
34
  span = OpenTracing.start_span(operation_name, start_time: start_time, tags: tags, child_of: child_of)
37
35
 
36
+ log_common_fields_on_span(span, operation_name)
38
37
  log_exception_on_span(span, exception) if exception
39
38
 
40
39
  span.finish(end_time: end_time)
41
40
  end
42
41
 
42
+ # Add common fields to a span
43
+ def self.log_common_fields_on_span(span, operation_name)
44
+ correlation_id = Labkit::Correlation::CorrelationId.current_id
45
+ span.set_tag("correlation_id", correlation_id) if correlation_id
46
+ span.log_kv(stack: caller.join('\n')) if include_stacktrace?(operation_name)
47
+ end
48
+
43
49
  # Add exception logging to a span
44
50
  def self.log_exception_on_span(span, exception)
45
51
  span.set_tag("error", true)
@@ -60,6 +66,14 @@ module Labkit
60
66
  { :"event" => "error", :"error.kind" => exception.class.to_s, :"error.object" => Labkit::Logging::Sanitizer.sanitize_field(exception.to_s) }
61
67
  end
62
68
  end
69
+
70
+ def self.include_stacktrace?(operation_name)
71
+ @include_stacktrace ||= Hash.new do |result, name|
72
+ result[name] = Tracing.stacktrace_operations.any? { |stacktrace_operation| name.starts_with?(stacktrace_operation) }
73
+ end
74
+
75
+ @include_stacktrace[operation_name]
76
+ end
63
77
  end
64
78
  end
65
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -284,7 +284,14 @@ files:
284
284
  - lib/labkit/middleware/rack.rb
285
285
  - lib/labkit/middleware/sidekiq.rb
286
286
  - lib/labkit/middleware/sidekiq/client.rb
287
+ - lib/labkit/middleware/sidekiq/context.rb
288
+ - lib/labkit/middleware/sidekiq/context/client.rb
289
+ - lib/labkit/middleware/sidekiq/context/server.rb
287
290
  - lib/labkit/middleware/sidekiq/server.rb
291
+ - lib/labkit/middleware/sidekiq/tracing.rb
292
+ - lib/labkit/middleware/sidekiq/tracing/client.rb
293
+ - lib/labkit/middleware/sidekiq/tracing/server.rb
294
+ - lib/labkit/middleware/sidekiq/tracing/sidekiq_common.rb
288
295
  - lib/labkit/tracing.rb
289
296
  - lib/labkit/tracing/factory.rb
290
297
  - lib/labkit/tracing/grpc.rb
@@ -294,17 +301,26 @@ files:
294
301
  - lib/labkit/tracing/jaeger_factory.rb
295
302
  - lib/labkit/tracing/rack_middleware.rb
296
303
  - lib/labkit/tracing/rails.rb
297
- - lib/labkit/tracing/rails/action_view_subscriber.rb
298
- - lib/labkit/tracing/rails/active_record_subscriber.rb
299
- - lib/labkit/tracing/rails/active_support_subscriber.rb
304
+ - lib/labkit/tracing/rails/abstract_instrumenter.rb
305
+ - lib/labkit/tracing/rails/action_view.rb
306
+ - lib/labkit/tracing/rails/action_view/render_collection_instrumenter.rb
307
+ - lib/labkit/tracing/rails/action_view/render_partial_instrumenter.rb
308
+ - lib/labkit/tracing/rails/action_view/render_template_instrumenter.rb
309
+ - lib/labkit/tracing/rails/action_view/subscriber.rb
310
+ - lib/labkit/tracing/rails/active_record.rb
311
+ - lib/labkit/tracing/rails/active_record/sql_instrumenter.rb
312
+ - lib/labkit/tracing/rails/active_record/subscriber.rb
313
+ - lib/labkit/tracing/rails/active_support.rb
314
+ - lib/labkit/tracing/rails/active_support/cache_delete_instrumenter.rb
315
+ - lib/labkit/tracing/rails/active_support/cache_fetch_hit_instrumenter.rb
316
+ - lib/labkit/tracing/rails/active_support/cache_generate_instrumenter.rb
317
+ - lib/labkit/tracing/rails/active_support/cache_read_instrumenter.rb
318
+ - lib/labkit/tracing/rails/active_support/cache_write_instrumenter.rb
319
+ - lib/labkit/tracing/rails/active_support/subscriber.rb
300
320
  - lib/labkit/tracing/rails/rails_common.rb
301
321
  - lib/labkit/tracing/redis.rb
302
322
  - lib/labkit/tracing/redis/redis_interceptor.rb
303
323
  - lib/labkit/tracing/redis/redis_interceptor_helper.rb
304
- - lib/labkit/tracing/sidekiq.rb
305
- - lib/labkit/tracing/sidekiq/client_middleware.rb
306
- - lib/labkit/tracing/sidekiq/server_middleware.rb
307
- - lib/labkit/tracing/sidekiq/sidekiq_common.rb
308
324
  - lib/labkit/tracing/tracing_utils.rb
309
325
  homepage: https://gitlab.com/gitlab-org/labkit-ruby
310
326
  licenses:
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- module Rails
6
- # ActionViewSubscriber bridges action view notifications to
7
- # the distributed tracing subsystem
8
- class ActionViewSubscriber
9
- include RailsCommon
10
-
11
- COMPONENT_TAG = "ActionView"
12
- RENDER_TEMPLATE_NOTIFICATION_TOPIC = "render_template.action_view"
13
- RENDER_COLLECTION_NOTIFICATION_TOPIC = "render_collection.action_view"
14
- RENDER_PARTIAL_NOTIFICATION_TOPIC = "render_partial.action_view"
15
-
16
- # Instruments Rails ActionView events for opentracing.
17
- # Returns a lambda, which, when called will unsubscribe from the notifications
18
- def self.instrument
19
- subscriber = new
20
-
21
- subscriptions = [
22
- ActiveSupport::Notifications.subscribe(RENDER_TEMPLATE_NOTIFICATION_TOPIC) do |_, start, finish, _, payload|
23
- subscriber.notify_render_template(start, finish, payload)
24
- end,
25
- ActiveSupport::Notifications.subscribe(RENDER_COLLECTION_NOTIFICATION_TOPIC) do |_, start, finish, _, payload|
26
- subscriber.notify_render_collection(start, finish, payload)
27
- end,
28
- ActiveSupport::Notifications.subscribe(RENDER_PARTIAL_NOTIFICATION_TOPIC) do |_, start, finish, _, payload|
29
- subscriber.notify_render_partial(start, finish, payload)
30
- end,
31
- ]
32
-
33
- create_unsubscriber subscriptions
34
- end
35
-
36
- # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
37
- def notify_render_template(start, finish, payload)
38
- generate_span_for_notification("render_template", start, finish, payload, tags_for_render_template(payload))
39
- end
40
-
41
- def notify_render_collection(start, finish, payload)
42
- generate_span_for_notification("render_collection", start, finish, payload, tags_for_render_collection(payload))
43
- end
44
-
45
- def notify_render_partial(start, finish, payload)
46
- generate_span_for_notification("render_partial", start, finish, payload, tags_for_render_partial(payload))
47
- end
48
-
49
- private
50
-
51
- def tags_for_render_template(payload)
52
- { "component" => COMPONENT_TAG, "template.id" => payload[:identifier], "template.layout" => payload[:layout] }
53
- end
54
-
55
- def tags_for_render_collection(payload)
56
- {
57
- "component" => COMPONENT_TAG,
58
- "template.id" => payload[:identifier],
59
- "template.count" => payload[:count] || 0,
60
- "template.cache.hits" => payload[:cache_hits] || 0,
61
- }
62
- end
63
-
64
- def tags_for_render_partial(payload)
65
- { "component" => COMPONENT_TAG, "template.id" => payload[:identifier] }
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- module Rails
6
- # ActiveRecordSubscriber bridges active record notifications to
7
- # the distributed tracing subsystem
8
- class ActiveRecordSubscriber
9
- include RailsCommon
10
-
11
- ACTIVE_RECORD_NOTIFICATION_TOPIC = "sql.active_record"
12
- OPERATION_NAME_PREFIX = "active_record:"
13
- DEFAULT_OPERATION_NAME = "sqlquery"
14
-
15
- # Instruments Rails ActiveRecord events for opentracing.
16
- # Returns a lambda, which, when called will unsubscribe from the notifications
17
- def self.instrument
18
- subscriber = new
19
-
20
- subscription =
21
- ActiveSupport::Notifications.subscribe(ACTIVE_RECORD_NOTIFICATION_TOPIC) do |_, start, finish, _, payload|
22
- subscriber.notify(start, finish, payload)
23
- end
24
-
25
- create_unsubscriber [subscription]
26
- end
27
-
28
- # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html
29
- def notify(start, finish, payload)
30
- generate_span_for_notification(notification_name(payload), start, finish, payload, tags_for_notification(payload))
31
- end
32
-
33
- private
34
-
35
- def notification_name(payload)
36
- OPERATION_NAME_PREFIX + (payload[:name].presence || DEFAULT_OPERATION_NAME)
37
- end
38
-
39
- def tags_for_notification(payload)
40
- {
41
- "component" => "ActiveRecord",
42
- "span.kind" => "client",
43
- "db.type" => "sql",
44
- "db.connection_id" => payload[:connection_id],
45
- "db.cached" => payload[:cached] || false,
46
- "db.statement" => payload[:sql],
47
- }
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- module Rails
6
- # ActiveSupport bridges action active support notifications to
7
- # the distributed tracing subsystem
8
- class ActiveSupportSubscriber
9
- include RailsCommon
10
-
11
- COMPONENT_TAG = "ActiveSupport"
12
-
13
- CACHE_READ_TOPIC = "cache_read.active_support"
14
- CACHE_GENERATE_TOPIC = "cache_generate.active_support"
15
- CACHE_FETCH_HIT_TOPIC = "cache_fetch_hit.active_support"
16
- CACHE_WRITE_TOPIC = "cache_write.active_support"
17
- CACHE_DELETE_TOPIC = "cache_delete.active_support"
18
-
19
- # Instruments Rails ActiveSupport events for opentracing.
20
- # Returns a lambda, which, when called will unsubscribe from the notifications
21
- def self.instrument
22
- subscriber = new
23
-
24
- subscriptions = [
25
- ActiveSupport::Notifications.subscribe(CACHE_READ_TOPIC) do |_, start, finish, _, payload|
26
- subscriber.notify_cache_read(start, finish, payload)
27
- end,
28
- ActiveSupport::Notifications.subscribe(CACHE_GENERATE_TOPIC) do |_, start, finish, _, payload|
29
- subscriber.notify_cache_generate(start, finish, payload)
30
- end,
31
- ActiveSupport::Notifications.subscribe(CACHE_FETCH_HIT_TOPIC) do |_, start, finish, _, payload|
32
- subscriber.notify_cache_fetch_hit(start, finish, payload)
33
- end,
34
- ActiveSupport::Notifications.subscribe(CACHE_WRITE_TOPIC) do |_, start, finish, _, payload|
35
- subscriber.notify_cache_write(start, finish, payload)
36
- end,
37
- ActiveSupport::Notifications.subscribe(CACHE_DELETE_TOPIC) do |_, start, finish, _, payload|
38
- subscriber.notify_cache_delete(start, finish, payload)
39
- end,
40
- ]
41
-
42
- create_unsubscriber subscriptions
43
- end
44
-
45
- # For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html#active-support
46
- def notify_cache_read(start, finish, payload)
47
- generate_span_for_notification("cache_read", start, finish, payload, tags_for_cache_read(payload))
48
- end
49
-
50
- def notify_cache_generate(start, finish, payload)
51
- generate_span_for_notification("cache_generate", start, finish, payload, tags_for_key(payload))
52
- end
53
-
54
- def notify_cache_fetch_hit(start, finish, payload)
55
- generate_span_for_notification("cache_fetch_hit", start, finish, payload, tags_for_key(payload))
56
- end
57
-
58
- def notify_cache_write(start, finish, payload)
59
- generate_span_for_notification("cache_write", start, finish, payload, tags_for_key(payload))
60
- end
61
-
62
- def notify_cache_delete(start, finish, payload)
63
- generate_span_for_notification("cache_delete", start, finish, payload, tags_for_key(payload))
64
- end
65
-
66
- private
67
-
68
- def tags_for_cache_read(payload)
69
- {
70
- "component" => COMPONENT_TAG,
71
- "cache.key" => payload[:key],
72
- "cache.hit" => payload[:hit],
73
- "cache.super_operation" => payload[:super_operation],
74
- }
75
- end
76
-
77
- def tags_for_key(payload)
78
- {
79
- "component" => COMPONENT_TAG,
80
- "cache.key" => payload[:key],
81
- }
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- # Sidekiq provides classes for instrumenting Sidekiq client and server
6
- # functionality
7
- module Sidekiq
8
- autoload :ClientMiddleware, "labkit/tracing/sidekiq/client_middleware"
9
- autoload :ServerMiddleware, "labkit/tracing/sidekiq/server_middleware"
10
- autoload :SidekiqCommon, "labkit/tracing/sidekiq/sidekiq_common"
11
- end
12
- end
13
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "opentracing"
4
-
5
- module Labkit
6
- module Tracing
7
- module Sidekiq
8
- # ClientMiddleware provides a sidekiq client middleware for
9
- # instrumenting distributed tracing calls made from the client
10
- # application
11
- class ClientMiddleware
12
- include SidekiqCommon
13
-
14
- SPAN_KIND = "client"
15
-
16
- def call(_worker_class, job, _queue, _redis_pool)
17
- TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span|
18
- # Inject the details directly into the job
19
- TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
20
-
21
- yield
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "opentracing"
4
-
5
- module Labkit
6
- module Tracing
7
- module Sidekiq
8
- # ServerMiddleware provides a sidekiq server middleware for
9
- # instrumenting distributed tracing calls when they are
10
- # executed by the Sidekiq server
11
- class ServerMiddleware
12
- include SidekiqCommon
13
-
14
- SPAN_KIND = "server"
15
-
16
- def call(_worker, job, _queue)
17
- context = TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, job)
18
-
19
- TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", child_of: context, tags: tags_from_job(job, SPAN_KIND)) { |_span| yield }
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- module Sidekiq
6
- # SidekiqCommon is a mixin for the sidekiq middleware components
7
- module SidekiqCommon
8
- def tags_from_job(job, kind)
9
- {
10
- "component" => "sidekiq",
11
- "span.kind" => kind,
12
- "sidekiq.queue" => job["queue"],
13
- "sidekiq.jid" => job["jid"],
14
- "sidekiq.retry" => job["retry"].to_s,
15
- "sidekiq.args" => job["args"]&.join(", "),
16
- }
17
- end
18
- end
19
- end
20
- end
21
- end