Skip to content

feat: Add multi-token support for project migration#1672

Merged
alexmojaki merged 16 commits intomainfrom
multi-token-support
Feb 3, 2026
Merged

feat: Add multi-token support for project migration#1672
alexmojaki merged 16 commits intomainfrom
multi-token-support

Conversation

@adriangb
Copy link
Copy Markdown
Member

@adriangb adriangb commented Jan 29, 2026

Summary

Extend the token parameter in logfire.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

  • Add str | list[str] type support for token parameter in configure()
  • Parse comma-separated tokens from LOGFIRE_TOKEN env var
  • Create separate exporters for each token with independent HTTP sessions
  • Normalize token handling: single token stays as str, multiple tokens as list[str], empty/None stays None (via normalize_token() function)
  • Update CLI whoami command to validate and print project info for all configured tokens
  • Add documentation for project migration workflow

Usage

import logfire

# Single token (existing behavior, unchanged)
logfire.configure(token='my_token')

# Multiple tokens (new)
logfire.configure(token=['old_project_token', 'new_project_token'])

Or via environment variable:

export LOGFIRE_TOKEN=old_project_token,new_project_token

Test plan

  • make format passes
  • make lint passes
  • make typecheck passes
  • All token-related tests pass
  • All configure tests pass
  • All CLI tests pass
  • Docs build successfully

🤖 Generated with Claude Code

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Jan 29, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

@adriangb adriangb force-pushed the multi-token-support branch from b9bf0a1 to 01072b6 Compare January 29, 2026 12:48
@adriangb adriangb marked this pull request as ready for review January 29, 2026 17:07
adriangb and others added 3 commits January 29, 2026 12:11
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 token parameter in logfire.configure() to accept str | list[str]
  • Added support for comma-separated tokens in the LOGFIRE_TOKEN environment variable
  • Modified the configuration initialization to create separate export pipelines (traces, metrics, logs) for each token with independent HTTP sessions
  • Updated the CLI whoami command 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.

adriangb and others added 2 commits January 29, 2026 12:39
- 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>
@alexmojaki
Copy link
Copy Markdown
Collaborator

@adriangb is this fully ready for my review? are the comments above resolved?

@adriangb
Copy link
Copy Markdown
Member Author

@adriangb is this fully ready for my review? are the comments above resolved?

Yes should be!

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 2, 2026

@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.

adriangb and others added 5 commits February 2, 2026 12:03
- 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>
@adriangb adriangb requested a review from alexmojaki February 2, 2026 17:11
adriangb and others added 2 commits February 2, 2026 12:12
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional flags.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

alexmojaki and others added 2 commits February 3, 2026 17:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@alexmojaki alexmojaki enabled auto-merge (squash) February 3, 2026 15:54
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional flags.

Open in Devin Review

@alexmojaki alexmojaki merged commit a955f0e into main Feb 3, 2026
14 of 15 checks passed
@alexmojaki alexmojaki deleted the multi-token-support branch February 3, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants