Code Monkey home page Code Monkey logo

Comments (3)

sile avatar sile commented on May 30, 2024

Thank you for reaching out.

Your code snippets seem almost fine, so I'm wondering why that didn't work. The only problem that might be is if the channel is empty, span_rx.try_recv() will immediately return Err(TryRecvError::Empty) and break the above while loop.


BTW, if you could share a working example code to reproduce the issue, I would investigate it in more detail.

from rustracing_jaeger.

e-oz avatar e-oz commented on May 30, 2024

Thank you very much, you were right - loop was called before the request :)
I fixed it with RAII magic.

I'll post here parts of my code just in case if it will be useful.
Thank you again!

pub struct TraceSender<'a> {
    pub channel_receiver: &'a Receiver<FinishedSpan>,
    pub reporter: Option<&'a JaegerCompactReporter>,
}

impl<'a> Drop for TraceSender<'a> {
    fn drop(&mut self) {
        if let Some(reporter) = self.reporter {
            while let Ok(span) = self.channel_receiver.try_recv() {
                let _ = reporter.report(&[span]);
            }
        }
    }
}

pub struct TraceFactory {
    pub tracer: Tracer,
    channel_receiver: Receiver<FinishedSpan>,
    reporter: Option<JaegerCompactReporter>,
}

impl TraceFactory {
    pub fn new(tracer: Tracer, channel_receiver: Receiver<FinishedSpan>, reporter_name: &str) -> TraceFactory {
        let reporter = match JaegerCompactReporter::new(reporter_name) {
            Ok(r) => Some(r),
            Err(_) => None
        };
        TraceFactory { tracer, channel_receiver, reporter }
    }

    pub fn get_sender(&self) -> TraceSender {
        TraceSender { channel_receiver: &self.channel_receiver, reporter: self.reporter.as_ref() }
    }
}

from rustracing_jaeger.

sile avatar sile commented on May 30, 2024

My pleasure :)

from rustracing_jaeger.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.