Skip to content

Commit 8683e2c

Browse files
umaannamalaimergify[bot]TimPansino
authored
Remove instrumentation for options method on async ElasticSearch client. (#1477)
* Remove instrumentation for options method on async ES client. * Add skip if lower than v8. * Ignore options method in instrumented methods test. * Lint --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Tim Pansino <[email protected]>
1 parent 1a2fe33 commit 8683e2c

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

newrelic/hooks/datastore_elasticsearch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ async def _nr_wrapper_AsyncElasticsearch_method_(wrapped, instance, args, kwargs
270270
("msearch_template", _extract_args_search_templates_index),
271271
("mtermvectors", _extract_args_index),
272272
("open_point_in_time", _extract_args_index),
273-
("options", None),
274273
("ping", None),
275274
("put_script", None),
276275
("rank_eval", _extract_args_requests_index),

tests/datastore_elasticsearch/test_async_elasticsearch.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from conftest import ES_SETTINGS, IS_V8_OR_ABOVE
14+
from conftest import ES_SETTINGS, IS_V8_OR_ABOVE, RUN_IF_V8_OR_ABOVE
1515
from elasticsearch._async import client
1616
from testing_support.fixture.event_loop import event_loop as loop
1717
from testing_support.fixtures import override_application_settings
@@ -215,3 +215,20 @@ def test_async_elasticsearch_operation_enabled_empty_transaction_settings(async_
215215

216216
def test_async_elasticsearch_no_transaction(async_client, loop):
217217
loop.run_until_complete(_exercise_es(async_client))
218+
219+
220+
@RUN_IF_V8_OR_ABOVE
221+
@background_task()
222+
def test_async_elasticsearch_options_no_crash(async_client, loop):
223+
"""Test that the options method on the async client doesn't cause a crash when run with the agent"""
224+
225+
async def _test():
226+
client_with_auth = async_client.options(basic_auth=("username", "password"))
227+
assert client_with_auth is not None
228+
assert client_with_auth != async_client
229+
230+
# If options was instrumented, this would cause a crash since the first call would return an unexpected coroutine
231+
client_chained = async_client.options(basic_auth=("user", "pass")).options(request_timeout=60)
232+
assert client_chained is not None
233+
234+
loop.run_until_complete(_test())

tests/datastore_elasticsearch/test_async_instrumented_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def _test():
7575

7676
def _test_methods_wrapped(_object, ignored_methods=None):
7777
if not ignored_methods:
78-
ignored_methods = {"perform_request", "transport"}
78+
ignored_methods = {"perform_request", "transport", "options"}
7979

8080
def is_wrapped(m):
8181
return hasattr(getattr(_object, m), "__wrapped__")

tests/datastore_elasticsearch/test_instrumented_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _test():
8484

8585
def _test_methods_wrapped(_object, ignored_methods=None):
8686
if not ignored_methods:
87-
ignored_methods = {"perform_request", "transport"}
87+
ignored_methods = {"perform_request", "transport", "options"}
8888

8989
def is_wrapped(m):
9090
return hasattr(getattr(_object, m), "__wrapped__")

0 commit comments

Comments
 (0)