Python Pythonbeta

The Python Probe can be configured using environment variables. These settings can be set in your global shell configuration file (such as ~/.bashrc or ~/.zshrc), or in your project's local .env file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Sets the socket where the agent is listening.
# Possible value can be a unix socket or a TCP address.
# Defaults to unix:///var/run/blackfire/agent.sock on Linux,
# unix:///usr/local/var/run/blackfire-agent.sock on macOS,
# and to tcp://127.0.0.1:8307 on Windows.
# export BLACKFIRE_AGENT_SOCKET=unix:///var/run/blackfire/agent.sock

# Sets the timeout before the Probe drops the connection to
# the Blackfire Agent.
# export BLACKFIRE_AGENT_TIMEOUT=0.25

# Log verbosity level (4: debug, 3: info, 2: warning, 1: error)
# export BLACKFIRE_LOG_LEVEL=1

Using Environment Variables

You can configure the Python probe without modifying your code, by using environment variables.

  • BLACKFIRE_AGENT_SOCKET

    Sets the socket the Probe will contact the Agent on. Possible values can be a unix socket or a TCP address.

    The default value is platform dependent, as detailed below.

    On Linux:

    1
    BLACKFIRE_AGENT_SOCKET="unix:///var/run/blackfire/agent.sock"
    

    On macOS:

    1
    BLACKFIRE_AGENT_SOCKET="unix:///usr/local/var/run/blackfire-agent.sock"
    

    On Windows:

    1
    BLACKFIRE_AGENT_SOCKET="tcp://127.0.0.1:8307"
    
  • BLACKFIRE_AGENT_TIMEOUT

    Sets the timeout, in seconds, after which the Probe will drop the connection to the Agent. Default value is 0.25, which means 250ms.

    1
    BLACKFIRE_AGENT_TIMEOUT="0.25"
    
  • BLACKFIRE_LOG_LEVEL

    Sets the verbosity of Probe's log output. Default value is 1 (error).

    1
    2
    # 1: error, 2: warning, 3: info, 4: debug
    BLACKFIRE_LOG_LEVEL=1
    
  • BLACKFIRE_LOG_FILE

    Sets the output destination of Probe's log. Default value is empty.

    1
    BLACKFIRE_LOG_FILE="/tmp/probe.log"
    
  • BLACKFIRE_ENDPOINT

    Sets the API endpoint the profile data will be sent to.

    1
    BLACKFIRE_ENDPOINT="https://blackfire.io"
    
  • BLACKFIRE_CLIENT_ID

    Sets the client ID from the Client ID/Client Token credentials pair. It is used by the SDK when authenticating to the Blackfire API.

    Please log in or sign up first:

    or

  • BLACKFIRE_CLIENT_TOKEN

    Sets the client Token from the Client ID/Client Token credentials pair. It is used by the SDK when authenticating to the Blackfire API.

    Please log in or sign up first:

    or

Using the Probe in your Application

If needed, it is possible to configure the probe directly from the code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from blackfire import probe

probe.initialize(
     # The Blackfire Query, usually given by blackfire run or created on the fly by the SDK.
     query=None,
     # The network socket to use for contacting the agent
     agent_socket=None,
     # The connection timeout when connecting to the agent
     agent_timeout=None,
     # 1: error, 2: warning, 3: info, 4: debug
     log_level=None,
     # The destination of the log. i.e: /tmp/probe.log
     log_file=None,
     # Client credentials. If None, they are read from environment variables, or config_file.
     client_id=None,
     client_token=None,
     # Where to find the Blackfire CLI configuration file to retrieve the client_id and client_token values.
     config_file='~/.blackfire.ini'
     # The Blackfire API endpoint
     endpoint=None,
 )

Using the Blackfire CLI Configuration File

The Python SDK can look for the Client Credentials in the configuration file of the Blackfire CLI. The location of this file depends on the operating system you use. Read more about the CLI configuration.