Skip to content

Commit

Permalink
remove access to patching elasticsearch client directly as it is not …
Browse files Browse the repository at this point in the history
…supported anymore by elasticsearch
  • Loading branch information
ekump committed Jan 24, 2024
1 parent 277b90f commit 1dc782c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 66 deletions.
22 changes: 2 additions & 20 deletions lib/datadog/tracing/contrib/elasticsearch/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,8 @@ module Client
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def perform_request(*args)
# DEV-2.0: Remove this access, as `Client#self` in this context is not exposed to the user
# since `elasticsearch` v8.0.0. In contrast, `Client#transport` is always available across
# all `elasticsearch` gem versions and should be used instead.
service = Datadog.configuration_for(self, :service_name)

if service
SELF_DEPRECATION_ONLY_ONCE.run do
Datadog.logger.warn(
'Providing configuration though the Elasticsearch client object is deprecated.' \
'Configure the `client#transport` object instead: ' \
'Datadog.configure_onto(client.transport, service_name: service_name, ...)'
)
end
end

# `Client#transport` is most convenient object both this integration and the library
# user have shared access to across all `elasticsearch` versions.
#
# `Client#self` in this context is an internal object that the library user
# does not have access to since `elasticsearch` v8.0.0.
# `Client#transport` is the most convenient object both for this integration and the library
# as users have shared access to it across all `elasticsearch` versions.
service ||= Datadog.configuration_for(transport, :service_name) || datadog_configuration[:service_name]

method = args[0]
Expand Down
46 changes: 0 additions & 46 deletions spec/datadog/tracing/contrib/elasticsearch/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,50 +174,4 @@ def call(env)
end
end
end

describe 'client configuration override' do
context 'when #service is overridden' do
before { Datadog.configure_onto(client.transport, service_name: service_name) }

let(:service_name) { 'bar' }

describe 'then a GET request' do
subject(:response) { client.perform_request(method, path) }

let(:method) { 'GET' }
let(:path) { '_cluster/health' }

before do
stub_request(:get, "#{server}/#{path}").to_return(status: 200)
end

it 'produces a well-formed trace' do
expect(response.status).to eq(200)
expect(WebMock).to have_requested(:get, "#{server}/#{path}")
expect(spans).to have(1).items
expect(span.name).to eq('elasticsearch.query')
expect(span.service).to eq(service_name)
end

context 'configured at the Elasticsearch client level' do
before do
skip('Configuration through client object is not possible in Elasticsearch >= 8.0.0') if version_greater_than_8

Datadog::Tracing::Contrib::Elasticsearch::Patcher::SELF_DEPRECATION_ONLY_ONCE
.send(:reset_ran_once_state_for_tests)

Datadog.configure_onto(client, service_name: 'custom')
end

let(:version_greater_than_8) { Gem::Version.new(::Elasticsearch::VERSION) >= Gem::Version.new('8.0.0') }

it 'warns about deprecated configuration of the Elasticsearch client itself' do
expect { response }.to emit_deprecation_warning(
include('Providing configuration though the Elasticsearch client object is deprecated')
)
end
end
end
end
end
end

0 comments on commit 1dc782c

Please sign in to comment.