dd-trace-php
dd-trace-php copied to clipboard
[Feature] add a .apk for arm64 to the release section
Is your feature request related to a problem? Please describe.
We are using dd-trace-php with AWS ECS starting a1 type instances (arm64).
Our php app is a dockerized FROM php:7.1-fpm-alpine
No .apk is available for arm64 architecture.
Describe the solution you'd like
We'd like to install the extension using an .apk as indicated by the documentation using: apk add datadog-php-tracer.apk --allow-untrusted
For exemple we expect to have the file datadog-php-tracer_0.54.0_arm64.apk
as an additional asset is the github release section for version 0.54.0
Thank you @philippefuentes. I understand that this is important to you and I hope that we will be able to support arm64 architecture out of the box soon.
Currently we have a few limitations, though:
- CircleCI does not support arm builds at the moment, if not via self-hosted runners.
- Even if we build via self-hosted runners, then the entire testing pipeline should be reproduced there, as we cannot just build a binary without testing it.
Note that I am not an expert into building for different architectures and I might use some suggestions here.
In the meantime, how was the building experience for you? Any take away that you can share and that we can use to either improve our docs or build scripts.
Last but not least, CircleCI will let us know when ARM architectures will be available (https://www2.circleci.com/arm.html), maybe a good idea to sign up in order to show some interest 😄 .
Thank you for your quick answer @labbati , I have to confess that my level of expertise on this subject is quite low :)
However, I can share this with you: To make it work on arm64, I first tried to follow the documentation to compile and install the extension from source:
https://docs.datadoghq.com/tracing/faq/php-tracer-manual-installation/#install-from-source
and add a .ini to use the compiled extension and update the ddtrace.request_init_hook
as indicated in the same doc page:
ddtrace.request_init_hook=<PATH_TO_SOURCES>/bridge/dd_wrap_autoloader.php
But it didn't work this way, the app crashed at early stage running the request_init_hook
I managed to make it work by "overriding" the .so extension file of the .apk installation procedure, by the compiled .so, to keep the configuration from the .apk installation and only changing the .so.
So I installed the .apk as I would for amd64, then compiled the extension as indicated above, then replaced the .so by the one freshly compiled, here is an extract of the dockerfile used to build the image on an arm64 instance:
FROM php:7.1-fpm-alpine
...
# .apk installation
ARG DDTRACE_VERSION=0.54.0
RUN cd $(mktemp -d) \
&& curl -Lo datadog-php-tracer.apk https://github.com/DataDog/dd-trace-php/releases/download/${DDTRACE_VERSION}/datadog-php-tracer_${DDTRACE_VERSION}_noarch.apk \
&& apk add datadog-php-tracer.apk --allow-untrusted \
&& rm datadog-php-tracer.apk
# installation from source
RUN apk add --update curl-dev && \
cd / && \
wget https://github.com/DataDog/dd-trace-php/archive/${DDTRACE_VERSION}.tar.gz ; tar -zxvf ${DDTRACE_VERSION}.tar.gz && \
cd dd-trace-php-${DDTRACE_VERSION} && \
phpize && \
./configure --enable-ddtrace && \
make && \
make install
# change the tracer configuration to use the compiled extension
ARG PHP_DIR=/usr/local/etc/php/conf.d
RUN sed -i 's/extension=.*/extension=ddtrace.so/' ${PHP_DIR}/98-ddtrace.ini
...
PS: just signed up to receive notifications about arm on CircleCI :)
Bump!
Hi there,
Circle is now supported ARM. Is there any update for this?
Hey @nthienan, at the moment we haven't finalized our plans for our next quarter yet. We will post here as soon as we know.
Worth revisiting this https://circleci.com/blog/managing-ci-cd-pipelines-with-arm-compute-resource-classes/
Any update on this please?
Hello. Support for arm64 hasn't been prioritized for Q1. Installation instructions from @philippefuentes can be used in the meantime. Let me also drop here a link to the complete step-by-step instructions to build the arm64 images on different systems
@labbati As this might be ok for PHP 7.4. Running make generate
as proposed in the instructions will fail on PHP 8.0. From looking at the Makefile this is to be expected. Is there any way how we could build multi-arch PHP containers for PHP 8?
@YorickH currently you'll need to copy the generated files from the bridge
folder manually.
We will check out using a solution independent of classpreloader in future.
Here's my working example of building the dd-trace extension from source on PHP 7.4-cli image using Docker stages on Mac with M1:
# syntax=docker/dockerfile:1.3
FROM php:7.4-cli as base
ARG DEBIAN_FRONTEND=noninteractive
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
unzip \
libzip-dev \
&& rm -r /var/lib/apt/lists/*
## PHP
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
RUN docker-php-ext-install sockets pdo_mysql zip
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
FROM base AS datadog
ENV DD_TRACE_VERSION=0.65.1
## Datadog build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libcurl4-openssl-dev \
&& rm -r /var/lib/apt/lists/*
WORKDIR /tmp
RUN git clone --single-branch --branch=${DD_TRACE_VERSION} --depth 1 https://github.com/DataDog/dd-trace-php.git
WORKDIR /tmp/dd-trace-php
RUN make all CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra" ECHO_ARG="-e"
RUN make generate
RUN echo "extension=ddtrace.so" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
RUN echo "datadog.trace.request_init_hook=/opt/datadog/dd-trace-php/bridge/dd_wrap_autoloader.php" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
FROM base AS production
ENV DD_TRACE_DEBUG=false
ENV DD_TRACE_CLI_ENABLED=true
ENV DD_TRACE_GENERATE_ROOT_SPAN=false
ENV DD_TRACE_AUTO_FLUSH_ENABLED=true
ENV DD_TRACE_SYMFONY_ENABLED=false
ENV APP_ENV=prod
## Datadog install
RUN mkdir -p /opt/datadog/dd-trace-php
COPY --from=datadog /tmp/dd-trace-php/bridge /opt/datadog/dd-trace-php/bridge
COPY --from=datadog /tmp/dd-trace-php/tmp/build_extension/modules/ddtrace.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902
COPY --from=datadog /usr/local/etc/php/conf.d/98-ddtrace.ini /usr/local/etc/php/conf.d/98-ddtrace.ini
## Run your app here
@YorickH currently you'll need to copy the generated files from the
bridge
folder manually.We will check out using a solution independent of classpreloader in future.
Hey @bwoebi, I'm aware that we should copy the bridge
folder manually, this is mentioned in the comment on the other arm issue that's open.
And that's not the issue we are having, it's the RUN make all CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra" ECHO_ARG="-e"
step that's failing. Besides some warning I get these errors:
#19 11.24 /tmp/dd-trace-php/tmp/build_extension/ext/php8/request_hooks.c:146:11: error: too many arguments to function 'php_stream_open_for_zend_ex'
#19 11.24 146 | ret = php_stream_open_for_zend_ex(filename, &file_handle, USE_PATH | STREAM_OPEN_FOR_INCLUDE);
#19 11.25 /tmp/dd-trace-php/tmp/build_extension/ext/php8/request_hooks.c:258:5: error: too many arguments to function 'php_stat'
#19 11.25 258 | php_stat(DDTRACE_G(request_init_hook), strlen(DDTRACE_G(request_init_hook)), FS_EXISTS, &exists_flag TSRMLS_CC);
Hey, I am confused how you are getting to this error? https://github.com/DataDog/dd-trace-php/blob/master/ext/php8/request_hooks.c has no such lines of code. (like that file is only 170 lines big, you are reporting errors from a line 258)
Are you building a very old version of ddtrace on top of a PHP version which was not yet supported by that version?
@bwoebi wow you are right, was using an older version. My bad! Anyhow, still failing but now on the classpreloader generation:
#41 1.589 > classpreloader.php compile --config=../../bridge/_files_api.php --output=../../bridge/_generated_api.php
#41 1.611 > Loading configuration file
#41 1.613 - Found 11 files
#41 1.613 > Compiling classes
#41 1.614 - Writing /tmp/dd-trace-php/bridge/../src/api/Type.php
#41 1.615
#41 1.615 - Writing /tmp/dd-trace-php/bridge/../src/api/Tag.php
#41 1.615
#41 1.615 Warning: Undefined array key 314 in /tmp/dd-trace-php/tooling/generation/vendor/nikic/php-parser/lib/PhpParser/Lexer.php on line 195
#41 1.615
#41 1.615 Warning: Undefined array key "" in /tmp/dd-trace-php/tooling/generation/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 173
#41 1.615
#41 1.615 Warning: Undefined array key "" in /tmp/dd-trace-php/tooling/generation/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php on line 335
#41 1.620
#41 1.620 [PhpParser\Error]
#41 1.620 Syntax error, unexpected , expecting T_STRING or T_NS_SEPARATOR or '{' on line 3
#41 1.620
#41 1.620
#41 1.620 compile [--config CONFIG] [--output OUTPUT] [--skip_dir_file] [--fix_dir FIX_DIR] [--fix_file FIX_FILE] [--strip_comments STRIP_COMMENTS]
#41 1.620
#41 1.623 Script classpreloader.php compile --config=../../bridge/_files_api.php --output=../../bridge/_generated_api.php handling the generate event returned with error code 1
This is with 0.70.1 on both 8.0 and 8.1. This also happens on amd64 and not only arm.
My steps I use to install:
ENV DD_TRACE_VERSION 0.70.0
## Datadog build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libcurl4-openssl-dev \
&& rm -r /var/lib/apt/lists/*
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/bin/composer
# clone dd-tr ace-php repo (https://github.com/DataDog/dd-trace-php)
WORKDIR /tmp
RUN git clone --single-branch --branch=${DD_TRACE_VERSION} --depth 1 https://github.com/DataDog/dd-trace-php.git
WORKDIR /tmp/dd-trace-php
# build
RUN make all CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra" ECHO_ARG="-e"
RUN make generate
# install
# 1) copy the bridge folder to some location
RUN mkdir -p /opt/datadog/dd-trace-php && \
cp -r bridge/ /opt/datadog/dd-trace-php/
# 2) copy ./tmp/build_extension/modules/ddtrace.so to your extension directory.
# You can find your extension directory running:
# - for `php` --> `php -i | grep -i extension_dir`
# - for `php-fpm` --> `php-fpm7.4 -i | grep -i extension_dir`
# in this specific example it results to be /usr/lib/php/20190902
RUN cp ./tmp/build_extension/modules/ddtrace.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902
# 3) add the following lines to 98-ddtrace.ini in your ini settings directory.
# You can find your ini settings directory running:
# - for `php` --> `php -i | grep -i 'Scan this dir for additional .ini files'`
# - for `php-fpm` --> `php-fpm7.4 -i | grep -i 'Scan this dir for additional .ini files'`
# in this specific example it results to be /etc/php/7.4/cli/conf.d and /etc/php/7.4/fpm/conf.d respectively
RUN echo "extension=ddtrace.so" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
RUN echo "ddtrace.request_init_hook=/opt/datadog/dd-trace-php/bridge/dd_wrap_autoloader.php" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
make generate
is this class preloader operation. Which you need to run on PHP 7 currently, because it does not work with PHP 8 right now. And then, copy the result (the bridge folder from that build) to this new build.
It's not great, we are aware of that issue and will look at fixing it in future.
@bwoebi Aha, ok so running the build and compile inside a stage with 7.4 should do the trick? Or only the make generate
command?
You can download the released .tar.gz bundle from https://github.com/DataDog/dd-trace-php/releases for the specific version and copy all the bridge/_generated*.php
.
@labbati But that would not work for arm64
, will try with a dedicated 7.4 stage
php files are independent from the architecture. You can use them. This is actually what we are going to do soon with support for arm64.
Just to clarify, you need to build the extension on arm64. The companion PHP files in the directory I mentioned can be copied from any bundle of that same dd-trace-php version even if for a different architecture.
@labbati @bwoebi Feel like bothering you guys but here goes, but happy to help getting this out the door asap and if that means being live testing, that's fine. Got it working for building, I put the whole generation into a stage with php 7.4:
FROM php:7.4 AS datadog
ENV DD_TRACE_VERSION 0.70.1
## Datadog build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
libcurl4-openssl-dev \
&& rm -r /var/lib/apt/lists/*
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/bin/composer
# clone dd-tr ace-php repo (https://github.com/DataDog/dd-trace-php)
WORKDIR /tmp
RUN git clone --single-branch --branch=${DD_TRACE_VERSION} --depth 1 https://github.com/DataDog/dd-trace-php.git
WORKDIR /tmp/dd-trace-php
# build
RUN make all CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra" ECHO_ARG="-e"
RUN make generate
# install
# add the following lines to 98-ddtrace.ini in your ini settings directory.
# You can find your ini settings directory running:
# - for `php` --> `php -i | grep -i 'Scan this dir for additional .ini files'`
# - for `php-fpm` --> `php-fpm7.4 -i | grep -i 'Scan this dir for additional .ini files'`
# in this specific example it results to be /etc/php/7.4/cli/conf.d and /etc/php/7.4/fpm/conf.d respectively
RUN echo "extension=ddtrace.so" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
RUN echo "ddtrace.request_init_hook=/opt/datadog/dd-trace-php/bridge/dd_wrap_autoloader.php" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
And afterward I copy the bridge, the .so
file and the ini file over to the final stage:
## Datadog install
RUN mkdir -p /opt/datadog/dd-trace-php
COPY --from=datadog /tmp/dd-trace-php/bridge /opt/datadog/dd-trace-php/bridge
COPY --from=datadog /tmp/dd-trace-php/tmp/build_extension/modules/ddtrace.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930
COPY --from=datadog /usr/local/etc/php/conf.d/98-ddtrace.ini /usr/local/etc/php/conf.d/98-ddtrace.ini
This does work as intended but it complains at startup:
PHP Warning: PHP Startup: ddtrace: Unable to initialize module
Module compiled with module API=20190902
PHP compiled with module API=20200930
These options need to match
in Unknown on line 0
Kinda to be expected though as I compiled it with 7.4. So stuck again, got so close!
@YorickH try this
###########################################################################
# If you want to generate, generate them on PHP 7.4...
###########################################################################
FROM php:7.4 AS datadog
ENV DD_TRACE_VERSION 0.70.1
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
libcurl4-openssl-dev \
&& rm -r /var/lib/apt/lists/*
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/bin/composer
# clone dd-tr ace-php repo (https://github.com/DataDog/dd-trace-php)
WORKDIR /tmp
RUN git clone --single-branch --branch=${DD_TRACE_VERSION} --depth 1 https://github.com/DataDog/dd-trace-php.git
WORKDIR /tmp/dd-trace-php
RUN make generate
###########################################################################
# ... then use your PHP 8
###########################################################################
FROM php:8.0
## Datadog build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
libcurl4-openssl-dev \
&& rm -r /var/lib/apt/lists/*
# clone dd-tr ace-php repo (https://github.com/DataDog/dd-trace-php)
WORKDIR /tmp
COPY --from=datadog /tmp/dd-trace-php /tmp/dd-trace-php
WORKDIR /tmp/dd-trace-php
# build
RUN make all CFLAGS="-std=gnu11 -O2 -g -Wall -Wextra" ECHO_ARG="-e"
RUN cp /tmp/dd-trace-php/tmp/build_extension/modules/ddtrace.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
# install
# add the following lines to 98-ddtrace.ini in your ini settings directory.
# You can find your ini settings directory running:
# - for `php` --> `php -i | grep -i 'Scan this dir for additional .ini files'`
# - for `php-fpm` --> `php-fpm7.4 -i | grep -i 'Scan this dir for additional .ini files'`
# in this specific example it results to be /etc/php/7.4/cli/conf.d and /etc/php/7.4/fpm/conf.d respectively
RUN echo "extension=ddtrace.so" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
RUN echo "ddtrace.request_init_hook=/opt/datadog/dd-trace-php/bridge/dd_wrap_autoloader.php" >> /usr/local/etc/php/conf.d/98-ddtrace.ini
COPY --from=datadog /tmp/dd-trace-php/bridge /opt/datadog/dd-trace-php/bridge
Hi @labbati,
I tried your solution in order to be able to trace my php application running on Fargate arm but I'm getting the following error :
Datadog tracing support => disabled
Version => 0.73.0
DATADOG TRACER CONFIGURATION => {"date":"2022-05-02T22:35:52Z","os_name":"Linux ip-x-x-x-x.eu-west-3.compute.internal 4.14.268-205.500.amzn2.aarch64 #1 SMP Wed Mar 2 18:38:29 UTC 2022 aarch64","os_version":"4.14.268-205.500.amzn2.aarch64","version":"0.73.0","lang":"php","lang_version":"8.0.18","env":null,"enabled":true,"service":"admin","enabled_cli":false,"agent_url":"http:\/\/localhost:8126","debug":false,"analytics_enabled":false,"sample_rate":1,"sampling_rules":[],"tags":[],"service_mapping":[],"distributed_tracing_enabled":true,"priority_sampling_enabled":true,"dd_version":null,"architecture":"aarch64","sapi":"cli","datadog.trace.request_init_hook":"\/opt\/datadog\/dd-library\/0.73.0\/dd-trace-sources\/bridge\/dd_wrap_autoloader.php","open_basedir_configured":false,"uri_fragment_regex":null,"uri_mapping_incoming":null,"uri_mapping_outgoing":null,"auto_flush_enabled":false,"generate_root_span":true,"http_client_split_by_domain":false,"measure_compile_time":true,"report_hostname_on_root_span":false,"traced_internal_functions":null,"auto_prepend_file_configured":false,"integrations_disabled":"default","enabled_from_env":false,"opcache.file_cache":null,"agent_error":"Failed to connect to localhost port 8126: Connection refused"}
Any idea what I'm missing ?
N.B : It was working fine before I switch the ecs task runtime_platform to arm64, so I think my datadog-agent config should be fine (datadog-agent does support the arm platform right ?)
Thanks in advance, Julien
Hey @pesseyjulien,
there should be nothing missing on the tracer side. It just means that there's no agent listening on the local 8126 port. Depending on your setup there might be missing port-forwardings, or it being the wrong host-port pair or simply the agent not running.
My bad, it works :) I forgot I disabled the apm on one for my container :/ Sorry and thanks @labbati or the temporary solution !
Arm64 releases are now available with 0.78.0.