logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Use `stack_info` instead of `stack_offset`

Open Kludex opened this issue 9 months ago • 5 comments

Kludex avatar May 06 '24 14:05 Kludex

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 82f8c18
Status: ✅  Deploy successful!
Preview URL: https://120562c0.logfire-docs.pages.dev
Branch Preview URL: https://user-stack-level-on-openai.logfire-docs.pages.dev

View logs

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar May 06 '24 14:05 codecov[bot]

Can you try using this with structlog?

alexmojaki avatar May 08 '24 11:05 alexmojaki

Can you try using this with structlog?

Yeah, it doesn't work. That number 2 doesn't look correct. I'll not merge this.

Kludex avatar May 08 '24 11:05 Kludex

I've fixed this to also work with structlog. I've explained the + and - I've added. I think we need to refactor the logic we have around those stack_offset anyway

Kludex avatar May 09 '24 14:05 Kludex

I've made the following changes, hope it's OK:

  1. Removed the stack_info param from logfire_format. When it needs a stacklevel it can just find the user frame again. This makes things a bit cleaner and also means that instrument doesn't have to recompute stack_info just for formatting, it already has that info in its attributes.
  2. Also excluded stdlib frames. This means that the fastapi arguments logs now have no stack info at all, which I think is fine. We can make maybe them point at the endpoint function in the future, but there was no way they could get stack info from calling frames.
  3. Excluded list/set/dict comprehension frames, partly just to make tests consistent across versions.
  4. Remove the stack_offset param of Logfire.log as you suggested. I think it's best to just rip it out rather than deprecate, and it'd be good to hear from users who were using it (which is unlikely). Besides, the _stack_offset param of span was also removed, and that was also a public API.

alexmojaki avatar May 11 '24 11:05 alexmojaki

Merged so that I can immediately resolve conflicts in https://github.com/pydantic/logfire/pull/151.

alexmojaki avatar May 11 '24 11:05 alexmojaki