Platform.sh

Blackfire has built-in support for Platform.sh projects. The integration is made simpler as Blackfire agent and probe are installed and enabled by default on all Platform.sh accounts.

Blackfire server credentials and the .platform.app.yaml file should be configured out of the box for Platform.sh Obervability Suite customers. Those steps may then be ignored. Blackfire integration appears in the project settings in Platform.sh console.

Setting-Up Blackfire Credentials In Your Project

Set the Blackfire server credentials as environment variables (run this command from the root directory of your project):

To auto-fill server credentials in the command below, or first

platform var:create --name=BLACKFIRE_SERVER_ID --value=XXXX --level=project --prefix=env: --json=false --sensitive=false --visible-build=true --visible-runtime=true
platform var:create --name=BLACKFIRE_SERVER_TOKEN --value=XXXX --level=project --prefix=env: --json=false --sensitive=true --visible-build=true --visible-runtime=true

Note

You may also use your Platform.sh console

Setting-Up Blackfire Client Credentials to trigger CLI Profiles

The client credentials are required to trigger profiles with the CLI from your Platform.sh environments. In this case, set the client credentials as environment variables (run this command from the root directory of your project):

To auto-fill client credentials in the command below, or first

platform var:create --name=BLACKFIRE_CLIENT_ID --value=XXXX --level=project --prefix=env: --json=false --sensitive=false --visible-build=true --visible-runtime=true
platform var:create --name=BLACKFIRE_CLIENT_TOKEN --value=XXXX --level=project --prefix=env: --json=false --sensitive=true --visible-build=true --visible-runtime=true

Warning

CLI profiling relies on BLACKFIRE_CLIENT_ID and BLACKFIRE_CLIENT_TOKEN, your personal credentials. Only the user whose credentials are used can access those profiles from /my/profiles.

Please consider adding the --env=<ENV_UUID> parameter to send the profile to a shared environment and permit collaboration.

Configuring Your App

The configuration of your application depends on its type.

PHP Application

Add the blackfire PHP extension to the .platform.app.yaml project file:

1
2
3
runtime:
    extensions:
        - blackfire

Python Application

Note

Your application must have the Blackfire Probe installed as a pip dependency.

Update your .platform.app.yaml file to use the blackfire-python binary to start your webserver:

1
2
3
4
5
6
7
8
# .platform.app.yaml
web:
    upstream:
        socket_family: unix
    # Commands are run once after deployment to start the application process.
    commands:
        # Replace "my_app.wsgi" by your actual WSGI script.
        start: "blackfire-python gunicorn -w 4 -b unix:$SOCKET my_app.wsgi:application"

Builds Requires Production

Follow these steps to enable Blackfire builds on all your platform’s environments each time a branch is deployed (after a push, merge, or redeploy event):

  • Download and install the platform utility;
  • Enable the Blackfire’s integration on Platform.sh:

To auto-fill token credentials and environment UUID in the command below, or first

platform integration:add --type=webhook --url='https://TOKEN_USER:TOKEN_PASSWORD@blackfire.io/api/v2/builds/env/ENV_UUID/platformsh'

The command asks several questions. Hit enter to accept the default for all of them. If you get a permission error, ask a project admin to upgrade your account or ask someone who is an admin to run this command.

Now, whenever you push to a Platform.sh environment, Blackfire will automatically trigger a build for this specific environment. Blackfire scenarios will be run for all your pull requests.

GitHub integration

If you are using GitHub and if you have setup the synchronization between GitHub and Platform.sh, don’t forget to configure the Blackfire GitHub notification channel. That way, Blackfire will post a status on your GitHub pull requests.

Develop on GitHub, Deploy to Platform.sh and Test on Blackfire Requires Production

Here is a full video tutorial to get you started with the integration of the three services: