Skip to content

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 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/myserver", company_key="123456-abcde")

The server_url keyword is required only if Lightrun is used as an on-premise deployment.

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.

Note

The above methods for passing keywords can be combined. However, configuration parameters passed as keyword arguments 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
company Company name. -
server_url The URL of the Lightrun backend server (default: https://app.lightrun.com/ should only be changed when using Lightrun on-premise. -
com_lightrun_server Combined URL of of the company and the Lightrun backend server. This single parameter can be used instead of the combination of company and server_url. -
company_key The company's secret API key. -
breakpoint_expiration_sec The default expiration time for Lightrun actions. -
ignore_quota Whether or not to disable all performance safety measures.
Warning: Use with caution.
-
agent_regmetadata_file Path to a JSON file containing the agent's registration metadata (such as tags, and display name). -
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"}]')
-
dynamic_log_console_handler_format The format for the logs to be printed by inserted logpoints to the console. For example: '%(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 -
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. -
max_condition_cost Maximum allowed additional CPU load when inserting actions during condition evaluation (value between 0.1 and 1.0). 1.0
max_log_cpu_cost Maximum allowed additional CPU load when logging (value between 0.1 and 1.0). 1.0
max_snapshot_buffer_size

max_snapshot_buffer_size_in_bytes
Maximum allowed total bytes for snapshots. 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.
65653


32768
max_variable_size Maximum snapshot variable string size. To retrieve large values, add them as watch expressions to a snapshot. Note: Introduced in version 1.16 256
max_watchlist_variable_size Maximum size of snapshot variables that were specified via watch expressions. Introduced in version 1.16. 32768
default_certificate_pinning_enabled Enable/disable certificate pinning. Setting to false skips certificate checking. True
alsologtostderr Sends the logs to STDERR standard file as opposed to typically sending them over to STDOUT. True

Info

Except for the parameter company_key, all other configuration options have default values.


Last update: March 19, 2024