Skip to content

Commit 97955b0

Browse files
feat: Faraday Minimum v1.0 (#1267)
* fix: Share Faraday Attrs with Adapter Spans The Faraday gem has additional http attributes that are sometimes missing or difficult to derive in Adapter instrumentations. * feat: Faraday Minimum v1.0 Faraday pre-1.0 is no longer receiving updates. --------- Co-authored-by: Kayla Reopelle <[email protected]>
1 parent 4f926f1 commit 97955b0

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

instrumentation/faraday/Appraisals

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
%w[0.17.6 1.0 2.0].each do |version|
7+
%w[1.0 2.0].each do |version|
88
appraise "faraday-#{version}" do
99
gem 'faraday', "~> #{version}"
1010
end

instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/instrumentation.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ module Faraday
1010
# The Instrumentation class contains logic to detect and install the Faraday
1111
# instrumentation
1212
class Instrumentation < OpenTelemetry::Instrumentation::Base
13+
MINIMUM_VERSION = Gem::Version.new('1.0')
14+
1315
install do |_config|
1416
require_dependencies
1517
register_tracer_middleware
1618
use_middleware_by_default
1719
end
1820

21+
compatible do
22+
gem_version >= MINIMUM_VERSION
23+
end
24+
1925
present do
2026
defined?(::Faraday)
2127
end
@@ -25,10 +31,13 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2531

2632
private
2733

34+
def gem_version
35+
Gem::Version.new(::Faraday::VERSION)
36+
end
37+
2838
def require_dependencies
2939
require_relative 'middlewares/tracer_middleware'
3040
require_relative 'patches/connection'
31-
require_relative 'patches/rack_builder'
3241
end
3342

3443
def register_tracer_middleware
@@ -38,11 +47,7 @@ def register_tracer_middleware
3847
end
3948

4049
def use_middleware_by_default
41-
if Gem::Version.new(::Faraday::VERSION) >= Gem::Version.new('1')
42-
::Faraday::Connection.prepend(Patches::Connection)
43-
else
44-
::Faraday::RackBuilder.prepend(Patches::RackBuilder)
45-
end
50+
::Faraday::Connection.prepend(Patches::Connection)
4651
end
4752
end
4853
end

instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/patches/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Patches
1313
module Connection
1414
# Wraps Faraday::Connection#initialize:
1515
# https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92
16-
def initialize(*args)
16+
def initialize(...)
1717
super.tap do
1818
use(:open_telemetry) unless builder.handlers.any? do |handler|
1919
handler.klass == Middlewares::TracerMiddleware

instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/patches/rack_builder.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)