Skip to content

Feat: local mode, and allowing empty/unset API key to be passed for local_mode#7

Open
apelsynca wants to merge 5 commits into
logtide-dev:mainfrom
apelsynca:feat/no-send-mode
Open

Feat: local mode, and allowing empty/unset API key to be passed for local_mode#7
apelsynca wants to merge 5 commits into
logtide-dev:mainfrom
apelsynca:feat/no-send-mode

Conversation

@apelsynca

Copy link
Copy Markdown
Contributor

A bit of refactor (for the tests mostly), also moved function _process_value from client.py to payload_limits.py
And renamed it to apply_payload_limits (underscore was bad cuz async_client.py was also importing it)

In local mode (or if local_mode is 'if_unset_api_key' and the api_key unset) the client on log method call does nothing.

This allows for easy functionale in test environments, dev environments where you dont want to set api_key or just want to stop logtide from working

@Polliog Polliog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looked at the diff. The apply_payload_limits refactor and the test changes are fine. Three things to fix:

1. (blocking) local_mode is missing in the async client - async_client.py log() only checks self._closed, so with AsyncLogTideClient and local_mode=True logs still get sent. And since local_mode=True allows api_key=None, the async client will attempt to send with a null key. The same guard from the sync client needs to be replicated:

if self._closed or self.options.local_mode is True:
    return
if self.options.local_mode == "if_unset_api_key" and not self.options.api_key:
    return

2. dsn now always overwrites explicit api_url/api_key (models.py __post_init__). Before, explicit values won (if not self.api_url: ...); now dsn always wins and hand-passed values are silently dropped. Intentional?

3. default api_url = production + relaxed validation (models.py). With api_url now defaulting to https://api.logtide.dev, building ClientOptions(api_key="...") without a url or dsn no longer raises and silently points at prod. It used to raise ValueError. A misconfig ends up in production unnoticed.

Minor: dead comment # if self.options and the two TODOs in log(), plus a typo in the error message ("other then" -> "other than").

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