|
| 1 | +# Local development for OpenTelemetry PHP Distro Local development |
| 2 | +## Build and package |
| 3 | + |
| 4 | +The best method for building is to use a set of Bash scripts that we utilize in production workflows for building releases. |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +All scripts are located in the `tools/build` folder, but they should be called from the root folder of the repository. To ensure everything works correctly on your system, you need to have Docker installed. |
| 9 | +Each of the scripts mentioned below has a help page; to display it, simply provide the `--help` argument. |
| 10 | + |
| 11 | +### Building the native library like on CI |
| 12 | + |
| 13 | +```bash |
| 14 | +cd opentelemetry-php-distro |
| 15 | +./tools/build/build_native.sh --build_architecture linux-x86-64 --interactive --ncpu 2 |
| 16 | +``` |
| 17 | + |
| 18 | +This script will configure the project and build the libraries for the linux-x86-64 architecture. Adding the interactive argument allows you to interrupt the build using the `Ctrl + C` combination, and with the ncpu option, you can build in parallel using the specified number of processor threads. |
| 19 | +If you are not adding new files to the project and just want to rebuild your changes, |
| 20 | +you can provide the `--skip_configure` argument - this will save time on reconfiguring the project. |
| 21 | +You can also save a lot of time by creating a local cache for Conan packages; |
| 22 | +the files will then be stored outside the container and reused repeatedly. |
| 23 | +To do this, provide a path to the `--conan_cache_path` argument, e.g., `~/.conan_cache`. |
| 24 | +The script will automatically execute native unit tests just after the build. |
| 25 | +If you would like to skip native unit tests you can use `--skip_unit_tests` command line option. |
| 26 | + |
| 27 | +Currently, we support the following architectures: |
| 28 | + |
| 29 | +```bash |
| 30 | +linux-x86-64 |
| 31 | +linuxmusl-x86-64 |
| 32 | +linux-arm64 |
| 33 | +linuxmusl-arm64 |
| 34 | +``` |
| 35 | + |
| 36 | +If you want to enable debug logging in tested classes, you need to export environment variable `OTEL_PHP_DEBUG_LOG_TESTS=1` before run. |
| 37 | + |
| 38 | +### Building the native library for other platforms |
| 39 | + |
| 40 | +You can always try to compile the native part for an unsupported architecture or platform. To facilitate this, we have made it possible to remove hard dependencies on Docker images, the compiler, and build profiles. |
| 41 | + |
| 42 | +To make everything work on your system, you will need the gcc compiler (at the time of writing, version 15.2.0+), cmake (v4.2.1+), and python 3.14+. |
| 43 | + |
| 44 | +Since our system uses Conan as the repository for required dependencies, you need to install them first. The following script will install everything necessary in the `~/.conan2` folder. If you haven't used Conan before, provide the argument `--detect_conan_profile` to create a default profile – if you have used Conan before, you can skip this. If you are not using python-venv and have Conan installed directly on your system, you can pass the argument `--skip_venv_conan`, which will cause the script to skip creating a venv and installing Conan. |
| 45 | + |
| 46 | +```bash |
| 47 | +./prod/native/building/install_dependencies.sh --build_output_path ./prod/native/_build/custom-release --build_type Release --detect_conan_profile |
| 48 | +``` |
| 49 | + |
| 50 | +The script will install dependencies and generate the files necessary to configure the project in the next step (prod/native/_build/custom-release): |
| 51 | + |
| 52 | +```bash |
| 53 | +cmake -S ./prod/native/ -B ./prod/native/_build/custom-release/ -DCMAKE_PREFIX_PATH=./prod/native/_build/custom-release/build/Release/generators/ -DSKIP_CONAN_INSTALL=1 -DCMAKE_BUILD_TYPE=Release |
| 54 | +``` |
| 55 | + |
| 56 | +Building: |
| 57 | +```bash |
| 58 | +cmake --build ./prod/native/_build/custom-release/ |
| 59 | +``` |
| 60 | + |
| 61 | +If the build is successful, you can find the built libraries using the following command: |
| 62 | +```bash |
| 63 | +find prod/native/_build/custom-release -name opentelemetry*.so |
| 64 | +``` |
| 65 | + |
| 66 | +As a result you should see: |
| 67 | +```bash |
| 68 | +prod/native/_build/custom-release/loader/code/opentelemetry_php_distro_loader.so |
| 69 | +prod/native/_build/custom-release/extension/code/opentelemetry_php_distro_84.so |
| 70 | +prod/native/_build/custom-release/extension/code/opentelemetry_php_distro_83.so |
| 71 | +prod/native/_build/custom-release/extension/code/opentelemetry_php_distro_82.so |
| 72 | +prod/native/_build/custom-release/extension/code/opentelemetry_php_distro_81.so |
| 73 | +``` |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +### Testing the native library |
| 78 | + |
| 79 | +The following script will run the phpt tests for the native library, which should be built in the previous step - make sure to use the same architecture. You can run tests for multiple PHP versions simultaneously by providing several versions separated by a space to the `--php_versions` parameter. |
| 80 | + |
| 81 | +```bash |
| 82 | +cd opentelemetry-php-distro |
| 83 | + ./tools/build/test_phpt.sh --build_architecture linux-x86-64 --php_versions '81 82 83 84' |
| 84 | +``` |
| 85 | + |
| 86 | +### Building PHP dependencies |
| 87 | + |
| 88 | +To ensure the instrumentation is fully successful, it is required to download and install dependencies for the PHP implementation. You can do this automatically using a script that will download and install them separately for each specified PHP version. Similar to the previous step, you need to provide the PHP versions separated by spaces as a parameter to the `--php_versions` argument. |
| 89 | + |
| 90 | +```bash |
| 91 | +cd opentelemetry-php-distro |
| 92 | + ./tools/build/build_php_deps.sh --php_versions '81 82 83 84' |
| 93 | +``` |
| 94 | + |
| 95 | +### Building Packages |
| 96 | + |
| 97 | +We currently support building packages for Debian-based systems (deb), Red Hat-based systems (rpm), and Alpine Package Keeper (apk) for each supported CPU architecture. |
| 98 | + |
| 99 | +To build a package, use the `./tools/build/build_packages.sh` script with the following arguments: |
| 100 | +``` |
| 101 | + --package_version Required. Version of the package. |
| 102 | + --build_architecture Required. Architecture of the native build. (eg. linux-x86-64) |
| 103 | + --package_goarchitecture Required. Architecture of the package in Golang convention. (eg. amd64) |
| 104 | + --package_sha Optional. SHA of the package. Default is fetch from git commit hash or unknown if got doesn't exists. |
| 105 | + --package_types Required. List of package types separated by spaces (e.g., 'deb rpm'). |
| 106 | +``` |
| 107 | + |
| 108 | +For the `--package_goarchitecture` parameter, we currently distinguish between two architectures: amd64 and arm64. These should correspond to the value of the `--build_architecture` argument. |
| 109 | + |
| 110 | +Remember, it's best if the package version reflects the version recorded in the `project.properties` file. |
| 111 | + |
| 112 | +```bash |
| 113 | +cd opentelemetry-php-distro |
| 114 | +./tools/build/build_packages.sh --package_version v1.0.0-dev --build_architecture linux-x86-64 --package_goarchitecture amd64 --package_types 'deb rpm' |
| 115 | +``` |
| 116 | + |
| 117 | +# Updating docker images used for building and testing |
| 118 | +## Building and updating docker images used to build the agent extension |
| 119 | + |
| 120 | +For detailed information about Docker images architecture, versioning, and build instructions, please refer to [prod/native/building/dockerized/README.md](prod/native/building/dockerized/README.md). |
| 121 | + |
| 122 | +All image versions are parameterized in [docker-compose.yml](prod/native/building/dockerized/docker-compose.yml). During CI builds, image versions are automatically read from this file - if an image doesn't exist in DockerHub, it will be automatically built. |
| 123 | + |
| 124 | +Be aware that if you want to build images for ARM64 you must run it on ARM64 hardware or inside emulator. The same applies to x86-64. |
| 125 | + |
| 126 | +To test freshly built images, you need to udate image version in ```./tools/build/build_native.sh``` script and run build task described in [Build/package](#build-and-package) |
| 127 | + |
| 128 | +## Adding or removing support for PHP release |
| 129 | + |
| 130 | +- Add the new version to the `supported_php_versions` list in the [project.properties](project.properties) file. |
| 131 | +- Update supported PHP version detection in function `is_php_supported` in [post-install.sh](packaging/scripts/post-install.sh) |
| 132 | +- Add or modify the supported versions array in the loader's [phpdetection.cpp](prod/native/loader/code/phpdetection.cpp) file. |
| 133 | +- Add or remove metadata for the specified PHP version in [conandata.yml](prod/native/building/dependencies/php-headers/conandata.yml). |
| 134 | +- Add or remove the Conan dependency for php-headers-* in [conanfile.txt](prod/native/conanfile.txt). |
| 135 | +- Follow the steps in the ["Building the native library like on CI"](#building-the-native-library-like-on-ci) section to configure and build the agent. |
| 136 | +- To speed up CI builds, upload Conan artifacts to Artifactory if support for the new PHP release has been added (see [Building and publishing conan artifacts](#building-and-publishing-conan-artifacts)) |
| 137 | + |
| 138 | +# Managing PHP 3rd party dependencies |
| 139 | +This documentation section describes how to manage PHP 3rd party dependencies |
| 140 | +i.e., `vendor` directory, `composer.json` and `composer.lock` |
| 141 | + |
| 142 | +We would like to have reproducible builds, so we need to ensure that the same |
| 143 | +versions of dependencies are used for each build of the source code repository snapshot. |
| 144 | +To achieve this, we committed `composer.lock` files to version control. |
| 145 | +There are multiple `composer.lock` files - one for each supported major.minor PHP version. |
| 146 | + |
| 147 | +## To install dependencies |
| 148 | + |
| 149 | +Run |
| 150 | +``` |
| 151 | +./tools/build/install_PHP_deps_in_dev_env.sh |
| 152 | +``` |
| 153 | +Instead of the usual `composer install`. |
| 154 | +This will select one of the generated composer's lock files (the one that corresponds to the current PHP version), |
| 155 | +copy it to `<repo root>/composer.lock`and install the packages using that `composer.lock` file. |
| 156 | + |
| 157 | +## To check which dependencies can be updated |
| 158 | +Run |
| 159 | +``` |
| 160 | +composer outdated |
| 161 | +``` |
| 162 | + |
| 163 | +## To update dependencies |
| 164 | +1) Update `composer.json` to the desired version of the dependency |
| 165 | +2) Run |
| 166 | +``` |
| 167 | +./tools/build/generate_composer_lock_files.sh && ./tools/build/install_PHP_deps_in_dev_env.sh |
| 168 | +``` |
| 169 | + |
| 170 | +instead of the usual `composer update` |
| 171 | + |
| 172 | +3) Commit the changes to the composer's lock files |
| 173 | + |
0 commit comments