php_skywalking.h 6.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
  +----------------------------------------------------------------------+
  | PHP Version 7                                                        |
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2017 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.01 of the PHP license,      |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.php.net/license/3_01.txt                                  |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net so we can mail you a copy immediately.               |
  +----------------------------------------------------------------------+
  | Author:                                                              |
  +----------------------------------------------------------------------+
*/

/* $Id$ */

#ifndef PHP_SKYWALKING_H
#define PHP_SKYWALKING_H

extern zend_module_entry skywalking_module_entry;
#define phpext_skywalking_ptr &skywalking_module_entry

H
heyanlong 已提交
27
#define PHP_SKYWALKING_VERSION "5.0.0" /* Replace with version number for your extension */
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

#ifdef PHP_WIN32
#	define PHP_SKYWALKING_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
#	define PHP_SKYWALKING_API __attribute__ ((visibility("default")))
#else
#	define PHP_SKYWALKING_API
#endif

#ifdef ZTS
#include "TSRM.h"
#endif

#ifdef ZTS 
#define SKY_G(v) TSRMG(skywalking_globals_id, zend_skywalking_globals *, v)
#else
#define SKY_G(v) (skywalking_globals.v)
#endif

S
songzhian 已提交
47 48 49 50 51 52 53 54
#define S_SEND_TYPE_CLOSE   (1<<0L)
#define S_SEND_TYPE_GRPC    (1<<1L)
#define S_SEND_TYPE_WRITE   (1<<2L)

#define USE_PARENT_TRACE_ID 1
#define DONOT_USE_PARENT_TRACE_ID 0


H
heyanlong 已提交
55
#define SHARED_MEMORY_KEY 428935192
S
songzhian 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#define SKYWALKING_SEGMENT "sg" //全部段节点
#define SKYWALKING_DISTRIBUTED_TRACEIDS "gt"//DistributedTraceIds
#define SKYWALKING_TRACE_SEGMENT_ID "ts"//本次请求id
#define SKYWALKING_APPLICATION_ID "ai"//app id
#define SKYWALKING_APPLICATION_INSTANCE_ID "ii"//实例id
#define SKYWALKING_FATHER_NODE_DATA "rs" //父节点数据
#define SKYWALKING_SPANS_NODE_DATA "ss" //span节点数据集合

#define SKYWALKING_PARENT_TRACE_SEGMENT_ID "ts" //本次请求id
#define SKYWALKING_PARENT_APPLICATION_ID "ai"//app id
#define SKYWALKING_PARENT_SPAN_ID "si"//spanid
#define SKYWALKING_PARENT_SERVICE_ID "vi"//
#define SKYWALKING_PARENT_SERVICE_NAME "vn"
#define SKYWALKING_NETWORK_ADDRESS_ID "ni"
#define SKYWALKING_NETWORK_ADDRESS "nn"
#define SKYWALKING_ENTRY_APPLICATION_INSTANCE_ID "ea"
#define SKYWALKING_ENTRY_SERVICE_ID "ei"
#define SKYWALKING_ENTRY_SERVICE_NAME "en"
#define SKYWALKING_REF_TYPE_VALUE "rv"

#define SKYWALKING_SPAN_ID "si" //SpanId
#define SKYWALKING_SPAN_TYPE_VALUE "tv"
#define SKYWALKING_SPAN_LAYER_VALUE "lv"
#define SKYWALKING_FATHER_SPAN_ID "ps" //父节点传过来的SpanId
#define SKYWALKING_STARTTIME "st" //开始时间
#define SKYWALKING_ENDTIME "et"  //结束时间
#define SKYWALKING_COMPONENT_ID "ci"
#define SKYWALKING_COMPONENT_NAME "cn"
#define SKYWALKING_OPERATION_NAME_ID "oi"
#define SKYWALKING_OPERATION_NAME "on"// Span 的服务URI
#define SKYWALKING_PEER_ID "pi"
#define SKYWALKING_PEER "pn"
#define SKYWALKING_IS_ERROR "ie"
#define SKYWALKING_TAGS "to"
#define SKYWALKING_LOGS "lo"

#define SKYWALKING_KEY "k"
#define SKYWALKING_VALUE "v"

#define SKYWALKING_TIME "ti"
#define SKYWALKING_LOG_DATA "ld"


99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

#define RAND_RANGE(__n, __min, __max, __tmax) \
    (__n) = ((__min) + (zend_long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0))))

#define PHP_MT_RAND_MAX ((zend_long) (0x7FFFFFFF)) /* (1<<31) - 1 */

#ifdef PHP_WIN32
#define GENERATE_SEED() (((zend_long) (time(0) * GetCurrentProcessId())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
#else
#define GENERATE_SEED() (((zend_long) (time(0) * getpid())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
#endif


