Skip to content

Commit 2909603

Browse files
TimPansinomergify[bot]hmstepanek
authored
Botocore SQS Code Cleanup (#1187)
* Rename SQS specific function for clarity * Trim out unnecessary extra function * Fix bug where params was not passed through SQS wrapper (unused currently) * Remove unused imports --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Hannah Stepanek <[email protected]>
1 parent 4e2dd16 commit 2909603

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

newrelic/hooks/external_botocore.py

+8-31
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import functools
1615
import json
1716
import logging
1817
import re
@@ -31,7 +30,6 @@
3130
from newrelic.api.transaction import current_transaction
3231
from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper
3332
from newrelic.common.object_wrapper import (
34-
FunctionWrapper,
3533
ObjectProxy,
3634
function_wrapper,
3735
wrap_function_wrapper,
@@ -59,7 +57,7 @@ def extract_sqs(*args, **kwargs):
5957
return queue_value.rsplit("/", 1)[-1]
6058

6159

62-
def extract_agent_attrs(*args, **kwargs):
60+
def extract_sqs_agent_attrs(*args, **kwargs):
6361
# Try to capture AWS SQS info as agent attributes. Log any exception to debug.
6462
agent_attrs = {}
6563
try:
@@ -848,29 +846,8 @@ def sqs_message_trace(
848846
async_wrapper=None,
849847
extract_agent_attrs=None,
850848
):
851-
return functools.partial(
852-
SQSMessageTraceWrapper,
853-
operation=operation,
854-
destination_type=destination_type,
855-
destination_name=destination_name,
856-
params=params,
857-
terminal=terminal,
858-
async_wrapper=async_wrapper,
859-
extract_agent_attrs=extract_agent_attrs,
860-
)
861-
862-
863-
def SQSMessageTraceWrapper(
864-
wrapped,
865-
operation,
866-
destination_type,
867-
destination_name,
868-
params={},
869-
terminal=True,
870-
async_wrapper=None,
871-
extract_agent_attrs=None,
872-
):
873-
def _nr_message_trace_wrapper_(wrapped, instance, args, kwargs):
849+
@function_wrapper
850+
def _nr_sqs_message_trace_wrapper_(wrapped, instance, args, kwargs):
874851
wrapper = async_wrapper if async_wrapper is not None else get_async_wrapper(wrapped)
875852
if not wrapper:
876853
parent = current_trace()
@@ -889,7 +866,7 @@ def _nr_message_trace_wrapper_(wrapped, instance, args, kwargs):
889866
_operation,
890867
_destination_type,
891868
_destination_name,
892-
params={},
869+
params=params,
893870
terminal=terminal,
894871
parent=parent,
895872
source=wrapped,
@@ -905,7 +882,7 @@ def _nr_message_trace_wrapper_(wrapped, instance, args, kwargs):
905882
with trace:
906883
return wrapped(*args, **kwargs)
907884

908-
return FunctionWrapper(wrapped, _nr_message_trace_wrapper_)
885+
return _nr_sqs_message_trace_wrapper_
909886

910887

911888
CUSTOM_TRACE_POINTS = {
@@ -919,13 +896,13 @@ def _nr_message_trace_wrapper_(wrapped, instance, args, kwargs):
919896
("dynamodb", "query"): datastore_trace("DynamoDB", extract("TableName"), "query"),
920897
("dynamodb", "scan"): datastore_trace("DynamoDB", extract("TableName"), "scan"),
921898
("sqs", "send_message"): sqs_message_trace(
922-
"Produce", "Queue", extract_sqs, extract_agent_attrs=extract_agent_attrs
899+
"Produce", "Queue", extract_sqs, extract_agent_attrs=extract_sqs_agent_attrs
923900
),
924901
("sqs", "send_message_batch"): sqs_message_trace(
925-
"Produce", "Queue", extract_sqs, extract_agent_attrs=extract_agent_attrs
902+
"Produce", "Queue", extract_sqs, extract_agent_attrs=extract_sqs_agent_attrs
926903
),
927904
("sqs", "receive_message"): sqs_message_trace(
928-
"Consume", "Queue", extract_sqs, extract_agent_attrs=extract_agent_attrs
905+
"Consume", "Queue", extract_sqs, extract_agent_attrs=extract_sqs_agent_attrs
929906
),
930907
("bedrock-runtime", "invoke_model"): wrap_bedrock_runtime_invoke_model(response_streaming=False),
931908
("bedrock-runtime", "invoke_model_with_response_stream"): wrap_bedrock_runtime_invoke_model(

0 commit comments

Comments
 (0)