86
86
87
87
//clang-format on
88
88
*/
89
- void nr_lib_aws_sdk_php_sqs_handle (nr_segment_t * segment ,
89
+ void nr_lib_aws_sdk_php_sqs_handle (nr_segment_t * auto_segment ,
90
90
char * command_name_string ,
91
91
size_t command_name_len ,
92
92
NR_EXECUTE_PROTO ) {
93
93
char * command_arg_value = NULL ;
94
+ nr_segment_t * message_segment = NULL ;
95
+
94
96
nr_segment_message_params_t message_params = {
95
97
.library = SQS_LIBRARY_NAME ,
96
98
.destination_type = NR_MESSAGE_DESTINATION_TYPE_QUEUE ,
97
99
.messaging_system = AWS_SQS_MESSAGING_SERVICE ,
98
100
};
99
101
nr_segment_cloud_attrs_t cloud_attrs = {0 };
100
102
101
- if (NULL == segment ) {
103
+ if (NULL == auto_segment ) {
102
104
return ;
103
105
}
104
106
@@ -122,6 +124,17 @@ void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
122
124
}
123
125
#undef AWS_COMMAND_IS
124
126
127
+ /*
128
+ * By this point, it's been determined that this call will be instrumented so
129
+ * only create the segment now, grab the parent segment start time, add our
130
+ * special segment attributes/metrics then close the newly created segment.
131
+ */
132
+ message_segment = nr_segment_start (NRPRG (txn ), NULL , NULL );
133
+ if (NULL == message_segment ) {
134
+ return ;
135
+ }
136
+ /* re-use start time from auto_segment started in func_begin */
137
+ message_segment -> start_time = auto_segment -> start_time ;
125
138
cloud_attrs .aws_operation = command_name_string ;
126
139
127
140
command_arg_value = nr_lib_aws_sdk_php_get_command_arg_value (
@@ -136,10 +149,10 @@ void nr_lib_aws_sdk_php_sqs_handle(nr_segment_t* segment,
136
149
137
150
/* Add cloud attributes, if available. */
138
151
139
- nr_segment_traces_add_cloud_attributes (segment , & cloud_attrs );
152
+ nr_segment_traces_add_cloud_attributes (message_segment , & cloud_attrs );
140
153
141
154
/* Now end the instrumented segment as a message segment. */
142
- nr_segment_message_end (& segment , & message_params );
155
+ nr_segment_message_end (& message_segment , & message_params );
143
156
144
157
nr_free (command_arg_value );
145
158
}
@@ -332,20 +345,6 @@ char* nr_lib_aws_sdk_php_get_command_arg_value(char* command_arg_name,
332
345
* @throws \Exception
333
346
*/
334
347
335
- NR_PHP_WRAPPER (nr_aws_client_call_before ) {
336
- (void )wraprec ;
337
- nr_segment_t * segment = NULL ;
338
- /*
339
- * Start a segment in case it needs to become an external, message, or
340
- * datastore segment.
341
- */
342
- segment = nr_segment_start (NRPRG (txn ), NULL , NULL );
343
- if (NULL != segment ) {
344
- segment -> wraprec = auto_segment -> wraprec ;
345
- }
346
- }
347
- NR_PHP_WRAPPER_END
348
-
349
348
NR_PHP_WRAPPER (nr_aws_client_call ) {
350
349
(void )wraprec ;
351
350
@@ -388,16 +387,6 @@ NR_PHP_WRAPPER(nr_aws_client_call) {
388
387
389
388
#undef AWS_CLASS_IS
390
389
391
- if (NR_SEGMENT_CUSTOM == auto_segment -> type ) {
392
- /*
393
- * We need to end the segment that we started in the 'before' wrapper if
394
- * it wasn't handled and ended by the handling function. Handling
395
- * function would have changed the segment type from from default
396
- * (`NR_SEGMENT_CUSTOM`) if it ended it.
397
- */
398
- nr_segment_discard (& auto_segment );
399
- }
400
-
401
390
/*
402
391
* Since we have klass and command_name, we can give the calling segment
403
392
* a more meaningful name than Aws/AwsClient::__call We can decode it to
@@ -406,11 +395,10 @@ NR_PHP_WRAPPER(nr_aws_client_call) {
406
395
* EX: Aws\\Sqs\\SqsClient::sendMessage
407
396
*/
408
397
409
- segment = nr_txn_get_current_segment (NRPRG (txn ), NULL );
410
- if (NULL != segment ) {
398
+ if (NULL != auto_segment ) {
411
399
real_class_and_command
412
400
= nr_formatf ("Custom/%s::%s" , klass , command_name_string );
413
- nr_segment_set_name (segment , real_class_and_command );
401
+ nr_segment_set_name (auto_segment , real_class_and_command );
414
402
nr_free (real_class_and_command );
415
403
}
416
404
@@ -576,7 +564,7 @@ void nr_aws_sdk_php_enable() {
576
564
/* We only support instrumentation above PHP 8.1 */
577
565
/* Called when a service command is issued from a Client */
578
566
nr_php_wrap_user_function_before_after_clean (
579
- NR_PSTR ("Aws\\AwsClient::__call" ), nr_aws_client_call_before ,
580
- nr_aws_client_call , nr_aws_client_call );
567
+ NR_PSTR ("Aws\\AwsClient::__call" ), NULL , nr_aws_client_call ,
568
+ nr_aws_client_call );
581
569
#endif
582
570
}
0 commit comments