-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
234 additions
and
46 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
35 changes: 35 additions & 0 deletions
35
instrumentation/redis/lib/opentelemetry/instrumentation/redis/patches/metrics_helpers.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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module Redis | ||
module Patches | ||
# Common logic for tracking histograms and other metrics instruments | ||
module MetricsHelpers | ||
private | ||
|
||
def otel_record_histogram(histogram, attributes) | ||
t0 = otel_monotonic_now | ||
yield.tap do |result| | ||
attributes['error.type'] = result.class.to_s if result.is_a?(StandardError) | ||
end | ||
rescue StandardError => e | ||
attributes['error.type'] = e.class.to_s | ||
raise | ||
ensure | ||
duration = otel_monotonic_now - t0 | ||
histogram.record(duration, attributes: attributes) | ||
end | ||
|
||
def otel_monotonic_now | ||
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) | ||
end | ||
end | ||
end | ||
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
35 changes: 35 additions & 0 deletions
35
...entation/redis/lib/opentelemetry/instrumentation/redis/patches/redis_v4_client_metrics.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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module Redis | ||
module Patches | ||
# Module to prepend to Redis::Client for metrics | ||
module RedisV4ClientMetrics | ||
def self.prepended(base) | ||
base.prepend(OpenTelemetry::Instrumentation::Redis::Patches::MetricsHelpers) | ||
end | ||
|
||
def process(commands) | ||
return super unless (histogram = instrumentation.client_operation_duration_histogram) | ||
|
||
attributes = otel_base_attributes | ||
|
||
attributes['db.operation.name'] = | ||
if commands.length == 1 | ||
commands[0][0].to_s | ||
else | ||
'PIPELINED' | ||
end | ||
|
||
otel_record_histogram(histogram, attributes) { super } | ||
end | ||
end | ||
end | ||
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