-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: metrics integration for sidekiq
- Loading branch information
Showing
12 changed files
with
463 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
appraise 'sidekiq-7.0' do | ||
gem 'sidekiq', '~> 7.0' | ||
end | ||
|
||
appraise 'sidekiq-6.5' do | ||
gem 'sidekiq', '>= 6.5', '< 7.0' | ||
end | ||
{ | ||
'sidekiq-7.0' => [['sidekiq', '~> 7.0']], | ||
'sidekiq-6.5' => [['sidekiq', '>= 6.5', '< 7.0']], | ||
'sidekiq-6.0' => [ | ||
['sidekiq', '>= 6.0', '< 6.5'], | ||
['redis', '< 4.8'] | ||
], | ||
'sidekiq-5.2' => [ | ||
['sidekiq', '~> 5.2'], | ||
['redis', '< 4.8'] | ||
], | ||
'sidekiq-4.2' => [ | ||
['sidekiq', '~> 4.2'], | ||
['redis', '< 4.8'] | ||
] | ||
}.each do |gemfile_name, specs| | ||
appraise gemfile_name do | ||
specs.each do |spec| | ||
gem *spec | ||
remove_gem 'opentelemetry-metrics-api' | ||
remove_gem 'opentelemetry-metrics-sdk' | ||
end | ||
end | ||
|
||
appraise 'sidekiq-6.0' do | ||
gem 'sidekiq', '>= 6.0', '< 6.5' | ||
gem 'redis', '< 4.8' | ||
end | ||
|
||
appraise 'sidekiq-5.2' do | ||
gem 'sidekiq', '~> 5.2' | ||
gem 'redis', '< 4.8' | ||
end | ||
appraise "#{gemfile_name}-metrics-api" do | ||
specs.each do |spec| | ||
gem *spec | ||
remove_gem 'opentelemetry-metrics-sdk' | ||
end | ||
end | ||
|
||
appraise 'sidekiq-4.2' do | ||
gem 'sidekiq', '~> 4.2' | ||
gem 'redis', '< 4.8' | ||
appraise "#{gemfile_name}-metrics-sdk" do | ||
specs.each do |spec| | ||
gem *spec | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
instrumentation/sidekiq/lib/opentelemetry/instrumentation/sidekiq/middlewares/common.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module Sidekiq | ||
module Middlewares | ||
module Common | ||
private | ||
|
||
def instrumentation | ||
Sidekiq::Instrumentation.instance | ||
end | ||
|
||
def instrumentation_config | ||
Sidekiq::Instrumentation.instance.config | ||
end | ||
|
||
# Bypasses _all_ enclosed logic unless metrics are enabled | ||
def with_meter(&block) | ||
instrumentation.with_meter(&block) | ||
end | ||
|
||
# time an inner block and yield the duration to the given callback | ||
def timed(callback) | ||
return yield unless metrics_enabled? | ||
|
||
t0 = monotonic_now | ||
|
||
yield.tap do | ||
callback.call(monotonic_now - t0) | ||
end | ||
end | ||
|
||
# FIXME: is this a util somewhere | ||
def realtime_now | ||
Process.clock_gettime(Process::CLOCK_REALTIME) | ||
end | ||
|
||
def monotonic_now | ||
Process.clock_gettime(Process::CLOCK_MONOTONIC) | ||
end | ||
|
||
def tracer | ||
instrumentation.tracer | ||
end | ||
|
||
def metrics_enabled? | ||
instrumentation.metrics_enabled? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.