forked from open-telemetry/opentelemetry-ruby-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve compatibility with Faraday v1
Fixes open-telemetry#1031 Faraday >= 1 changes where the #adapter method gets called, affecting the RackBuilder patch in this gem. Without this change, the tracer middleware gets added to the beginning of the stack instead of the end, and explicitly adding the middleware would cause it to get added twice. This change patches `Connection#initialize` for Faraday >= 1 to preserve the behavior we had with Faraday < 1. This is similar to the dd-trace-rb change made in DataDog/dd-trace-rb#906. There is some followup work here to explore moving the middleware to the beginning of the stack instead of the end, but we can work on that separately.
- Loading branch information
1 parent
5b09f9b
commit 548c7ab
Showing
3 changed files
with
46 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/patches/connection.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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module Faraday | ||
module Patches | ||
# Module to be prepended to force Faraday to use the middleware by | ||
# default so the user doesn't have to call `use` for every connection. | ||
module Connection | ||
# Wraps Faraday::Connection#initialize: | ||
# https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92 | ||
def initialize(*args) | ||
super.tap do | ||
use(:open_telemetry) unless builder.handlers.any? do |handler| | ||
handler.klass == Middlewares::TracerMiddleware | ||
end | ||
end | ||
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