Skip to content

f-string magic - #151

Merged
Kludex merged 72 commits into
mainfrom
alex/fstring-magic
May 13, 2024
Merged

Kludex merged 72 commits into
mainfrom
alex/fstring-magic

Conversation

@alexmojaki

@alexmojaki alexmojaki commented May 7, 2024 •

Copy link
Copy Markdown
Contributor

Leaving docs to another PR because https://docs.pydantic.dev/logfire/guides/onboarding_checklist/add_manual_tracing/ needs significant reworking anyway - it already uses f-strings where it shouldn't have and doesn't mention 'manual' formatting.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 7, 2024 •

Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a2ff570
Status: ✅  Deploy successful!
Preview URL: https://ca814859.logfire-docs.pages.dev
Branch Preview URL: https://alex-fstring-magic.logfire-docs.pages.dev

View logs

@codecov

codecov Bot commented May 7, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@alexmojaki
alexmojaki force-pushed the alex/fstring-magic branch from 30831f9 to 51e4af9 Compare May 9, 2024 19:29
@alexmojaki
alexmojaki marked this pull request as ready for review May 9, 2024 19:30
Comment thread logfire/_internal/config.py Outdated
fast_shutdown: bool = False,
scrubbing_patterns: Sequence[str] | None = None,
scrubbing_callback: ScrubCallback | None = None,
fstring_magic: bool | None = None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we said we'd change it for fstring_inspect or something? I don't recall the conversation properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to inspect_arguments

Comment thread logfire/_internal/formatter.py Resolved
Comment thread pyproject.toml
"protobuf >= 4.23.4",
"typing-extensions >= 4.1.0",
"tomli >= 2.0.1; python_version < '3.11'",
"executing>=2.0.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

python_version >= 3.9? Or... optional if not using the feature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Started doing this but decided not to. If we accidentally eagerly import executing somewhere we won't notice this breaking 3.8 because it'll be installed in CI.

Comment thread logfire/_internal/main.py
Comment on lines +550 to +554
fstring_frame = inspect.currentframe()
if fstring_frame.f_back.f_code.co_filename == Logfire.log.__code__.co_filename: # type: ignore
# fstring_frame.f_back should be the user's frame.
# The user called logfire.info or a similar method rather than calling logfire.log directly.
fstring_frame = fstring_frame.f_back # type: ignore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we use some utility function we have already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here 'user' includes us. We need the place where the actual logfire method was called, even if it's inside an integration.

Comment thread logfire/_internal/formatter.py Outdated
Comment on lines +417 to +418
except Exception:
source_segment_unparsed = ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is AttributeError only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, added a comment

@alexmojaki
alexmojaki requested a review from Kludex May 13, 2024 12:59
@Kludex
Kludex enabled auto-merge (squash) May 13, 2024 16:25
@Kludex
Kludex disabled auto-merge May 13, 2024 16:25
@Kludex
Kludex enabled auto-merge (squash) May 13, 2024 16:26
@Kludex
Kludex merged commit e3ff40e into main May 13, 2024
@Kludex
Kludex deleted the alex/fstring-magic branch May 13, 2024 16:27
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