Skip to content

Refactor user tokens, introduce Logfire client #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Apr 3, 2025

This is a refactor in preparation of #961.

I'm introducing a Logfire client, so that we can use it in the various LogfireCredentials methods without passing the base URL and session around. A proper user token structure is also introduced (which will also be useful for the whoami command improvements).

Early PR before adapting test to get some early feeback.

Viicos added 5 commits April 3, 2025 18:03
Most of the changes are in the `LogfireCredentials` class,
where we don't pass in base URLs, tokens and sessions anymore.
Any API-only related operations are defined on the new Logfire client,
and `LogfireCredentials` now only has the actual functional logic
(with user prompts, etc).
@Viicos Viicos marked this pull request as draft April 3, 2025 16:54
Comment on lines +70 to +100
from .config import PYDANTIC_LOGFIRE_TOKEN_PATTERN, REGIONS

region = 'us'
if match := PYDANTIC_LOGFIRE_TOKEN_PATTERN.match(self.token):
region = match.group('region')
if region not in REGIONS:
region = 'us'
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this should be a separate method/function

return token

def is_logged_in(self, base_url: str | None = None) -> bool:
if base_url is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

The base_url is None case seems weird to me

Copy link
Contributor

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

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

General idea looks good

Comment on lines +50 to +71
try:
response = self._get('/v1/organizations')
except UnexpectedResponse as e:
raise LogfireConfigError('Error retrieving list of organizations') from e
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it should be something like this:

Suggested change
try:
response = self._get('/v1/organizations')
except UnexpectedResponse as e:
raise LogfireConfigError('Error retrieving list of organizations') from e
response = self._get('/v1/organizations')
LogfireConfigError.raise_for_status(response, 'Error retrieving list of organizations')

)

def __str__(self) -> str:
# TODO define in this module?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, yes

@Viicos Viicos force-pushed the refactor-user-tokens branch from 3831bd8 to 22ba035 Compare April 30, 2025 13:11
Copy link

cloudflare-workers-and-pages bot commented Apr 30, 2025

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: cf0860f
Status: ✅  Deploy successful!
Preview URL: https://01e5e4eb.logfire-docs.pages.dev
Branch Preview URL: https://refactor-user-tokens.logfire-docs.pages.dev

View logs

@Viicos Viicos force-pushed the refactor-user-tokens branch from 22ba035 to cf0860f Compare April 30, 2025 13:12
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.

2 participants