pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://docs.pydantic.dev/logfire/
MIT License
1.62k stars 46 forks source link

Tail sampling #263

Closed alexmojaki closed 5 days ago

alexmojaki commented 1 week ago

There's some details which I'm unsure about such as defaults, but I'd like to get this through so we can test it out for ourselves. It could be quite useful in our backend, especially in places where we're using random trace sampling. Documentation and maybe some tweaking (including env var configuration) can come after we've used it.

Usage in a nutshell:

import logfire

logfire.configure(
    tail_sampling=logfire.TailSamplingOptions(
        # These are the defaults of TailSamplingOptions, tail_sampling is None by default.
        level='notice',  # include traces with at least one span/log at this level or higher
        duration=1.0,  # include traces with at least this duration
    ),
    # Also include 10% of traces randomly from the beginning, before checking the other conditions.
    trace_sample_rate=0.1,
)

Improper usage will eat up memory as the spans are buffered.

cloudflare-pages[bot] commented 1 week ago

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 80e8f4e
Status: âœ…  Deploy successful!
Preview URL: https://c7bf0f28.logfire-docs.pages.dev
Branch Preview URL: https://alex-tail-sampling.logfire-docs.pages.dev

View logs

codecov[bot] commented 1 week ago

Codecov Report

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

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