Skip to content

Commit 219af9b

Browse files
committed
fix 32bit tests
- remove the ability to pass complex items as attributes (since the spec already disallows them, they'd get dropped later anyway) - update alpine dockerfile to also support 32bit builds, which enables local testing against a 32bit platform
1 parent e883528 commit 219af9b

4 files changed

Lines changed: 46 additions & 23 deletions

File tree

docker-compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@ services:
1919
- ./ext:/usr/src/myapp
2020
environment:
2121
TEST_PHP_ARGS: "-q"
22+
32bit:
23+
build:
24+
context: docker
25+
dockerfile: Dockerfile.alpine
26+
args:
27+
ALPINE_VERSION: i386/alpine
28+
PHP_VERSION: ${PHP_VERSION:-8.4.0beta4}
29+
volumes:
30+
- ./ext:/usr/src/myapp
31+
environment:
32+
TEST_PHP_ARGS: "-q"

docker/Dockerfile.alpine

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM alpine:3.16 as builder
1+
ARG ALPINE_VERSION=alpine:3.16
2+
FROM ${ALPINE_VERSION} as builder
23
WORKDIR /usr/src
34

45
ENV PHPIZE_DEPS \
@@ -22,23 +23,25 @@ RUN apk add --no-cache \
2223
xz
2324

2425
RUN apk add --no-cache \
26+
bison \
2527
coreutils \
2628
curl-dev \
2729
libxml2-dev \
2830
linux-headers \
31+
re2c \
2932
readline-dev \
3033
sqlite-dev
3134

3235
ARG PHP_VERSION
33-
ENV PHP_URL="https://www.php.net/distributions/php-${PHP_VERSION}.tar.xz"
34-
35-
RUN echo "$PHP_URL" && curl -fsSL -o php.tar.xz "$PHP_URL"
36-
RUN cd /usr/src \
37-
&& tar -xf php.tar.xz
36+
ENV PHP_URL="https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz"
3837

3938
ARG PHP_CONFIG_OPTS="--enable-debug --with-pear --with-zlib"
40-
RUN cd php-${PHP_VERSION} \
41-
&& ./buildconf \
39+
RUN echo "$PHP_URL" && curl -fsSL -o php.tar.gz "$PHP_URL" \
40+
&& cd /usr/src \
41+
&& mkdir php-src \
42+
&& tar -xzf php.tar.gz -C php-src --strip-components=1 \
43+
&& cd php-src \
44+
&& ./buildconf --force \
4245
&& ./configure ${PHP_CONFIG_OPTS} \
4346
&& make -j $(nproc) \
4447
&& make install

ext/otel_observer.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ static bool func_has_withspan_attribute(zend_execute_data *ex) {
152152
return attr != NULL;
153153
}
154154

155+
/*
156+
* OpenTelemetry attribute values may only be of limited types
157+
*/
158+
static bool is_valid_attribute_value(zval *val) {
159+
switch (Z_TYPE_P(val)) {
160+
case IS_STRING:
161+
case IS_LONG: // Numeric (integer)
162+
case IS_DOUBLE: // Numeric (floating point)
163+
case IS_TRUE:
164+
case IS_FALSE: // Boolean
165+
case IS_ARRAY:
166+
return true;
167+
default:
168+
return false;
169+
}
170+
}
171+
155172
// get function args. any args with the
156173
// SpanAttributes attribute are added to the attributes HashTable
157174
static void func_get_args(zval *zv, HashTable *attributes,
@@ -198,7 +215,7 @@ static void func_get_args(zval *zv, HashTable *attributes,
198215
zend_string *arg_name = ex->func->op_array.vars[i];
199216
zend_attribute *attribute =
200217
find_spanattribute_attribute(ex->func, i);
201-
if (attribute != NULL) {
218+
if (attribute != NULL && is_valid_attribute_value(p)) {
202219
if (attribute->argc) {
203220
zend_string *key = Z_STR(attribute->args[0].value);
204221
zend_hash_del(attributes, key);

ext/tests/span_attribute/function_params_non_simple.phpt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Check if function non-simple types can be passed as function params
2+
Check if function non-simple types are ignored
33
--SKIPIF--
44
<?php if (PHP_VERSION_ID < 80100) die('skip requires PHP >= 8.1'); ?>
55
--EXTENSIONS--
@@ -28,28 +28,20 @@ function foo(
2828
}
2929

3030
foo(
31-
['foo' => 'bar'],
32-
new \stdClass(),
33-
function(){return 'fn';},
34-
null,
31+
one: ['foo' => 'bar'],
32+
two: new \stdClass(),
33+
three: function(){return 'fn';},
34+
four: null,
3535
);
3636
?>
3737
--EXPECTF--
3838
string(3) "pre"
39-
array(4) {
39+
array(1) {
4040
["one"]=>
4141
array(1) {
4242
["foo"]=>
4343
string(3) "bar"
4444
}
45-
["two"]=>
46-
object(stdClass)#1 (0) {
47-
}
48-
["three"]=>
49-
object(Closure)#2 (%d) {%A
50-
}
51-
["four"]=>
52-
NULL
5345
}
5446
string(3) "foo"
5547
string(4) "post"

0 commit comments

Comments
 (0)