void *SKY_ADD_ASSOC_ZVAL(zval *z, const char *k) {

H
report  
heyanlong 已提交
114 115 116 117
    zval null_array;
    array_init(&null_array);
    add_assoc_zval(z, k, &null_array);
    return NULL;
118 119
}

G
goerzh 已提交
120 121 122 123 124 125 126 127 128 129 130
typedef struct ContextCarrier {
    zval *primaryDistributedTraceId;
    zval *traceSegmentId;
    zval *spanId;
    zval *parentServiceInstanceId;
    zval *entryServiceInstanceId;
    zval *peerHost;
    zval *entryEndpointName;
    zval *parentEndpointName;
}ContextCarrier;

S
songzhian 已提交
131

132
static char *sky_json_encode(zval *parameter);
H
report  
heyanlong 已提交
133
static long get_second();
134
static char *get_millisecond();
H
heyanlong 已提交
135
static char *generate_sw3(zend_long span_id, char *peer_host, char *operation_name);
H
report  
heyanlong 已提交
136
static void generate_context();
H
heyanlong 已提交
137
static char *get_page_request_uri();
H
report  
heyanlong 已提交
138
static void write_log( char *text);
H
heyanlong 已提交
139
static void request_init();
S
songzhian 已提交
140

H
heyanlong 已提交
141
void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS);
H
heyanlong 已提交
142 143
void sky_curl_setopt_handler(INTERNAL_FUNCTION_PARAMETERS);
void sky_curl_setopt_array_handler(INTERNAL_FUNCTION_PARAMETERS);
H
heyanlong 已提交
144
void sky_curl_close_handler(INTERNAL_FUNCTION_PARAMETERS);
S
songzhian 已提交
145

H
report  
heyanlong 已提交
146
static void sky_flush_all();
H
heyanlong 已提交
147 148
static zval *get_first_span();
static zval *get_spans();
S
songzhian 已提交
149 150
static char* _get_current_machine_ip();
static void (*orig_curl_exec)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
H
heyanlong 已提交
151
static void (*orig_curl_setopt)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
H
heyanlong 已提交
152
static void (*orig_curl_setopt_array)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
H
heyanlong 已提交
153
static void (*orig_curl_close)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
154 155 156 157 158
/*
  	Declare any global variables you may need between the BEGIN
	and END macros here:
*/
ZEND_BEGIN_MODULE_GLOBALS(skywalking)
H
report  
heyanlong 已提交
159 160 161 162 163 164
    char *log_path;
    char *app_code;
    zend_bool enable;
    char *grpc;
    zval UpstreamSegment;
    zval context;
H
heyanlong 已提交
165
    zval curl_header;
H
heyanlong 已提交
166
    zval curl_header_send;
H
heyanlong 已提交
167
    int  version;
G
goerzh 已提交
168
    int header_version;
169 170 171 172 173 174 175 176
ZEND_END_MODULE_GLOBALS(skywalking)

extern ZEND_DECLARE_MODULE_GLOBALS(skywalking);

/* Always refer to the globals in your function as SKYWALKING_G(variable).
   You are encouraged to rename these macros something shorter, see
   examples in any other php module directory.
*/
H
heyanlong 已提交
177 178 179
#ifdef ZTS
#define SKYWALKING_G(v) TSRMG(skywalking_globals_id, zend_skywalking_globals *, v)
#else
180
#define SKYWALKING_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(skywalking, v)
H
heyanlong 已提交
181
#endif
182 183 184 185 186

#if defined(ZTS) && defined(COMPILE_DL_SKYWALKING)
ZEND_TSRMLS_CACHE_EXTERN()
#endif

S
songzhian 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

#ifdef __unix


#ifdef __linux
#define SKY_OS_NAME "Linux"
#endif

#ifdef __sun
    #ifdef __sparc
#define SKY_OS_NAME "Sun SPARC"
    #else
#define SKY_OS_NAME "Sun X86"
    #endif
#endif

#ifdef _AIX
#define SKY_OS_NAME "AIX"
#endif

#else


#ifdef WINVER
#define SKY_OS_NAME "Windows"
#else
H
report  
heyanlong 已提交
213 214 215
#ifdef __APPLE__
#define SKY_OS_NAME "Darwin"
#else
S
songzhian 已提交
216 217
#define SKY_OS_NAME "Unknown"
#endif
H
report  
heyanlong 已提交
218
#endif
S
songzhian 已提交
219 220 221 222 223 224
 

#endif



225 226 227 228 229 230 231 232 233 234 235
#endif	/* PHP_SKYWALKING_H */


/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noet sw=4 ts=4 fdm=marker
 * vim<600: noet sw=4 ts=4
 */