aports/testing/php84-pecl-opentelemetry/fix-php84.patch
2024-09-08 15:29:52 +02:00

95 lines
2.9 KiB
Diff

Patch-Source: https://github.com/open-telemetry/opentelemetry-php-instrumentation/pull/153
diff --git a/ext/otel_observer.c b/ext/otel_observer.c
index b3138d1..080db36 100644
--- ext/otel_observer.c
+++ ext/otel_observer.c
@@ -152,6 +152,23 @@ static bool func_has_withspan_attribute(zend_execute_data *ex) {
return attr != NULL;
}
+/*
+ * OpenTelemetry attribute values may only be of limited types
+ */
+static bool is_valid_attribute_value(zval *val) {
+ switch (Z_TYPE_P(val)) {
+ case IS_STRING:
+ case IS_LONG: // Numeric (integer)
+ case IS_DOUBLE: // Numeric (floating point)
+ case IS_TRUE:
+ case IS_FALSE: // Boolean
+ case IS_ARRAY:
+ return true;
+ default:
+ return false;
+ }
+}
+
// get function args. any args with the
// SpanAttributes attribute are added to the attributes HashTable
static void func_get_args(zval *zv, HashTable *attributes,
@@ -198,7 +215,7 @@ static void func_get_args(zval *zv, HashTable *attributes,
zend_string *arg_name = ex->func->op_array.vars[i];
zend_attribute *attribute =
find_spanattribute_attribute(ex->func, i);
- if (attribute != NULL) {
+ if (attribute != NULL && is_valid_attribute_value(p)) {
if (attribute->argc) {
zend_string *key = Z_STR(attribute->args[0].value);
zend_hash_del(attributes, key);
@@ -1149,5 +1166,8 @@ void opentelemetry_observer_init(INIT_FUNC_ARGS) {
zend_observer_fcall_register(observer_fcall_init);
op_array_extension =
zend_get_op_array_extension_handle("opentelemetry");
+#if PHP_VERSION_ID >= 80400
+ zend_get_internal_function_extension_handle("opentelemetry");
+#endif
}
}
diff --git a/ext/tests/span_attribute/function_params_non_simple.phpt b/ext/tests/span_attribute/function_params_non_simple.phpt
index f637ab1..fc53f51 100644
--- ext/tests/span_attribute/function_params_non_simple.phpt
+++ ext/tests/span_attribute/function_params_non_simple.phpt
@@ -1,5 +1,5 @@
--TEST--
-Check if function non-simple types can be passed as function params
+Check if function non-simple types are ignored
--SKIPIF--
<?php if (PHP_VERSION_ID < 80100) die('skip requires PHP >= 8.1'); ?>
--EXTENSIONS--
@@ -28,28 +28,20 @@ function foo(
}
foo(
- ['foo' => 'bar'],
- new \stdClass(),
- function(){return 'fn';},
- null,
+ one: ['foo' => 'bar'],
+ two: new \stdClass(),
+ three: function(){return 'fn';},
+ four: null,
);
?>
--EXPECTF--
string(3) "pre"
-array(4) {
+array(1) {
["one"]=>
array(1) {
["foo"]=>
string(3) "bar"
}
- ["two"]=>
- object(stdClass)#1 (0) {
- }
- ["three"]=>
- object(Closure)#2 (0) {
- }
- ["four"]=>
- NULL
}
string(3) "foo"
string(4) "post"
\ No newline at end of file