Creating Write Tokens
to theLogfireTo send data, you need to create a write token. A write token is a unique identifier that allows you to send data to a specific Logfire project sends data. If you follow First Step Guide Set Logfire, then you have bound a write token locally to the project you created. However, if you want to configure other computers to write to the project, such as in a deployed application, you need to create a new write token.
You can create a write token by following these steps:
-
in logfire.pydantic.dev open Logfire The Web interface.
-
Select your project from the"Project" section on the left side of the page.
-
Click "$>"in the upper right corner of the pageset"tab.
-
Select the{}Write tokenstab in the menu on the left.
-
Click theCreate Write Tokenbutton.
After creating the write token, you will see a dialog box containing the token value.copies this value and stores it securely, it will not displayagain.
You can now use this write token to send data from any computer or application to your Logfire for the project.
We recommend that you write tokens via environment variable injection in deployed applications. Set token to the environment variable 的值 LOGFIRE_TOKEN and logfire will automatically use it to send data to your project.
set send_to_logfire='if-token-present'¶
You may want to not send data to logfire during local development, but you can still choose to send data in a production environment without changing the code. To do this, we have logfire.configure() Parameters are provided in the function send_to_logfire='if-token-present'. If it is set to 'if-token-present' Only when the environment variable LOGFIRE_TOKEN Logfire sends data to logfire only if a write token exists in or is saved locally. If you run tests in CI, no data is sent.
You can also configure this option by setting the environmentnet variable LOGFIRE_SEND_TO_LOGFIRE. For example, you can set it to LOGFIRE_SEND_TO_LOGFIRE=true in deployed applications and LOGFIRE_SEND_TO_LOGFIRE=false in test settings.
本文总阅读量次