-
Notifications
You must be signed in to change notification settings - Fork 117
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
base: main
Are you sure you want to change the base?
Conversation
It is guaranteed to be set
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).
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' |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this 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
try: | ||
response = self._get('/v1/organizations') | ||
except UnexpectedResponse as e: | ||
raise LogfireConfigError('Error retrieving list of organizations') from e |
There was a problem hiding this comment.
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:
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, yes
3831bd8
to
22ba035
Compare
Deploying logfire-docs with
|
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 |
22ba035
to
cf0860f
Compare
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.