Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For WINDOWS build! #88

Merged
merged 15 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/config.w32
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// vim:ft=javascript

ARG_ENABLE('opentelemetry', 'opentelemetry support', 'no');

if (PHP_OPENTELEMETRY != 'no') {
AC_DEFINE('HAVE_OPENTELEMETRY', 1, 'opentelemetry support enabled');

EXTENSION('opentelemetry', 'opentelemetry.c' 'otel_observer.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
EXTENSION('opentelemetry', 'opentelemetry.c otel_observer.c', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
}
28 changes: 22 additions & 6 deletions ext/otel_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,26 @@ static void log_invalid_message(char *msg, zval *scope, zval *function) {
s = Z_STRVAL_P(scope);
}
char *f = Z_STRVAL_P(function);
char formatted[strlen(msg) + strlen(s) + strlen(f) + 1];
snprintf(formatted, sizeof(formatted), msg, s, f);

// Calculate the size of the formatted message.
int formatted_size = strlen(msg) + strlen(s) + strlen(f) + 1;

// Allocate a buffer for the formatted message.
char *formatted = malloc(formatted_size);
if (formatted == NULL) {
php_log_err("OpenTelemetry: Failed to allocate "
"memory for formatted message.");
return;
}

// Format the message.
snprintf(formatted, formatted_size, msg, s, f);

// Log the message.
php_log_err(formatted);

// Free the allocated memory.
free(formatted);
}

static void observer_begin(zend_execute_data *execute_data, zend_llist *hooks) {
Expand All @@ -218,8 +234,8 @@ static void observer_begin(zend_execute_data *execute_data, zend_llist *hooks) {

for (zend_llist_element *element = hooks->head; element;
element = element->next) {
zend_fcall_info fci = {};
zend_fcall_info_cache fcc = {};
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
zend_function *func = execute_data->func; // the observed function
if (UNEXPECTED(zend_fcall_info_init((zval *)element->data, 0, &fci,
&fcc, NULL, NULL) != SUCCESS)) {
Expand Down Expand Up @@ -337,8 +353,8 @@ static void observer_end(zend_execute_data *execute_data, zval *retval,

for (zend_llist_element *element = hooks->tail; element;
element = element->prev) {
zend_fcall_info fci = {};
zend_fcall_info_cache fcc = {};
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
if (UNEXPECTED(zend_fcall_info_init((zval *)element->data, 0, &fci,
&fcc, NULL, NULL) != SUCCESS)) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions ext/tests/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ array(6) {
[3]=>
string(10) "helloWorld"
[4]=>
string(%d) "%s/tests/005.php"
string(%d) "%s%etests%e005.php"
[5]=>
int(4)
}
Expand All @@ -44,7 +44,7 @@ array(8) {
[5]=>
string(10) "helloWorld"
[6]=>
string(%d) "%s/tests/005.php"
string(%d) "%s%etests%e005.php"
[7]=>
int(4)
}
4 changes: 2 additions & 2 deletions ext/tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ array(6) {
[3]=>
string(10) "helloWorld"
[4]=>
string(%d) "%s/tests/006.php"
string(%d) "%s%etests%e006.php"
[5]=>
int(4)
}
Expand All @@ -47,7 +47,7 @@ array(8) {
[5]=>
string(10) "helloWorld"
[6]=>
string(%d) "%s/tests/006.php"
string(%d) "%s%etests%e006.php"
[7]=>
int(4)
}
4 changes: 3 additions & 1 deletion ext/tests/invalid_post_callback_signature.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The invalid callback signature should not cause a fatal, so it is checked before
is invalid, the callback will not be called.
--EXTENSIONS--
opentelemetry
--XFAIL--
Providing a post invalid callback signature causes segfault. The behaviour is currently disabled, so instead of a segfault a message is logged to error_log.
--FILE--
<?php
OpenTelemetry\Instrumentation\hook(
Expand All @@ -31,4 +33,4 @@ TestClass::test();
--EXPECTF--
string(3) "pre"
string(4) "test"
OpenTelemetry: post hook invalid signature, class=TestClass function=test
OpenTelemetry: post hook invalid signature, class=TestClass function=test
4 changes: 3 additions & 1 deletion ext/tests/invalid_pre_callback_signature.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The invalid callback signature should not cause a fatal, so it is checked before
is invalid, the callback will not be called and a message will be written to error_log.
--EXTENSIONS--
opentelemetry
--XFAIL--
Providing a pre invalid callback signature causes segfault. The behaviour is currently disabled, so instead of a segfault a message is logged to error_log.
--FILE--
<?php
OpenTelemetry\Instrumentation\hook(
Expand All @@ -31,4 +33,4 @@ TestClass::test();
--EXPECTF--
OpenTelemetry: pre hook invalid signature, class=TestClass function=test
string(4) "test"
string(4) "post"
string(4) "post"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ is invalid, the callback will not be called and a message will be written to err
null class.
--EXTENSIONS--
opentelemetry
--XFAIL--
Providing a invalid pre callback signature for function without class causes segfault. The behaviour is currently disabled, so instead of a segfault a message is logged to error_log.
--FILE--
<?php
OpenTelemetry\Instrumentation\hook(
Expand All @@ -30,4 +32,4 @@ hello();
--EXPECTF--
OpenTelemetry: pre hook invalid signature, class=null function=hello
string(5) "hello"
string(4) "post"
string(4) "post"