feat: Add multi-token support for project migration#1672
Conversation
Deploying logfire-docs with
|
| Latest commit: |
76a19eb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://174ff46b.logfire-docs.pages.dev |
| Branch Preview URL: | https://multi-token-support.logfire-docs.pages.dev |
b9bf0a1 to
01072b6
Compare
Extend the `token` parameter in `logfire.configure()` to accept a list of tokens. When multiple tokens are provided, duplicate export pipelines (traces, metrics, logs) are created for each token, enabling seamless migration between Logfire projects by double-writing data. - Add `str | list[str]` type support for token parameter - Parse comma-separated tokens from LOGFIRE_TOKEN env var - Create separate exporters for each token with independent sessions - Update CLI whoami to handle list of tokens - Add documentation for project migration workflow Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
f59a532 to
a6b8184
Compare
There was a problem hiding this comment.
Pull request overview
This pull request adds multi-token support to Logfire, enabling users to send telemetry data to multiple Logfire projects simultaneously. This is particularly useful for seamless migration between projects during a transition period.
Changes:
- Extended the
tokenparameter inlogfire.configure()to acceptstr | list[str] - Added support for comma-separated tokens in the
LOGFIRE_TOKENenvironment variable - Modified the configuration initialization to create separate export pipelines (traces, metrics, logs) for each token with independent HTTP sessions
- Updated the CLI
whoamicommand to display information for all configured tokens - Added comprehensive documentation for the project migration workflow
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
logfire/_internal/config_params.py |
Added _extract_list_of_str helper function and updated TOKEN parameter to accept list[str] type |
logfire/_internal/config.py |
Modified token normalization logic and updated exporter creation to loop over multiple tokens, creating independent pipelines for each |
logfire/_internal/cli/__init__.py |
Enhanced whoami command to iterate through and display information for multiple tokens |
logfire-api/logfire_api/_internal/config.pyi |
Updated type signatures for configure() and related methods to reflect str | list[str] token parameter |
tests/test_configure.py |
Added comprehensive tests for multi-token scenarios and updated existing test to expect list format |
tests/test_cli.py |
Added test for whoami command with multiple tokens |
docs/reference/advanced/migrate-to-new-project.md |
Added comprehensive documentation explaining the migration workflow with examples |
mkdocs.yml |
Added navigation entry for the new migration documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Modify check_token() to validate and print project info for all tokens
- Fix grammar in migration docs ("eases" -> "ease", add period)
- Expand test coverage for _extract_list_of_str function
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename _extract_list_of_str to extract_list_of_str to fix pyright reportPrivateUsage error - Fix relative links in migration docs (../../ instead of ../) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@adriangb is this fully ready for my review? are the comments above resolved? |
Yes should be! |
|
@alexmojaki I've opened a new pull request, #1681, to work on those changes. Once the pull request is ready, I'll request review from you. |
- Add normalize_token() function that returns str for single token, list[str] for multiple tokens, or None for no tokens - Simplify token validation/printing logic with printed_tokens set to track which tokens have already been displayed - Keep eager printing from credentials file for fast feedback - Single token from credentials file now stored as str not [str] Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove redundant printed_tokens.add() in background thread - Move None/empty handling to normalize_token early - Simplify extract_list_of_str by removing None from type signature Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
Extend the
tokenparameter inlogfire.configure()to accept a list of tokens for multi-project export. When multiple tokens are provided, duplicate export pipelines (traces, metrics, logs) are created for each token, enabling seamless migration between Logfire projects by double-writing data.Changes
str | list[str]type support for token parameter inconfigure()LOGFIRE_TOKENenv varstr, multiple tokens aslist[str], empty/None staysNone(vianormalize_token()function)whoamicommand to validate and print project info for all configured tokensUsage
Or via environment variable:
export LOGFIRE_TOKEN=old_project_token,new_project_tokenTest plan
make formatpassesmake lintpassesmake typecheckpasses🤖 Generated with Claude Code