Skip to content

Configuration

You can use the following ways to configure Logfire:

  1. Programmatically via logfire.configure()
  2. Using environment variables
  3. Using a configuration file (pyproject.toml)

The order of precedence is as above.

Programmatically via configure

For more details, please refer to our API documentation.

Using environment variables

You can use the following environment variables to configure Logfire:

NameDescription
LOGFIRE_BASE_URLThe base URL of the Logfire backend. Primarily for testing purposes.
LOGFIRE_SEND_TO_LOGFIREWhether to send spans to Logfire.
LOGFIRE_MIN_LEVELMinimum log level for logs and spans to be created. By default, all logs and spans are created.
LOGFIRE_TOKENToken for sending application telemetry data to Logfire, also known as a “write token”. Can be a comma-separated list for multi-project export.
LOGFIRE_API_KEYAPI key for Logfire API access (used for managed variables and other public APIs).
LOGFIRE_SERVICE_NAMEName of the service emitting spans. For further details, please refer to the Service section.
LOGFIRE_SERVICE_VERSIONVersion number of the service emitting spans. For further details, please refer to the Service section.
LOGFIRE_ENVIRONMENTEnvironment in which the service is running. For further details, please refer to the Deployment section.
LOGFIRE_TRACE_SAMPLE_RATEHead sampling rate for traces.
LOGFIRE_CREDENTIALS_DIRThe directory where to store the configuration file.
LOGFIRE_CONSOLEWhether to enable/disable the console exporter.
LOGFIRE_CONSOLE_COLORSWhether to use colors in the console.
LOGFIRE_CONSOLE_SPAN_STYLEHow spans are shown in the console.
LOGFIRE_CONSOLE_INCLUDE_TIMESTAMPWhether to include the timestamp in the console.
LOGFIRE_CONSOLE_INCLUDE_TAGSWhether to include tags in the console.
LOGFIRE_CONSOLE_VERBOSEWhether to log in verbose mode in the console.
LOGFIRE_CONSOLE_MIN_LOG_LEVELMinimum log level to show in the console.
LOGFIRE_CONSOLE_SHOW_PROJECT_LINKWhether to enable/disable the console exporter.
LOGFIRE_PYDANTIC_PLUGIN_RECORDWhether instrument Pydantic validation..
LOGFIRE_PYDANTIC_PLUGIN_INCLUDESet of items that should be included in Logfire Pydantic plugin instrumentation.
LOGFIRE_PYDANTIC_PLUGIN_EXCLUDESet of items that should be excluded from Logfire Pydantic plugin instrumentation.
LOGFIRE_INSPECT_ARGUMENTSWhether to enable the f-string magic feature. On by default for Python 3.11 and above.
LOGFIRE_IGNORE_NO_CONFIGWhether to show a warning message if logfire if used without calling logfire.configure()
LOGFIRE_DISTRIBUTED_TRACINGWhether to extract incoming trace context. By default, will extract but warn about it.
LOGFIRE_HTTPX_CAPTURE_ALLWhether to capture all HTTP headers, request and response bodies when using logfire.instrument_httpx()
LOGFIRE_AIOHTTP_CLIENT_CAPTURE_ALLWhether to capture all HTTP headers, request and response bodies when using logfire.instrument_aiohttp_client()

When using environment variables, you still need to call logfire.configure(), but you can leave out the arguments.

Using a configuration file (pyproject.toml)

You can use the pyproject.toml to configure Logfire.

Here’s an example:

[tool.logfire]
project_name = "My Project"
console_colors = "never"

The keys are the same as the parameters of logfire.configure().