elastic-transport 8.3.6 → 8.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55e1343a320fd2a1dba29077ff4d9ad72b6adf62fe918856480f43e00e8a9927
4
- data.tar.gz: da17629d377258be5b8564ba0bd82c3ef6119117e307a14ac60f8da14894e375
3
+ metadata.gz: 5634ceac3d52fa6af5174e9aad5ecf2613018e4a9977114305a9f3a42ee25909
4
+ data.tar.gz: 92acaa8ac6c08475e3dc91aa1132e1a719060b0bab0c05c94b3feae92f9cb83f
5
5
  SHA512:
6
- metadata.gz: e375ab5339638b8fedd29d38ae0ff6384407e8256c9201c383ee084689e4781752fe4cc9b23830a2380185234acfbbc59533d91f653ec51fff9007a433b033b3
7
- data.tar.gz: 25a3847030def992ed441260e8921509ad5375353ad3e564218e799341bc53942e30245e6dad79c6e38e1783b993298e6729951320bb785e17308a2f5f9ca19f
6
+ metadata.gz: 2cd0a8e98e8bf2cfa5964779042672f15ba4d968b0fadec444474dc2253584c9dc3cf5932ffb731415503a57719838e5aa05eec78e77e184fbc3eb762291c137
7
+ data.tar.gz: d7132ee663cd2984e5b34ea7827ff27010e69c66d6ad3dc2ca3571b6d4b516ab1004b7a45c7495e68e38a047defc66c947cd2c1a0a026086a3b718d6328dc1ed
@@ -7,7 +7,7 @@ jobs:
7
7
  - uses: actions/checkout@v4
8
8
  - uses: ruby/setup-ruby@v1
9
9
  with:
10
- ruby-version: 3
10
+ ruby-version: '3.4'
11
11
  - name: Check license headers
12
12
  run: |
13
13
  ruby ./.github/check_license_headers.rb
@@ -2,10 +2,10 @@ name: opentelemetry
2
2
  on:
3
3
  push:
4
4
  branches:
5
- - 8.3
5
+ - main
6
6
  pull_request:
7
7
  branches:
8
- - 8.3
8
+ - main
9
9
  jobs:
10
10
  test-otel:
11
11
  name: 'Test Open Telemetry'
@@ -16,7 +16,7 @@ jobs:
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: ['3.3', 'jruby-9.4']
19
+ ruby: ['3.4', 'jruby-9.4']
20
20
  es_version: ['9.2.0-SNAPSHOT']
21
21
  runs-on: ubuntu-latest
22
22
  steps:
@@ -1,11 +1,12 @@
1
- name: 8.3 tests
1
+ name: main tests
2
2
  on:
3
3
  push:
4
4
  branches:
5
- - 8.3
5
+ - main
6
6
  pull_request:
7
7
  branches:
8
- - 8.3
8
+ - main
9
+ workflow_dispatch:
9
10
  jobs:
10
11
  test:
11
12
  name: 'Main tests'
@@ -15,7 +16,7 @@ jobs:
15
16
  strategy:
16
17
  fail-fast: false
17
18
  matrix:
18
- ruby: ['3.1', '3.2', '3.3', '3.4', 'jruby-9.3', 'jruby-9.4']
19
+ ruby: ['3.2', '3.3', '3.4', 'jruby-9.3', 'jruby-9.4', 'jruby-10.0']
19
20
  es_version: ['8.18.8-SNAPSHOT', '8.19.5-SNAPSHOT', '9.0.8-SNAPSHOT', '9.1.5-SNAPSHOT', '9.2.0-SNAPSHOT']
20
21
  runs-on: ubuntu-latest
21
22
  steps:
@@ -53,7 +54,7 @@ jobs:
53
54
  strategy:
54
55
  fail-fast: false
55
56
  matrix:
56
- ruby: ['3.1', '3.2', '3.3', '3.4', 'jruby-9.3']
57
+ ruby: ['3.0', '3.1', '3.2', '3.3', 'jruby-9.3']
57
58
  es_version: ['8.19.5-SNAPSHOT']
58
59
  runs-on: ubuntu-latest
59
60
  steps:
data/CHANGELOG.md CHANGED
@@ -1,8 +1,45 @@
1
- ## 8.3.6
1
+ ## 8.4.1
2
2
 
