Skip to content
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

Add logfire.add_non_user_code_prefix function for library developers #829

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Jan 29, 2025

Adds a public API for adding items to the tuple of non-user-code-prefixes, so that the frames are excluded in logfire spans. This will be used in pydantic_ai; see occurrences of the following in that codebase:

# while waiting for https://github.com/pydantic/logfire/issues/745
try:
    import logfire._internal.stack_info
except ImportError:
    pass
else:
    from pathlib import Path

    logfire._internal.stack_info.NON_USER_CODE_PREFIXES += (str(Path(__file__).parent.absolute()),)

Closes #745

Copy link

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

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a1a80fc
Status: ✅  Deploy successful!
Preview URL: https://660b28db.logfire-docs.pages.dev
Branch Preview URL: https://non-user-code-prefix.logfire-docs.pages.dev

View logs

@alexmojaki
Copy link
Contributor

alexmojaki commented Jan 29, 2025

Please add it to logfire.testing since that's what this is really intended for and the logfire namespace is already crowded, and make it accept a module for usability.

@alexmojaki alexmojaki self-assigned this Feb 3, 2025
@alexmojaki alexmojaki force-pushed the non-user-code-prefix branch from 57f2093 to a1a80fc Compare February 3, 2025 12:31
@alexmojaki
Copy link
Contributor

I've decided against the logfire.testing idea because that module requires pytest. I think the module thing would be good but I guess it's not essential and I'd like to merge this.

@alexmojaki alexmojaki enabled auto-merge (squash) February 3, 2025 12:33
@alexmojaki alexmojaki changed the title Add non-user-code-prefix stuff Add logfire.add_non_user_code_prefix function for library developers Feb 3, 2025
@alexmojaki alexmojaki merged commit bb7913b into main Feb 3, 2025
14 checks passed
@alexmojaki alexmojaki deleted the non-user-code-prefix branch February 3, 2025 12:37
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.

add def non_user_code_prefix
2 participants