跳转至

配置

您可以通过以下几种方式配置Logfire:

  1. 通过 [logfire.configure()][logfire.configure] 以编程方式

  2. 使用环境变量

  3. 使用配置文件 (pyproject.toml)

优先顺序如上所述。

通过 configure 以编程方式

更多详情请参考我们的【API文档】[logfire.configure]。

使用环境变量

您可以使用以下环境变量来配置Logfire

Name Description
LOGFIRE_BASE_URL Use to set the base URL of the Logfire backend.
LOGFIRE_SEND_TO_LOGFIRE Whether to send spans to Logfire.
LOGFIRE_TOKEN Token for the Logfire API.
LOGFIRE_PROJECT_NAME Name of the project. Project name accepts a string value containing alphanumeric characters and hyphens (-). The hyphen character must not be located at the beginning or end of the string and should appear in between alphanumeric characters.
LOGFIRE_SERVICE_NAME Name of the service emitting spans. For further details, please refer to the Service section.
LOGFIRE_SERVICE_VERSION Version number of the service emitting spans. For further details, please refer to the Service section.
LOGFIRE_TRACE_SAMPLE_RATE Default sampling ratio for traces. Can be overridden by the logfire.sample_rate attribute of a span.
LOGFIRE_SHOW_SUMMARY Whether to show the summary when a new project is created.
LOGFIRE_CREDENTIALS_DIR The directory where to store the configuration file.
LOGFIRE_COLLECT_SYSTEM_METRICS Whether to collect system metrics.
LOGFIRE_CONSOLE Whether to enable/disable the console exporter.
LOGFIRE_CONSOLE_COLORS Whether to use colors in the console.
LOGFIRE_CONSOLE_SPAN_STYLE How spans are shown in the console.
LOGFIRE_CONSOLE_INCLUDE_TIMESTAMP Whether to include the timestamp in the console.
LOGFIRE_CONSOLE_VERBOSE Whether to log in verbose mode in the console.
LOGFIRE_CONSOLE_MIN_LOG_LEVEL Minimum log level to show in the console.
LOGFIRE_PYDANTIC_PLUGIN_RECORD Whether instrument Pydantic validation..
LOGFIRE_PYDANTIC_PLUGIN_INCLUDE Set of items that should be included in Logfire Pydantic plugin instrumentation.
LOGFIRE_PYDANTIC_PLUGIN_EXCLUDE Set of items that should be excluded from Logfire Pydantic plugin instrumentation.
LOGFIRE_INSPECT_ARGUMENTS Whether to enable the f-string magic feature. On by default for Python 3.11 and above.
LOGFIRE_IGNORE_NO_CONFIG Whether to show a warning message if logire if used without calling logfire.configure()

使用环境变量时,您仍然需要调用 logfire.configure(),但您可以省略参数。

使用配置文件 (pyproject.toml)

您可以使用 pyproject.toml 来配置 Logfire

下面是一个示例:

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

键与 logfire.configure() 的参数相同。


本文总阅读量