@@ -2752,49 +2752,106 @@ zend_string *get_env() {
27522752 return get_DD_ENV ();
27532753}
27542754
2755+ ddog_Method dd_string_to_method (zend_string * method ) {
2756+ if (zend_string_equals_literal (method , "GET" )) {
2757+ return DDOG_METHOD_GET ;
2758+ }
2759+ if (zend_string_equals_literal (method , "POST" )) {
2760+ return DDOG_METHOD_POST ;
2761+ }
2762+ if (zend_string_equals_literal (method , "PUT" )) {
2763+ return DDOG_METHOD_PUT ;
2764+ }
2765+ if (zend_string_equals_literal (method , "DELETE" )) {
2766+ return DDOG_METHOD_DELETE ;
2767+ }
2768+ if (zend_string_equals_literal (method , "PATCH" )) {
2769+ return DDOG_METHOD_PATCH ;
2770+ }
2771+ if (zend_string_equals_literal (method , "HEAD" )) {
2772+ return DDOG_METHOD_HEAD ;
2773+ }
2774+ if (zend_string_equals_literal (method , "OPTIONS" )) {
2775+ return DDOG_METHOD_OPTIONS ;
2776+ }
2777+ if (zend_string_equals_literal (method , "TRACE" )) {
2778+ return DDOG_METHOD_TRACE ;
2779+ }
2780+ if (zend_string_equals_literal (method , "CONNECT" )) {
2781+ return DDOG_METHOD_CONNECT ;
2782+ }
2783+ return DDOG_METHOD_OTHER ;
2784+ }
2785+
27552786PHP_FUNCTION (DDTrace_add_endpoint ) {
27562787 UNUSED (execute_data );
2757- zend_string * type = NULL ;
27582788 zend_string * path = NULL ;
27592789 zend_string * operation_name = NULL ;
27602790 zend_string * resource_name = NULL ;
2791+ zend_string * method = NULL ;
2792+ zend_string * type = NULL ;
27612793 zend_string * request_body_type = NULL ;
27622794 zend_string * response_body_type = NULL ;
27632795 zend_long response_code = 0 ;
27642796 zend_long authentication = 0 ;
2765- zend_string * metadata = NULL ;
2797+ zend_string * metadata_input = NULL ;
27662798
2767- if (zend_parse_parameters (ZEND_NUM_ARGS (), "SSSSSSllS " , & type , & path , & operation_name , & resource_name , & request_body_type , & response_body_type ,
2768- & response_code , & authentication , & metadata ) == FAILURE ) {
2799+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "SSSS|SSllS " , & path , & operation_name , & resource_name , & method , & type , & request_body_type , & response_body_type ,
2800+ & response_code , & authentication , & metadata_input ) == FAILURE ) {
27692801 RETURN_FALSE ;
27702802 }
27712803
2804+ zend_string * default_metadata = NULL ;
2805+ zend_string * metadata = metadata_input ;
2806+ if (metadata == NULL ) {
2807+ default_metadata = zend_string_init (ZEND_STRL ("{}" ), 0 );
2808+ metadata = default_metadata ;
2809+ }
2810+
27722811 ddog_CharSlice type_slice = dd_zend_string_to_CharSlice (type );
2773- ddog_Method method_enum = DDOG_METHOD_GET ;
2812+ ddog_Method method_enum = dd_string_to_method ( method ) ;
27742813 ddog_CharSlice path_slice = dd_zend_string_to_CharSlice (path );
27752814 ddog_CharSlice operation_name_slice = dd_zend_string_to_CharSlice (operation_name );
27762815 ddog_CharSlice resource_name_slice = dd_zend_string_to_CharSlice (resource_name );
2777- struct ddog_Vec_CharSlice * request_body_type_vec = ddog_CharSlice_to_owned (dd_zend_string_to_CharSlice (request_body_type ));
2778- struct ddog_Vec_CharSlice * response_body_type_vec = ddog_CharSlice_to_owned (dd_zend_string_to_CharSlice (response_body_type ));
2779- struct ddog_Vec_Authentication * authentication_vec = ddog_number_to_owned_Authentication (authentication );
2816+ struct ddog_Vec_CharSlice * request_body_type_vec = NULL ;
2817+ if (request_body_type ) {
2818+ request_body_type_vec = ddog_CharSlice_to_owned (dd_zend_string_to_CharSlice (request_body_type ));
2819+ }
2820+ struct ddog_Vec_CharSlice * response_body_type_vec = NULL ;
2821+ if (response_body_type ) {
2822+ response_body_type_vec = ddog_CharSlice_to_owned (dd_zend_string_to_CharSlice (response_body_type ));
2823+ }
2824+ struct ddog_Vec_Authentication * authentication_vec = NULL ;
2825+ if (authentication ) {
2826+ authentication_vec = ddog_number_to_owned_Authentication (authentication );
2827+ }
27802828
2781- size_t len = ZSTR_LEN (metadata );
2782- zend_string * metadata_utf8 = NULL ;
27832829 ddog_CharSlice metadata_slice = {0 };
2784- char * stripped_utf8 = ddtrace_strip_invalid_utf8 (ZSTR_VAL (metadata ), & len );
2785- if (stripped_utf8 != NULL && len > 0 ) {
2786- metadata_utf8 = zend_string_init (stripped_utf8 , len , 0 );
2787- metadata_slice = dd_zend_string_to_CharSlice (metadata_utf8 );
2830+ if (metadata && ZSTR_LEN (metadata ) > 0 ) {
2831+ size_t len = ZSTR_LEN (metadata );
2832+ char * stripped_utf8 = ddtrace_strip_invalid_utf8 (ZSTR_VAL (metadata ), & len );
2833+ if (stripped_utf8 != NULL && len > 0 ) {
2834+ zend_string * metadata_utf8 = zend_string_init (stripped_utf8 , len , 0 );
2835+ metadata_slice = dd_zend_string_to_CharSlice (metadata_utf8 );
2836+ ddtrace_drop_rust_string (stripped_utf8 , len );
2837+ // metadata_utf8 will be released by Zend after function returns or at cleanup
2838+ } else {
2839+ metadata_slice = dd_zend_string_to_CharSlice (metadata );
2840+ }
27882841 }
27892842
27902843 if (!ddtrace_sidecar || !ddtrace_sidecar_instance_id || !DDTRACE_G (sidecar_queue_id )) {
27912844 RETURN_FALSE ;
27922845 }
27932846
2794- ddog_sidecar_telemetry_addEndpoint (& ddtrace_sidecar , ddtrace_sidecar_instance_id , & DDTRACE_G (sidecar_queue_id ), type_slice , method_enum ,
2847+ ddog_sidecar_telemetry_addEndpoint_buffer (& ddtrace_sidecar , ddtrace_sidecar_instance_id , & DDTRACE_G (sidecar_queue_id ), type_slice , method_enum ,
27952848 path_slice , operation_name_slice , resource_name_slice , request_body_type_vec , response_body_type_vec ,
27962849 response_code , authentication_vec , metadata_slice );
27972850
2851+ if (!metadata_input ) {
2852+ zend_string_release (default_metadata );
2853+ }
2854+
27982855 RETURN_TRUE ;
27992856}
28002857
0 commit comments