3
3
  - Moves `require 'timeout'` to the classes that use it. Closed [#79](https://github.com/elastic/elastic-transport-ruby/issues/79).
4
4
  - Sanitize url on OTEL spans, thanks @steve21168. Pull Request: [#98](https://github.com/elastic/elastic-transport-ruby/pull/98)
5
5
 
6
+ ## 8.4.0
7
+
8
+ - Adds support for **[Excon](https://github.com/excon/excon)** Faraday adapter. You can use the Excon adapter by setting it in when initializing an Elasticsearch client:
9
+
10
+ ```ruby
11
+ require 'faraday/excon'
12
+
13
+ Elasticsearch::Client.new(
14
+ host: host,
15
+ transport_options: transport_options,
16
+ adapter: :excon
17
+ )
18
+ ```
19
+
20
+ Excon may need some specific configuration for HTTPS/SSL. You may see certificate verification errors when trying to connect to Elastic. Excon has certificates bundled, but these can be customized:
21
+
22
+ ```ruby
23
+ Excon.defaults[:ssl_ca_path] = path_to_certs
24
+ ENV['SSL_CERT_DIR'] = path_to_certs
25
+ Excon.defaults[:ssl_ca_file] = path_to_file
26
+ ENV['SSL_CERT_FILE'] = path_to_file
27
+ Excon.defaults[:ssl_verify_callback] = callback
28
+ # (see OpenSSL::SSL::SSLContext#verify_callback)
29
+ Excon.defaults[:ssl_verify_peer] = false # (less secure).
30
+ ```
31
+
32
+ - Adds support for **[Async::HTTP::Faraday](https://github.com/socketry/async-http-faraday)**. You can use the adapter by setting it when initializing an Elasticsearch client:
33
+ ```ruby
34
+ require 'async-http-faraday'
35
+
36
+ Elasticsearch::Client.new(
37
+ host: host,
38
+ adapter: :async_http
39
+ )
40
+ ```
41
+ - Minor refactors, styling fixes.
42
+
6
43
  ## 8.3.5
7
44
 
8
45
  - Small updates in source code documentation.
data/CONTRIBUTING.md CHANGED
@@ -43,6 +43,23 @@ $ rake docker:start[8.0.0-alpha1]
43
43
 
44
44
  You can find the available version in [Docker @ Elastic](https://www.docker.elastic.co/r/elasticsearch).
45
45
 
46
+ You can also run Elasticsearch and Kibana locally with Docker with `start-local`:
47
+
48
+ ```bash
49
+ curl -fsSL https://elastic.co/start-local | sh
50
+ ```
51
+
52
+ This will run Elasticsearch in http://localhost:9200 and Kibana in http://localhost:5601. More information is available [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/run-elasticsearch-locally.html).
53
+
54
+ ## Faraday 1 tests
55
+
56
+ You can run the tests for Faraday v1 with the following commands:
57
+
58
+ ```bash
59
+ BUNDLE_GEMFILE=Gemfile-faraday1.gemfile bundle install
60
+ BUNDLE_GEMFILE=Gemfile-faraday1.gemfile rake test:all
61
+ ```
62
+
46
63
  # Contributing
47
64
 
48
65
  The process for contributing is:
data/Gemfile CHANGED
@@ -21,13 +21,16 @@ source 'https://rubygems.org'
21
21
  gemspec
22
22
 
23
23
  group :development, :test do
24
+ gem 'faraday-excon'
24
25
  gem 'faraday-httpclient'
25
26
  gem 'faraday-net_http_persistent'
26
27
  gem 'faraday-typhoeus'
28
+ gem 'mutex_m' if RUBY_VERSION >= '3.4'
27
29
  gem 'opentelemetry-sdk', require: false if RUBY_VERSION >= '3.0'
28
30
  if defined?(JRUBY_VERSION)
29
31
  gem 'pry-nav'
30
32
  else
33
+ gem 'async-http-faraday'
31
34
  gem 'faraday-patron'
32
35
  gem 'oj'
33
36
  gem 'pry-byebug'
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Elastic Transport
2
- [![8.1 tests](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml/badge.svg?branch=8.1)](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml)
3
2
  [![Run tests](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/elastic/elastic-transport-ruby/actions/workflows/tests.yml)
4
3
 
5
- This gem provides a low-level Ruby client for connecting to an [Elastic](http://elastic.co) cluster. It powers both the [Elasticsearch client](https://github.com/elasticsearch/elasticsearch-ruby/) and the [Elastic Enterprise Search](https://github.com/elastic/enterprise-search-ruby/) client.
4
+ This gem provides a low-level Ruby client for connecting to an [Elastic](http://elastic.co) cluster. It powers the [Elasticsearch client](https://github.com/elasticsearch/elasticsearch-ruby/) and other Elastic projects.
6
5
 
7
6
  In the simplest form, connect to Elasticsearch running on `http://localhost:9200` without any configuration:
8
7
 
@@ -14,9 +13,9 @@ response = client.perform_request('GET', '_cluster/health')
14
13
  # => #<Elastic::Transport::Transport::Response:0x007fc5d506ce38 @status=200, @body={ ... } >
15
14
  ```
16
15
 
17
- **Refer to [the official documentation on Elastic Transport](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/transport.html).**
16
+ **Refer to [the official documentation on Elastic Transport](https://www.elastic.co/docs/reference/elasticsearch/clients/ruby/transport).**
18
17
 
19
- **Refer to [Advanced Configuration](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/advanced-config.html) to read about more configuration options.**
18
+ **Refer to [Advanced Configuration](https://www.elastic.co/docs/reference/elasticsearch/clients/ruby/advanced-config) to read about more configuration options.**
20
19
 
21
20
  ## Compatibility
22
21
 
@@ -123,8 +123,8 @@ module Elastic
123
123
  #
124
124
  def initialize(arguments = {}, &block)
125
125
  @arguments = arguments.transform_keys(&:to_sym)
126
- @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil
127
- @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil
126
+ @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call : nil
127
+ @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call : nil
128
128
  @arguments[:reload_connections] ||= false
129
129
  @arguments[:retry_on_failure] ||= false
130
130
  @arguments[:delay_on_retry] ||= 0
@@ -134,13 +134,7 @@ module Elastic
134
134
  @arguments[:http] ||= {}
135
135
  @arguments[:enable_meta_header] = arguments.fetch(:enable_meta_header, true)
136
136
 
137
- @hosts ||= __extract_hosts(@arguments[:hosts] ||
138
- @arguments[:host] ||
139
- @arguments[:url] ||
140
- @arguments[:urls] ||
141
- ENV['ELASTICSEARCH_URL'] ||
142
- DEFAULT_HOST)
143
-
137
+ @hosts ||= extract_hosts
144
138
  @send_get_body_as = @arguments[:send_get_body_as] || 'GET'
145
139
  @ca_fingerprint = @arguments.delete(:ca_fingerprint)
146
140
 
@@ -153,7 +147,7 @@ module Elastic
153
147
  else
154
148
  @transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS
155
149
  @transport = if @transport_class == Transport::HTTP::Faraday
156
- @arguments[:adapter] ||= __auto_detect_adapter
150
+ @arguments[:adapter] ||= auto_detect_adapter
157
151
  set_meta_header # from include MetaHeader
158
152
  @transport_class.new(hosts: @hosts, options: @arguments) do |faraday|
159
153
  faraday.adapter(@arguments[:adapter])
@@ -246,7 +240,7 @@ module Elastic
246
240
  #
247
241
  # @api private
248
242
  #
249
- def __extract_hosts(hosts_config)
243
+ def extract_hosts
250
244
  hosts = case hosts_config
251
245
  when String
252
246
  hosts_config.split(',').map { |h| h.strip! || h }
@@ -257,12 +251,20 @@ module Elastic
257
251
  else
258
252
  Array(hosts_config)
259
253
  end
260
-
261
- host_list = hosts.map { |host| __parse_host(host) }
254
+ host_list = hosts.map { |host| parse_host(host) }
262
255
  @arguments[:randomize_hosts] ? host_list.shuffle! : host_list
263
256
  end
264
257
 
265
- def __parse_host(host)
258
+ def hosts_config
259
+ @arguments[:hosts] ||
260
+ @arguments[:host] ||
261
+ @arguments[:url] ||
262
+ @arguments[:urls] ||
263
+ ENV['ELASTICSEARCH_URL'] ||
264
+ DEFAULT_HOST
265
+ end
266
+
267
+ def parse_host(host)
266
268
  host_parts = case host
267
269
  when String
268
270
  if host =~ /^[a-z]+\:\/\//
@@ -313,12 +315,14 @@ module Elastic
313
315
  #
314
316
  # @api private
315
317
  #
316
- def __auto_detect_adapter
318
+ def auto_detect_adapter
317
319
  if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
318
320
  return :patron if defined?(Faraday::Adapter::Patron)
319
321
  return :typhoeus if defined?(Faraday::Adapter::Typhoeus)
320
322
  return :httpclient if defined?(Faraday::Adapter::HTTPClient)
321
323
  return :net_http_persistent if defined?(Faraday::Adapter::NetHttpPersistent)
324
+ return :excon if defined?(Faraday::Adapter::Excon)
325
+ return :async_http if defined?(Async::HTTP::Faraday)
322
326
  else
323
327
  return :patron if defined?(::Patron)
324
328
  return :typhoeus if defined?(::Typhoeus)
@@ -21,70 +21,77 @@ module Elastic
21
21
  #
22
22
  # @api private
23
23
  class OpenTelemetry
24
- OTEL_TRACER_NAME = 'elasticsearch-api'
24
+ OTEL_TRACER_NAME = 'elasticsearch-api'.freeze
25
25
  # Valid values for the enabled config are 'true' and 'false'. Default is 'true'.
26
- ENV_VARIABLE_ENABLED = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_ENABLED'
26
+ ENV_VARIABLE_ENABLED = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_ENABLED'.freeze
27
27
  # Describes how to handle search queries in the request body when assigned to
28
28
  # a span attribute.
29
29
  # Valid values are 'raw', 'omit', 'sanitize'. Default is 'omit'.
30
- ENV_VARIABLE_BODY_STRATEGY = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'
31
- ENV_VARIABLE_DEPRECATED_BODY_STRATEGY = 'OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'
32
- DEFAULT_BODY_STRATEGY = 'omit'
30
+ ENV_VARIABLE_BODY_STRATEGY = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'.freeze
31
+ ENV_VARIABLE_DEPRECATED_BODY_STRATEGY = 'OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY'.freeze
32
+ DEFAULT_BODY_STRATEGY = 'omit'.freeze
33
33
  # A string list of keys whose values are redacted. This is only relevant if the body strategy is
34
34
  # 'sanitize'. For example, a config 'sensitive-key,other-key' will redact the values at
35
35
  # 'sensitive-key' and 'other-key' in addition to the default keys.
36
- ENV_VARIABLE_BODY_SANITIZE_KEYS = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS'
36
+ ENV_VARIABLE_BODY_SANITIZE_KEYS = 'OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS'.freeze
37
37
 
38
38
  # A list of the Elasticsearch endpoints that qualify as "search" endpoints. The search query in
39
39
  # the request body may be captured for these endpoints, depending on the body capture strategy.
40
40
  SEARCH_ENDPOINTS = Set[
41
- "search",
42
- "async_search.submit",
43
- "msearch",
44
- "eql.search",
45
- "terms_enum",
46
- "search_template",
47
- "msearch_template",
48
- "render_search_template",
41
+ 'search',
42
+ 'async_search.submit',
43
+ 'msearch',
44
+ 'eql.search',
45
+ 'terms_enum',
46
+ 'search_template',
47
+ 'msearch_template',
48
+ 'render_search_template',
49
49
  ]
50
50
 
51
51
  # Initialize the Open Telemetry wrapper object. Takes the options originally passed to
52
52
  # Client#initialize.
53
53
  def initialize(opts)
54
- @tracer = (opts[:opentelemetry_tracer_provider] || ::OpenTelemetry.tracer_provider).tracer(
55
- OTEL_TRACER_NAME, Elastic::Transport::VERSION
56
- )
57
- @body_strategy = ENV[ENV_VARIABLE_DEPRECATED_BODY_STRATEGY] || ENV[ENV_VARIABLE_BODY_STRATEGY] ||
58
- DEFAULT_BODY_STRATEGY
54
+ @tracer = tracer_provider(opts).tracer(OTEL_TRACER_NAME, Elastic::Transport::VERSION)
55
+ @body_strategy = ENV[ENV_VARIABLE_DEPRECATED_BODY_STRATEGY] ||
56
+ ENV[ENV_VARIABLE_BODY_STRATEGY] ||
57
+ DEFAULT_BODY_STRATEGY
59
58
  @sanitize_keys = ENV[ENV_VARIABLE_BODY_SANITIZE_KEYS]&.split(',')&.collect! do |pattern|
60
59
  Regexp.new(pattern.gsub('*', '.*'))
61
60
  end
62
61
  end
63
62
  attr_accessor :tracer
64
63
 
64
+ def tracer_provider(opts)
65
+ opts[:opentelemetry_tracer_provider] || ::OpenTelemetry.tracer_provider
66
+ end
67
+
65
68
  # Process the request body. Applies the body strategy, which can be one of the following:
66
- # 'omit': return nil
69
+ # 'omit' (DEFAULT_BODY_STRATEGY): return nil
67
70
  # 'sanitize': redact values at the default list of keys + any additional keys provided in
68
71
  # the OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_SEARCH_QUERY_SANITIZE_KEYS env variable.
69
72
  # 'raw': return the original body, unchanged
70
73
  def process_body(body, endpoint)
71
- unless @body_strategy == 'omit' || !SEARCH_ENDPOINTS.include?(endpoint)
72
- if @body_strategy == 'sanitize'
73
- Sanitizer.sanitize(body, @sanitize_keys).to_json
74
- elsif @body_strategy == 'raw'
75
- body&.is_a?(String) ? body : body.to_json
76
- end
74
+ return if @body_strategy == DEFAULT_BODY_STRATEGY || !search_endpoint?(endpoint)
75
+
76
+ if @body_strategy == 'sanitize'
77
+ Sanitizer.sanitize(body, @sanitize_keys).to_json
78
+ elsif @body_strategy == 'raw'
79
+ body.is_a?(String) ? body : body.to_json
77
80
  end
78
81
  end
79
82
 
83
+ def search_endpoint?(endpoint)
84
+ SEARCH_ENDPOINTS.include?(endpoint)
85
+ end
86
+
80
87
  # Replaces values in a hash with 'REDACTED', given a set of keys to match on.
81
88
  class Sanitizer
82
89
  class << self
83
- FILTERED = 'REDACTED'
90
+ FILTERED = 'REDACTED'.freeze
84
91
  DEFAULT_KEY_PATTERNS =
85
92
  %w[password passwd pwd secret *key *token* *session* *credit* *card* *auth* set-cookie].map! do |p|
86
- Regexp.new(p.gsub('*', '.*'))
87
- end
93
+ Regexp.new(p.gsub('*', '.*'))
94
+ end
88
95
 
89
96
  def sanitize(body, key_patterns = [])
90
97
  patterns = DEFAULT_KEY_PATTERNS
@@ -83,7 +83,7 @@ module Elastic
83
83
  # @return [Connections::Connection]
84
84
  # @see Connections::Collection#get_connection
85
85
  #
86
- def get_connection(options={})
86
+ def get_connection(options = {})
87
87
  resurrect_dead_connections! if Time.now > @last_request_at + @resurrect_after
88
88
 
89
89
  @counter_mtx.synchronize { @counter += 1 }
@@ -120,7 +120,7 @@ module Elastic
120
120
  # @return [Connections::Collection]
121
121
  # @api private
122
122
  #
123
- def __rebuild_connections(arguments={})
123
+ def __rebuild_connections(arguments = {})
124
124
  @state_mutex.synchronize do
125
125
  @hosts = arguments[:hosts] || []
126
126
  @options = arguments[:options] || {}
@@ -232,7 +232,7 @@ module Elastic
232
232
  #
233
233
  # @api private
234
234
  #
235
- def __convert_to_json(o=nil, options={})
235
+ def __convert_to_json(o = nil, options = {})
236
236
  o.is_a?(String) ? o : serializer.dump(o, options)
237
237
  end
238
238
 
@@ -379,11 +379,11 @@ module Elastic
379
379
  private
380
380
 
381
381
  USER_AGENT_STR = 'User-Agent'.freeze
382
- USER_AGENT_REGEX = /user-?_?agent/
382
+ USER_AGENT_REGEX = /user-?_?agent/.freeze
383
383
  ACCEPT_ENCODING = 'Accept-Encoding'.freeze
384
384
  CONTENT_ENCODING = 'Content-Encoding'.freeze
385
385
  CONTENT_TYPE_STR = 'Content-Type'.freeze
386
- CONTENT_TYPE_REGEX = /content-?_?type/
386
+ CONTENT_TYPE_REGEX = /content-?_?type/.freeze
387
387
  DEFAULT_CONTENT_TYPE = 'application/json'.freeze
388
388
  GZIP = 'gzip'.freeze
389
389
  GZIP_FIRST_TWO_BYTES = '1f8b'.freeze
@@ -155,7 +155,6 @@ module Elastic
155
155
  "<#{self.class.name} host: #{host} (#{dead? ? 'dead since ' + dead_since.to_s : 'alive'})>"
156
156
  end
157
157
  end
158
-
159
158
  end
160
159
  end
161
160
  end
@@ -30,7 +30,7 @@ module Elastic
30
30
  # @return [Response]
31
31
  # @see Transport::Base#perform_request
32
32
  #
33
- def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
33
+ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
34
34
  super do |connection, url|
35
35
  capture_otel_span_attributes(connection, url)
36
36
  connection.connection.url = connection.full_url(path, params)
@@ -51,7 +51,6 @@ module Elastic
51
51
  connection.connection.headers = headers
52
52
  end
53
53
  end
54
-
55
54
  else raise ArgumentError, "Unsupported HTTP method: #{method}"
56
55
  end
57
56
 
@@ -73,7 +72,7 @@ module Elastic
73
72
  #
74
73
  # @return [Connections::Connection]
75
74
  #
76
- def __build_connection(host, options={}, block=nil)
75
+ def __build_connection(host, options = {}, block = nil)
77
76
  client = ::Curl::Easy.new
78
77
 
79
78
  apply_headers(client, options)
@@ -87,7 +86,7 @@ module Elastic
87
86
 
88
87
  client.instance_eval(&block) if block
89
88
 
90
- Connections::Connection.new :host => host, :connection => client
89
+ Connections::Connection.new(host: host, connection: client)
91
90
  end
92
91
 
93
92
  # Returns an array of implementation specific connection errors.
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elastic
19
19
  module Transport
20
- VERSION = '8.3.6'.freeze
20
+ VERSION = '8.4.1'.freeze
21
21
  end
22
22
  end
@@ -225,6 +225,38 @@ describe Elastic::Transport::Client do
225
225
  end
226
226
  end unless jruby?
227
227
 
228
+ context 'when the adapter is excon' do
229
+ let(:adapter) do
230
+ client.transport.connections.all.first.connection.builder.adapter
231
+ end
232
+
233
+ let(:client) do
234
+ require 'faraday/excon'
235
+
236
+ described_class.new(adapter: :excon, enable_meta_header: false)
237
+ end
238
+
239
+ it 'uses Faraday with the adapter' do
240
+ expect(adapter).to eq Faraday::Adapter::Excon
241
+ end
242
+ end if is_faraday_v2?
243
+
244
+ context 'when the adapter is async-http' do
245
+ let(:adapter) do
246
+ client.transport.connections.all.first.connection.builder.adapter
247
+ end
248
+
249
+ let(:client) do
250
+ require 'async/http/faraday'
251
+
252
+ described_class.new(adapter: :async_http, enable_meta_header: false)
253
+ end
254
+
255
+ it 'uses Faraday with the adapter' do
256
+ expect(adapter).to eq Async::HTTP::Faraday::Adapter
257
+ end
258
+ end unless jruby? || !is_faraday_v2?
259
+
228
260
  context 'when the adapter is specified as a string key' do
229
261
  let(:adapter) do
230
262
  client.transport.connections.all.first.connection.builder.adapter
@@ -1453,6 +1485,7 @@ describe Elastic::Transport::Client do
1453
1485
 
1454
1486
  context 'when using the HTTPClient adapter' do
1455
1487
  require 'faraday/httpclient'
1488
+ require 'mutex_m' if RUBY_VERSION >= '3.4'
1456
1489
 
1457
1490
  let(:client) do
1458
1491
  described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)
@@ -25,8 +25,8 @@ if defined?(::OpenTelemetry)
25
25
  let(:span) { exporter.finished_spans[0] }
26
26
 
27
27
  let(:client) do
28
- Elastic::Transport::Client.new(hosts: ELASTICSEARCH_HOSTS).tap do |_client|
29
- allow(_client).to receive(:__build_connections)
28
+ Elastic::Transport::Client.new(hosts: ELASTICSEARCH_HOSTS).tap do |client|
29
+ allow(client).to receive(:__build_connections)
30
30
  end
31
31
  end
32
32
 
@@ -36,7 +36,8 @@ if defined?(::OpenTelemetry)
36
36
  let(:tracer_provider) do
37
37
  double('tracer_provider').tap do |tp|
38
38
  expect(tp).to receive(:tracer).with(
39
- Elastic::Transport::OpenTelemetry::OTEL_TRACER_NAME, Elastic::Transport::VERSION
39
+ Elastic::Transport::OpenTelemetry::OTEL_TRACER_NAME,
40
+ Elastic::Transport::VERSION
40
41
  )
41
42
  end
42
43
  end
@@ -59,7 +60,7 @@ if defined?(::OpenTelemetry)
59
60
  it 'creates a span with path parameters' do
60
61
  client.perform_request(
61
62
  'POST', '/users/_create/abc', nil, { name: 'otel-test' }, nil,
62
- defined_params: {'index' => 'users', 'id' => 'abc'}, endpoint: 'create'
63
+ defined_params: { 'index' => 'users', 'id' => 'abc' }, endpoint: 'create'
63
64
  )
64
65
 
65
66
  span = exporter.finished_spans.find { |s| s.name == 'create' }
@@ -96,7 +97,7 @@ if defined?(::OpenTelemetry)
96
97
 
97
98
  context 'when a request is instrumented' do
98
99
  let(:body) do
99
- { query: { match: { password: { query: 'secret'} } } }
100
+ { query: { match: { password: { query: 'secret' } } } }
100
101
  end
101
102
 
102
103
  it 'creates a span and omits db.statement' do
@@ -214,9 +215,9 @@ if defined?(::OpenTelemetry)
214
215
 
215
216
  around(:example) do |ex|
216
217
  body_strategy = ENV[described_class::ENV_VARIABLE_BODY_STRATEGY]
217
- ENV[described_class::ENV_VARIABLE_BODY_STRATEGY] = 'omit'
218
+ ENV[described_class::ENV_VARIABLE_BODY_STRATEGY] = 'omit'
218
219
  ex.run
219
- ENV[described_class::ENV_VARIABLE_BODY_STRATEGY] = body_strategy
220
+ ENV[described_class::ENV_VARIABLE_BODY_STRATEGY]= body_strategy
220
221
  end
221
222
 
222
223
  it 'does not include anything' do
@@ -308,11 +309,11 @@ if defined?(::OpenTelemetry)
308
309
  let(:key_patterns) { [/something/] }
309
310
 
310
311
  let(:body) do
311
- { query: { match: { something: "test" } } }
312
+ { query: { match: { something: 'test' } } }
312
313
  end
313
314
 
314
315
  let(:expected_body) do
315
- { query: { match: { something: "REDACTED" } } }
316
+ { query: { match: { something: 'REDACTED' } } }
316
317
  end
317
318
 
318
319
  it 'redacts sensitive values' do
@@ -72,6 +72,22 @@ class Elastic::Transport::ClientAdaptersUnitTest < Minitest::Test
72
72
  end
73
73
  end
74
74
 
75
+ should 'use Excon Faraday adapter' do
76
+ fork do
77
+ require 'faraday/excon'
78
+ client = Elastic::Transport::Client.new
79
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Excon)
80
+ end
81
+ end if is_faraday_v2?
82
+
83
+ should 'use Async HTTP Faraday adapter' do
84
+ fork do
85
+ require 'async/http/faraday'
86
+ client = Elastic::Transport::Client.new
87
+ assert_equal(client.transport.connections.first.connection.adapter, Async::HTTP::Faraday::Adapter)
88
+ end
89
+ end if is_faraday_v2?
90
+
75
91
  should 'use HTTPClient Faraday adapter' do
76
92
  fork do
77
93
  if is_faraday_v2?
@@ -81,7 +97,7 @@ class Elastic::Transport::ClientAdaptersUnitTest < Minitest::Test
81
97
  end
82
98
 
83
99
  client = Elastic::Transport::Client.new
84
- assert_equal(Faraday::Adapter::HTTPClient, client.transport.connections.first.connection.adapter)
100
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
85
101
  end
86
102
  end
87
103
  end unless jruby?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.3.6
4
+ version: 8.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic Client Library Maintainers