Skip to content

Commit 7d9c4c0

Browse files
zsistlalavarou
andauthored
refactor(agent): Use macro for command comparisons.
Co-authored-by: Michal Nowacki <[email protected]>
1 parent 43fa2b8 commit 7d9c4c0

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

agent/lib_aws_sdk_php.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,21 @@ void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
107107
}
108108

109109
/* Determine if we instrument this command. */
110-
if (command_name_len == AWS_SQS_SEND_MESSAGE_BATCH_COMMAND_LEN
111-
&& 0
112-
== nr_strncmp(AWS_SQS_SEND_MESSAGE_BATCH_COMMAND,
113-
command_name_string,
114-
AWS_SQS_SEND_MESSAGE_BATCH_COMMAND_LEN)) {
110+
#define COMMAND_IS(CMD) \
111+
(command_name_len == (sizeof(CMD) - 1) && nr_streq(CMD, command_name_string))
112+
113+
/* Determine if we instrument this command. */
114+
if (COMMAND_IS("sendMessageBatch")) {
115115
message_params.message_action = NR_SPANKIND_PRODUCER;
116-
} else if (command_name_len == AWS_SQS_SEND_MESSAGE_COMMAND_LEN
117-
&& 0
118-
== nr_strncmp(AWS_SQS_SEND_MESSAGE_COMMAND,
119-
command_name_string,
120-
AWS_SQS_SEND_MESSAGE_COMMAND_LEN)) {
116+
} else if (COMMAND_IS("sendMessage")) {
121117
message_params.message_action = NR_SPANKIND_PRODUCER;
122-
} else if (command_name_len == AWS_SQS_RECEIVE_MESSAGE_COMMAND_LEN
123-
&& 0
124-
== nr_strncmp(AWS_SQS_RECEIVE_MESSAGE_COMMAND,
125-
command_name_string,
126-
AWS_SQS_RECEIVE_MESSAGE_COMMAND_LEN)) {
118+
} else if (COMMAND_IS("receiveMessage")) {
127119
message_params.message_action = NR_SPANKIND_CONSUMER;
128120
} else {
129121
/* Nothing to do here so exit. */
130122
return;
131123
}
124+
#undef IS_COMMAND
132125

133126
cloud_attrs.aws_operation = command_name_string;
134127

0 commit comments

Comments
 (0)