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

Remove custom_scope_suffix parameter of Logfire.log #399

Merged
merged 4 commits into from
Sep 2, 2024

Conversation

alexmojaki
Copy link
Contributor

Based on the script below, it's about 20% faster to use logfire.with_settings(custom_scope_suffix='my_scope') rather than logfire.log(..., custom_scope_suffix='my_scope'). That's not a huge difference, but I was expecting it to be bigger.

import time

import logfire

logfire.configure(send_to_logfire=False, console=False)

lf = logfire.with_settings(custom_scope_suffix='my_scope')
start = time.time()
for i in range(100000):
    lf.log('info', 'Hello, world!')
end = time.time()
print(end - start)

start = time.time()
for i in range(100000):
    logfire.log('info', 'Hello, world!', custom_scope_suffix='my_scope')
end = time.time()
print(end - start)

The issue with logfire.log(..., custom_scope_suffix=...) is that it creates a new tracer each time. Fortunately these tracers go into a WeakKeyDictionary so they don't stick around for long, but if this changed it could lead to a memory leak.

Besides that, custom_scope_suffix is really only for very advanced users, so no need to bloat the API docs to make it more convenient.

These aren't super strong reasons, but this seems like an improvement overall, and I'd like to make this change now before we release v1 of the SDK.

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (95a43d4) to head (11a587c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #399   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          130       130           
  Lines         9499      9504    +5     
  Branches      1230      1232    +2     
=========================================
+ Hits          9499      9504    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Aug 26, 2024

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 11a587c
Status: ✅  Deploy successful!
Preview URL: https://408e03b2.logfire-docs.pages.dev
Branch Preview URL: https://alex-custom-scope-suffix.logfire-docs.pages.dev

View logs

@alexmojaki alexmojaki requested a review from Kludex August 26, 2024 10:38
@ChristopherGS ChristopherGS changed the title Remove custom_scope_suffix parameter of Logfire.log PYD-1066: Remove custom_scope_suffix parameter of Logfire.log Aug 26, 2024
Copy link

linear bot commented Aug 26, 2024

PYD-1066 Logfire SDK V1

@ChristopherGS ChristopherGS changed the title PYD-1066: Remove custom_scope_suffix parameter of Logfire.log Remove custom_scope_suffix parameter of Logfire.log Aug 26, 2024
@alexmojaki alexmojaki merged commit 8d7778d into main Sep 2, 2024
13 checks passed
@alexmojaki alexmojaki deleted the alex/custom-scope-suffix branch September 2, 2024 18:19
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