This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
/
skywalking.c
275 lines (230 loc) · 9.66 KB
/
skywalking.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* Copyright 2021 SkyAPM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
+----------------------------------------------------------------------+
| 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 |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "SAPI.h"
#include "ext/standard/info.h"
#include "php_skywalking.h"
#include "src/sky_core_module.h"
#ifdef MYSQLI_USE_MYSQLND
#include "ext/mysqli/php_mysqli_structs.h"
#endif
ZEND_DECLARE_MODULE_GLOBALS(skywalking)
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("skywalking.enable", "0", PHP_INI_ALL, OnUpdateBool, enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.service", "hello_skywalking", PHP_INI_ALL, OnUpdateString, service, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.service_instance", "", PHP_INI_ALL, OnUpdateString, service_instance, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.oap_version", "9.0.0", PHP_INI_ALL, OnUpdateString, oap_version, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.oap_cross_process_protocol", "3.0", PHP_INI_ALL, OnUpdateString, oap_cross_process_protocol, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.oap_authentication", "", PHP_INI_ALL, OnUpdateString, oap_authentication, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_address", "127.0.0.1:11800", PHP_INI_ALL, OnUpdateString, grpc_address, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_BOOLEAN("skywalking.grpc_tls_enable", "0", PHP_INI_ALL, OnUpdateBool, grpc_tls_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_pem_root_certs", "", PHP_INI_ALL, OnUpdateString, grpc_tls_pem_root_certs, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_pem_private_key", "", PHP_INI_ALL, OnUpdateString, grpc_tls_pem_private_key, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.grpc_tls_pem_cert_chain", "", PHP_INI_ALL, OnUpdateString, grpc_tls_pem_cert_chain, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.log_level", "disable", PHP_INI_ALL, OnUpdateString, log_level, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.log_path", "/tmp/skywalking-php.log", PHP_INI_ALL, OnUpdateString, log_path, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_BOOLEAN("skywalking.curl_response_enable", "0", PHP_INI_ALL, OnUpdateBool, curl_response_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_BOOLEAN("skywalking.error_handler_enable", "0", PHP_INI_ALL, OnUpdateBool, error_handler_enable, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.mq_unique", "0", PHP_INI_ALL, OnUpdateBool, mq_unique, zend_skywalking_globals, skywalking_globals)
STD_PHP_INI_ENTRY("skywalking.sample_n_per_3_secs", "-1", PHP_INI_ALL, OnUpdateLong, sample_n_per_3_secs, zend_skywalking_globals, skywalking_globals)
PHP_INI_END()
static void php_skywalking_init_globals(zend_skywalking_globals *skywalking_globals) {
skywalking_globals->enable = 0;
skywalking_globals->service = NULL;
skywalking_globals->service_instance = NULL;
skywalking_globals->real_service_instance = "";
skywalking_globals->oap_version = "9.0.0";
skywalking_globals->oap_cross_process_protocol = "3.0";
skywalking_globals->oap_authentication = NULL;
// tls
skywalking_globals->grpc_address = NULL;
skywalking_globals->grpc_tls_enable = 0;
skywalking_globals->grpc_tls_pem_root_certs = NULL;
skywalking_globals->grpc_tls_pem_private_key = NULL;
skywalking_globals->grpc_tls_pem_cert_chain = NULL;
// log
skywalking_globals->log_level = "disable";
skywalking_globals->log_path = NULL;
skywalking_globals->curl_response_enable = 0;
// php error log
skywalking_globals->error_handler_enable = 0;
// rate limit
skywalking_globals->sample_n_per_3_secs = -1;
}
PHP_FUNCTION (skywalking_trace_id) {
// auto *segment = sky_get_segment(execute_data, -1);
// if (SKYWALKING_G(enable) && segment != NULL) {
// std::string trace_id = segment->getTraceId();
// RETURN_STRING(trace_id.c_str());
// } else {
RETURN_STRING("");
// }
}
/* {{{ proto void skywalking_log(string key, string log [, bool is_error]) */
PHP_FUNCTION(skywalking_log)
{
zend_string *name;
zend_string *key;
zend_string *value;
zend_bool is_error = 0;
ZEND_PARSE_PARAMETERS_START(3, 4)
Z_PARAM_STR(name)
Z_PARAM_STR(key)
Z_PARAM_STR(value)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(is_error)
ZEND_PARSE_PARAMETERS_END();
// auto *segment = sky_get_segment(execute_data, -1);
// if (!SKYWALKING_G(enable) || segment == NULL) {
// return;
// }
//
// if (ZSTR_LEN(name) > 0 && ZSTR_LEN(key) > 0 && ZSTR_LEN(value) > 0) {
// auto span = segment->findOrCreateSpan(name->val, SkyCoreSpanType::Local, SkyCoreSpanLayer::Unknown, 0);
// span->addLog(key->val, value->val);
// if (is_error) {
// span->setIsError(true);
// }
// span->setEndTIme();
// }
}
/* {{{ proto void skywalking_tag(string key, string value) */
PHP_FUNCTION(skywalking_tag)
{
zend_string *name;
zend_string *key;
zend_string *value;
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_STR(name)
Z_PARAM_STR(key)
Z_PARAM_STR(value)
ZEND_PARSE_PARAMETERS_END();
// auto *segment = sky_get_segment(execute_data, -1);
// if (!SKYWALKING_G(enable) || segment == nullptr) {
// return;
// }
//
// if (ZSTR_LEN(name) > 0 && ZSTR_LEN(key) > 0 && ZSTR_LEN(value) > 0) {
// auto span = segment->findOrCreateSpan(name->val, SkyCoreSpanType::Local, SkyCoreSpanLayer::Unknown, 0);
// span->addTag(key->val, value->val);
// span->setEndTIme();
// }
}
PHP_MINIT_FUNCTION (skywalking) {
ZEND_INIT_MODULE_GLOBALS(skywalking, php_skywalking_init_globals, NULL);
REGISTER_INI_ENTRIES();
if (SKYWALKING_G(enable)) {
sky_core_module_init(INIT_FUNC_ARGS_PASSTHRU);
}
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION (skywalking) {
UNREGISTER_INI_ENTRIES();
if (SKYWALKING_G(enable)) {
sky_core_module_free();
}
return SUCCESS;
}
PHP_RINIT_FUNCTION(skywalking)
{
#if defined(COMPILE_DL_SKYWALKING) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
if (SKYWALKING_G(enable)) {
sky_core_request_init(NULL, 0);
}
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION (skywalking) {
if (SKYWALKING_G(enable)) {
sky_core_request_free(NULL, 0);
}
return SUCCESS;
}
PHP_MINFO_FUNCTION(skywalking)
{
DISPLAY_INI_ENTRIES();
}
//PHP_GINIT_FUNCTION(skywalking)
//{
// memset(skywalking_globals, 0, sizeof(*skywalking_globals));
//}
zend_module_dep skywalking_deps[] = {
ZEND_MOD_REQUIRED("json")
ZEND_MOD_REQUIRED("pcre")
ZEND_MOD_REQUIRED("standard")
ZEND_MOD_REQUIRED("curl")
ZEND_MOD_END
};
ZEND_BEGIN_ARG_INFO_EX(arginfo_skywalking_trace_id, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_skywalking_log, 0, 0, 4)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, is_error)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_skywalking_tag, 0, 0, 3)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
const zend_function_entry skywalking_functions[] = {
PHP_FE (skywalking_trace_id, arginfo_skywalking_trace_id)
PHP_FE (skywalking_log, arginfo_skywalking_log)
PHP_FE (skywalking_tag, arginfo_skywalking_tag)
PHP_FE_END
};
zend_module_entry skywalking_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
skywalking_deps,
"skywalking",
skywalking_functions,
PHP_MINIT(skywalking),
PHP_MSHUTDOWN(skywalking),
PHP_RINIT(skywalking),
PHP_RSHUTDOWN(skywalking),
PHP_MINFO(skywalking),
PHP_SKYWALKING_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SKYWALKING
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(skywalking)
#endif