Skip to content

Commit 1ec945d

Browse files
Merge pull request #4 from realFlowControl/installer
Use `datadog-setup.php` installer
2 parents 01a8b78 + 8657478 commit 1ec945d

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

README.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,14 @@ To add this buildpack to your project, run the following:
1414
heroku buildpacks:add --app <your-app-name> https://github.com/SpeedCurve-Metrics/heroku-buildpack-php-ddtrace.git
1515
```
1616

17+
Make sure to add this buildpack after the PHP buildpack, as a PHP binary is
18+
needed to run the installer.
19+
1720
## Configuration
1821

1922
This buildpack accepts several config vars. All of them are optional:
2023

21-
- `DDTRACE_EXT_PHP_API` - The PHP API version that your application uses. Defaults to `20210902`. Use `phpinfo()` to find the API version if you're not sure.
22-
- `DDTRACE_EXT_RELEASE` - The release name of [dd-trace-php](https://github.com/DataDog/dd-trace-php/releases/) to download. Defaults to `0.82.0`.
23-
- `DDTRACE_EXT_PKG_URL` - The URL to a dd-trace-php `.deb` file. This option overides `DDTRACE_EXT_RELEASE`.
24-
25-
### More information: `DDTRACE_EXT_PHP_API`
26-
27-
This buildpack does not determine that PHP API version automatically. The default value should work for most PHP versions, but if the version is wrong then you will see warnings like this in your application logs:
28-
29-
```
30-
PHP Warning: PHP Startup: ddtrace: Unable to initialize module
31-
Module compiled with module API=20210902
32-
PHP compiled with module API=20220829
33-
These options need to match
34-
```
35-
36-
You can change the version by setting the `DDTRACE_EXT_PHP_API` config var in Heroku. For example:
37-
38-
```
39-
heroku config:set --app <your-app-name> DDTRACE_EXT_PHP_API=20220829
40-
```
24+
- `DD_RELEASE` - The release name of [dd-trace-php](https://github.com/DataDog/dd-trace-php/releases/) to download. Defaults to `0.87.2`.
25+
- `DD_INSTALLER_URL` - The URL to the `datadog-setup.php` to be used (to be found on the [dd-trace-php release page](https://github.com/DataDog/dd-trace-php/releases/)).
26+
- `DD_PROFILING_ENABLED` - Set to a non empty value, this will install and enable the profiling extension.
27+
- `DD_APPSEC_ENABLED` - Set to a non empty value, this will install and enable the appsec extension.

bin/compile

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,70 @@ export_env_dir() {
3737
fi
3838
}
3939

40-
export_env_dir "$ENV_DIR" '^DDTRACE_EXT_'
40+
export_env_dir "$ENV_DIR" '^DD_|DDTRACE_'
4141

42-
topic "Preparing to install ddtrace PHP extension"
42+
topic "Preparing to install Datadog PHP extensions"
4343

44+
if ! which php >/dev/null; then
45+
error "PHP is not installed. Please add a PHP buildpack to your app before adding this buildpack."
46+
fi
47+
48+
# Warn folks about
4449
if [[ -n ${DDTRACE_EXT_PKG_URL:-} ]]; then
45-
echo "Using package URL '$DDTRACE_EXT_PKG_URL' (from "'$DDTRACE_EXT_PKG_URL env var).' | indent
50+
error "The environment variable \$DDTRACE_EXT_PKG_URL has been renamed to \$DD_INSTALLER_URL and it needs to be a URL to the desired 'datadog-setup.php' to be found at https://github.com/DataDog/dd-trace-php/releases"
51+
fi
52+
53+
if [[ -n ${DDTRACE_EXT_RELEASE:-} ]]; then
54+
echo "The environment variable \$DDTRACE_EXT_RELEASE got renamed to \$DD_RELEASE, rewriting it for now, please update your environment variable." | indent
55+
DD_RELEASE=$DDTRACE_EXT_RELEASE
56+
fi
57+
58+
if [[ -n ${DDTRACE_EXT_PHP_API} ]]; then
59+
echo "The environment variable \$DDTRACE_EXT_PHP_API is superfluous and will be ignored, feel free to remove it." | indent
60+
fi
61+
62+
if [[ -n ${DD_INSTALLER_URL:-} ]]; then
63+
echo "Using package URL '$DD_INSTALLER_URL' (from "'$DD_INSTALLER_URL env var).' | indent
4664
else
47-
if [[ -n ${DDTRACE_EXT_RELEASE:-} ]]; then
48-
echo "Using dd-trace-php release '$DDTRACE_EXT_RELEASE' (from "'$DDTRACE_EXT_RELEASE env var).' | indent
65+
if [[ -n ${DD_RELEASE:-} ]]; then
66+
echo "Using dd-trace-php release '$DD_RELEASE' (from "'$DD_RELEASE env var).' | indent
4967
else
50-
export DDTRACE_EXT_RELEASE="0.82.0"
51-
echo "Using dd-trace-php release '$DDTRACE_EXT_RELEASE' (default value)." | indent
68+
export DD_RELEASE="0.87.2"
69+
echo "Using dd-trace-php release '$DD_RELEASE' (default value)." | indent
5270
fi
53-
export DDTRACE_EXT_PKG_URL="https://github.com/DataDog/dd-trace-php/releases/download/"$DDTRACE_EXT_RELEASE"/datadog-php-tracer_"$DDTRACE_EXT_RELEASE"_amd64.deb"
71+
export DD_INSTALLER_URL="https://github.com/DataDog/dd-trace-php/releases/download/"$DD_RELEASE"/datadog-setup.php"
5472
fi
5573

56-
APT_DIR="$BUILD_DIR/.apt"
57-
APT_CACHE_DIR="$CACHE_DIR/apt/cache"
58-
PACKAGE_NAME="dd-php-tracer"
59-
PACKAGE_FILE=$APT_CACHE_DIR/archives/$PACKAGE_NAME.deb
74+
if [[ "$DD_INSTALLER_URL" != *datadog-setup.php ]]
75+
then
76+
error "The package URL is out of date. Please use the 'datadog-setup.php' file URL from the releases at https://github.com/DataDog/dd-trace-php/releases"
77+
fi
6078

61-
mkdir -p $APT_CACHE_DIR/archives/partial
62-
mkdir -p $BUILD_DIR/.apt
79+
topic "Downloading installer from $DD_INSTALLER_URL"
80+
curl --silent --show-error --fail --location --output datadog-setup.php $DD_INSTALLER_URL 2>&1 | indent
6381

64-
topic "Downloading package from $DDTRACE_EXT_PKG_URL"
65-
curl --silent --show-error --fail --location --output $PACKAGE_FILE $DDTRACE_EXT_PKG_URL 2>&1 | indent
82+
topic "Running Datadog installer"
6683

67-
topic "Installing ddtrace PHP extension"
68-
dpkg -x $PACKAGE_FILE $BUILD_DIR/.apt/
84+
OPTS=""
6985

70-
topic "Enabling ddtrace PHP extension"
86+
if [[ -n ${DD_PROFILING_ENABLED:-} ]];
87+
then
88+
OPTS+=" --enable-profiling"
89+
echo "Profiling will be enabled" | indent
90+
fi
7191

72-
if [[ -n ${DDTRACE_EXT_PHP_API:-} ]]; then
73-
echo "Using version '$DDTRACE_EXT_PHP_API' (from "'$DDTRACE_EXT_PHP_API env var).' | indent
74-
else
75-
export DDTRACE_EXT_PHP_API="20210902"
76-
echo "Using version '$DDTRACE_EXT_PHP_API' (default value)." | indent
92+
if [[ -n ${DD_APPSEC_ENABLED:-} ]];
93+
then
94+
OPTS+=" --enable-appsec"
95+
echo "Appsec will be enabled" | indent
7796
fi
7897

79-
touch /app/.heroku/php/etc/php/conf.d/datadog-php-custom.ini
80-
echo "[PHP]" >> /app/.heroku/php/etc/php/conf.d/datadog-php-custom.ini
81-
echo "extension=/app/.apt/opt/datadog-php/extensions/ddtrace-$DDTRACE_EXT_PHP_API.so" >> /app/.heroku/php/etc/php/conf.d/datadog-php-custom.ini
82-
echo "ddtrace.request_init_hook=/app/.apt/opt/datadog-php/dd-trace-sources/bridge/dd_wrap_autoloader.php" >> /app/.heroku/php/etc/php/conf.d/datadog-php-custom.ini
98+
mkdir -p $BUILD_DIR/opt
99+
100+
env -u PHP_INI_SCAN_DIR php datadog-setup.php --php-bin=all --install-dir=$BUILD_DIR/opt $OPTS 2>&1 | indent
101+
102+
topic "Validating installation"
103+
104+
env -u PHP_INI_SCAN_DIR php -v 2>&1 | indent
83105

84106
echo "Done" | indent

bin/detect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22

3-
echo "ddtrace PHP extension"
3+
echo "Datadog PHP extensions"
44
exit 0

0 commit comments

Comments
 (0)