php_skywalking.h 8.0 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
3.1.4  
heyanlong 已提交
27
#define PHP_SKYWALKING_VERSION "3.1.4" /* 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
#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"

H
predis  
heyanlong 已提交
98 99 100 101 102 103 104 105 106 107
#define REDIS_KEY_KEY "|dump|exists|expire|expireat|move|persist|pexpire|pexpireat|pttl|rename|renamenx|sort|ttl|type|"
#define REDIS_KEY_STRING "|append|bitcount|bitfield|decr|decrby|get|getbit|getrange|getset|incr|incrby|incrbyfloat|psetex|set|setbit|setex|setnx|setrange|strlen|"
#define REDIS_OPERATION_STRING "|bitop|"
#define REDIS_KEY_HASH "|hdel|hexists|hget|hgetall|hincrby|hincrbyfloat|hkeys|hlen|hmget|hmset|hscan|hset|hsetnx|hvals|hstrlen|"
#define REDIS_KEY_LIST "|lindex|linsert|llen|lpop|lpush|lpushx|lrange|lrem|lset|ltrim|rpop|rpush|rpushx|"
#define REDIS_KEY_SET "|sadd|scard|sismember|smembers|spop|srandmember|srem|sscan|"
#define REDIS_KEY_SORT "|zadd|zcard|zcount|zincrby|zrange|zrangebyscore|zrank|zrem|zremrangebyrank|zremrangebyscore|zrevrange|zrevrangebyscore|zrevrank|zscore|zscan|zrangebylex|zrevrangebylex|zremrangebylex|zlexcount|"
#define REDIS_KEY_HLL "|pfadd|watch|"
#define REDIS_KEY_GEO "|geoadd|geohash|geopos|geodist|georadius|georadiusbymember|"

S
songzhian 已提交
108

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

#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 已提交
124 125 126 127
    zval null_array;
    array_init(&null_array);
    add_assoc_zval(z, k, &null_array);
    return NULL;
128 129
}

G
goerzh 已提交
130
typedef struct ContextCarrier {
G
goerzh 已提交
131 132 133 134 135 136 137 138
    zval primaryDistributedTraceId;
    zval traceSegmentId;
    zval spanId;
    zval parentServiceInstanceId;
    zval entryServiceInstanceId;
    zval peerHost;
    zval entryEndpointName;
    zval parentEndpointName;
G
goerzh 已提交
139 140
}ContextCarrier;

S
songzhian 已提交
141

142
static char *sky_json_encode(zval *parameter);
H
report  
heyanlong 已提交
143
static long get_second();
144
static char *get_millisecond();
H
heyanlong 已提交
145
static char *generate_sw3(zend_long span_id, char *peer_host, char *operation_name);
G
goerzh 已提交
146
static char *generate_sw6(zend_long span_id, char *peer_host, char *operation_name);
H
report  
heyanlong 已提交
147
static void generate_context();
H
heyanlong 已提交
148
static char *get_page_request_uri();
G
goerzh 已提交
149
static char *get_page_request_peer();
H
report  
heyanlong 已提交
150
static void write_log( char *text);
H
heyanlong 已提交
151
static void request_init();
G
goerzh 已提交
152 153
static void zval_b64_encode(zval *out, char *in);
static void zval_b64_decode(zval *out, char *in);
S
songzhian 已提交
154

H
heyanlong 已提交
155
void sky_curl_exec_handler(INTERNAL_FUNCTION_PARAMETERS);
H
heyanlong 已提交
156 157
void sky_curl_setopt_handler(INTERNAL_FUNCTION_PARAMETERS);
void sky_curl_setopt_array_handler(INTERNAL_FUNCTION_PARAMETERS);
H
heyanlong 已提交
158
void sky_curl_close_handler(INTERNAL_FUNCTION_PARAMETERS);
S
songzhian 已提交
159

H
report  
heyanlong 已提交
160
static void sky_flush_all();
H
heyanlong 已提交
161 162
static zval *get_first_span();
static zval *get_spans();
S
songzhian 已提交
163 164
static char* _get_current_machine_ip();
static void (*orig_curl_exec)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
H
heyanlong 已提交
165
static void (*orig_curl_setopt)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
H
heyanlong 已提交
166
static void (*orig_curl_setopt_array)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
H
heyanlong 已提交
167
static void (*orig_curl_close)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
168 169 170 171 172
/*
  	Declare any global variables you may need between the BEGIN
	and END macros here:
*/
ZEND_BEGIN_MODULE_GLOBALS(skywalking)
173
    char *sock_path;
H
report  
heyanlong 已提交
174 175 176 177
    char *app_code;
    zend_bool enable;
    zval UpstreamSegment;
    zval context;
H
heyanlong 已提交
178
    zval curl_header;
H
heyanlong 已提交
179
    zval curl_header_send;
H
heyanlong 已提交
180
    int  version;
181 182 183 184 185 186 187 188
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 已提交
189 190 191
#ifdef ZTS
#define SKYWALKING_G(v) TSRMG(skywalking_globals_id, zend_skywalking_globals *, v)
#else
192
#define SKYWALKING_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(skywalking, v)
H
heyanlong 已提交
193
#endif
194 195 196 197 198

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

S
songzhian 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

#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 已提交
225 226 227
#ifdef __APPLE__
#define SKY_OS_NAME "Darwin"
#else
S
songzhian 已提交
228 229
#define SKY_OS_NAME "Unknown"
#endif
H
report  
heyanlong 已提交
230
#endif
S
songzhian 已提交
231 232 233 234 235 236
 

#endif



237 238 239 240 241 242 243 244 245 246 247
#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
 */