Skip to content

Allow sampling #7

@y2kappa

Description

@y2kappa

I need to run this in production because I simply cannot profile locally. If my server has many hits this takes a big toll on my log quota so I'd like to sample when trace information is dumped.

I think the user should be able to provide a sampling rate, like 500, it has 1/500 chance of being recorded.

I think this should be done in the new constructor:

pub fn new(id: &str, processor: Option<fn(&str)>, stats: Option<TracingStats>) -> Trace {
        let trace = Trace {
            id: id.into(),
            processor: processor.unwrap_or(|x: &str| {
                println!("{}", x);
            }),
            stats: stats.unwrap_or(TracingStats::None),
        };
        Self::register(&trace.id);
        trace
}

Something like

if rand() == self.sampling_rate {
    Self::register(&trace.id);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions