Customize the Lightrun Python agent🔗
According to the Lightrun actions you specify, the agent dynamically inserts logs and snapshots in the target environment. The agent's behavior when performing these tasks is governed by a set of user-configurable properties.
Agent properties🔗
You can specify the agent properties within the code, on the command line, or by using a config file.
Specifying agent properties within the code🔗
You set agent configuration properties by entering keyword arguments in the lightrun.enable() call function. For example:
lightrun.enable(server_url="https://mycompany.com", company_key="123456-abcde")
The server_url keyword is required only if Lightrun is used as an on-premise deployment.
Specifying agent properties on the command line🔗
When you start your application with python -m lightrun, pass agent properties as --<property>=<value> arguments before the -- separator. For example:
python -m lightrun --company_key=<COMPANY_SECRET> --agent_log_level=debug -- app.py
For more information, see Run as command line argument.
Specifying agent properties using a config file🔗
When using lightrun.enable, you can either pass the company_key parameter (as above), or use the agent_config parameter as shown in this example.
The agent_config keyword must reference the full path to a user-created agent.config file.
You can see this an example agent.config file. The default parameter values can be modified for your own applications.
The config file contains one <property>=<value> pair per line. Lines that start with # are comments. Don't add spaces around =, and don't wrap values in quotes. Values can't contain the = character.
Note
The above methods for passing keywords can be combined. However, configuration parameters passed as keyword arguments or on the command line override the parameter values in agent.config (if provided).
Configuration parameters🔗
The following table lists the configuration parameters that can be set in both the agent.config file and the lightrun.enable() call function.
| Flag name | Description | Default value |
|---|---|---|
server_url | The URL of the Lightrun backend server (default: https://app.lightrun.com/) should only be changed when using Lightrun on-premise. The agent uses only the protocol, host, and port of this URL, and ignores any path. | https://app.lightrun.com |
company_key | The company's secret API key. | - |
breakpoint_expiration_sec | The default expiration time for Lightrun actions. | 3600 |
ignore_quota | Whether or not to disable all performance safety measures. Warning: Use with caution. | False |
agent_regmetadata_file | Path to a JSON file containing the agent's registration metadata (such as tags, and display name). A relative path is resolved against the directory of the agent_config file, or against the working directory if no config file is used. If the file can't be read, the agent doesn't start. For the file format, see Manage metadata and tags. | - |
metadata_registration_tags | Array of tags for the agent, can be used when there is no metadata file. You set agent tags by entering metadata_registration_tags argument in the lightrun.enable() call function. For example: lightrun.enable(company_key="<COMPANY_SECRET>", metadata_registration_tags='[{"name": "Production"},{"name": "EastUS"}]') | [{"name": "Production"}] |
dynamic_log_console_handler_format | The format for the logs to be printed by inserted logpoints to the console. | %(levelname)s: %(message)s |
dynamic_log_file_handler_file_pattern | The pattern for writing logpoints to a file. If this parameter is left empty, logs from inserted actions are not written to a file. | - |
dynamic_log_file_handler_format | The format for logs from inserted log points to be printed to the file specified in the dynamic_log_file_handler_file_pattern | %(levelname)s: %(message)s |
base_dir | Files from this directory will have a higher priority in the case of name conflicts. | sys.path[0] |
lightrun_wait_for_init | Block the application until the first time breakpoints are fetched from the server. This option is intended for short-running applications like serverless functions, and it ensures that the Lightrun agent has time to communicate with the Lightrun server before the short-running application disconnects. Note: Using lightrun_wait_for_init in a cloud environment will likely incur additional costs from the cloud provider due to a longer application runtime. | False |
lightrun_init_wait_time_seconds | Timeout in seconds for wait if lightrun_wait_for_init is set. | 2 |
max_snapshot_buffer_size max_snapshot_buffer_size_in_bytes | Maximum allowed total bytes for snapshots. Allowed range: 65536 to 2097152. Introduced in version 1.16, and replaces max_snapshot_buffer_size_in_bytes. Deprecation note: From version 1.16, This field is deprecated and replaced by max_snapshot_buffer_size. If it's set, it overrides max_snapshot_buffer_size. | 768000 - |
pinned_certs | A comma-separated list of public key hash values for the pinned certificates. Used only when default_certificate_pinning_enabled is set to true. Note: Introduced in version 1.16 | 515a630cfd1fb908e30087bcc20b7413ad146b9bf2b23d3aaa72c28e45b24fb2,c69ee141bb58642db8039cbef1c2aca53ff98d8ef672363affc1a7786365fbe5 |
max_variable_size | Maximum snapshot variable string size. To retrieve large values, add them as watch expressions to a snapshot. Allowed range: 32 to 2048. Note: Introduced in version 1.16 | 256 |
max_watchlist_variable_size | Maximum size of all snapshot variables that were specified via watch expressions. Allowed range: 256 to 70% of max_snapshot_buffer_size. Note: Introduced in version 1.16. Starting from version 1.53, a limit is applied to all variables. The limit is calculated as max_watchlist_variable_size divided by expressionCount. | 512KB |
max_collection_size | Controls the number of items captured for a collection. Allowed range: 1 to 2048. Note: Introduced in version 1.36. | 100 |
max_watchlist_collection_size | Controls the number of items captured for a collection in a watch expression. Allowed range: 100 to 70% of max_snapshot_buffer_size.Note: Introduced in version 1.36. | 1024 |
max_frames_with_vars | Controls the number of top stack frames for which to read values of local variables. Allowed range: 1 to 10. Note: Introduced in version 1.36. | 4 |
max_object_members | Controls the number of properties captured in an object. Allowed range: 1 to 2048. Note: Introduced in version 1.36. | 100 |
default_certificate_pinning_enabled | Enable/disable certificate pinning. Setting to false skips certificate checking. | False |
enable_pii_redaction | Enable personally identifiable information (PII) redaction at the agent's side (may affect the application's performance) | False |
alsologtostderr | Also sends the agent logs to STDERR, in addition to the log file. | False |
agent_log_max_file_size_mb | Maximum size in MB that a log file can reach before being rotated. | 10 |
agent_log_max_file_count | Maximum number of rotated log files to keep. Note that old files get deleted when this number of log files is reached. | 5 |
agent_log_target_dir | Sets the target directory for storing agent logs, which defaults to the operating system's temporary folder. From version 1.34, the log filename will be generated automatically according to the format: lightrun_python_agent.<PID>.<TIMESTAMP>.<LOG_ROTATION_RUNNING_INDEX>.log. For example: lightrun_python_agent.22840.20240513-153557.1.log. | Operating system's temporary folder |
agent_log_level | Minimum log level that is written to the log file. Available levels of severity, from the highest to lowest (not case sensitive): None, Fatal, Error, Warning, Info, Debug, and Verbose. | Info |
metadata_registration_displayName | The agent's display name. If it isn't set, Lightrun uses the host name and the process ID of the application. | - |
lightrun_extra_class_path | Additional paths that the agent indexes, on top of sys.path, so that you can add actions to their files. Each path can be a directory or a ZIP-format archive, such as a .zip, .whl, or .egg file. Separate multiple paths with the lightrun_extra_class_path_delimiter character. Relative paths are resolved against the working directory. | - |
lightrun_class_path | Paths that the agent indexes instead of sys.path. Accepts the same values as lightrun_extra_class_path. When this parameter is set, lightrun_extra_class_path is ignored. | - |
lightrun_extra_class_path_delimiter | The character that separates multiple paths in lightrun_class_path and lightrun_extra_class_path. | : |
ignore_pyc_files | Whether to skip compiled .pyc files when indexing source files. Set to false to index .pyc files as well. | True |
dynamic_log_is_colored_console | Whether to color the logs printed to the console by inserted logpoints. | True (False on Windows) |
max_condition_lines_rate | The maximum number of Python lines per second that the agent spends evaluating conditions, across all actions. When this limit is exceeded, conditions aren't evaluated and the action reports an error. | 5000 |
max_expression_lines | The maximum number of Python lines that the agent executes to evaluate a single expression. | 10000 |
max_dynamic_log_rate | The maximum number of log entries per second, across all logpoints. Short bursts can exceed this limit. When this limit is exceeded, logpoints are temporarily paused. | 30 |
max_dynamic_log_bytes_rate | The maximum number of log bytes per second, across all logpoints. Short bursts can exceed this limit. When this limit is exceeded, logpoints are temporarily paused. | 20480 |
Info
Except for the parameter company_key, all other configuration options have default values.
Note
If you set a value outside of its allowed range, the agent adjusts it to the nearest allowed value and prints a message to stderr.
HTTP-Proxy configuration🔗
A custom HTTP proxy server can be configured for the agent traffic.
The proxy server should support the CONNECT method.
proxy_host and proxy_port are mandatory settings, and should be provided together.
When specifying proxy_host, provide it as host.com without a protocol (e.g., https://host.com or http://host.com should not be used).
| Property name | Environment variable | Description |
|---|---|---|
proxy_host | LIGHTRUN_PROXY_HOST | HTTP-proxy host. |
proxy_port | LIGHTRUN_PROXY_PORT | HTTP-proxy port. |
proxy_username | LIGHTRUN_PROXY_USERNAME | HTTP-proxy username (optional). |
proxy_password | LIGHTRUN_PROXY_PASSWORD | HTTP-proxy password (optional). |
Environment variables🔗
The following environment variables override the values set in the agent.config file. Values passed to lightrun.enable() or on the command line override the environment variables.
| Environment variable | Description |
|---|---|
LIGHTRUN_TAGS | A comma-separated list of agent tags, for example, Production,EastUS. Sets metadata_registration_tags. For more information, see Manage metadata and tags. |
AGENT_LOG_LEVEL | Sets agent_log_level. |
AGENT_LOG_TARGET_DIR | Sets agent_log_target_dir. |
AGENT_LOG_MAX_FILE_SIZE_MB | Sets agent_log_max_file_size_mb. |
AGENT_LOG_MAX_FILE_COUNT | Sets agent_log_max_file_count. |
DISABLE_LIGHTRUN_AGENT | Set to true to prevent the agent from starting. Your application runs without the agent. |
LIGHTRUN_PROXY_HOST, LIGHTRUN_PROXY_PORT, LIGHTRUN_PROXY_USERNAME, LIGHTRUN_PROXY_PASSWORD | See HTTP-Proxy configuration. |