fn on_close(&self, span: Id, ctx: Context<'_, S>) {
        let span = ctx.span(&span).expect("Span not found, this is a bug");

        // Using a block to drop the immutable reference to extensions
        // given that we want to borrow it mutably just below
        let elapsed_milliseconds = {
            let extensions = span.extensions();
            extensions
                .get::<Instant>()
                .map(|i| i.elapsed().as_millis())
                // If `Instant` is not in the span extensions it means that the span was never
                // entered into.
                .unwrap_or(0)
        };

        #[cfg(not(feature = "arbitrary-precision"))]
        // without the arbitrary_precision feature u128 values are not supported,
        // but u64 is still more than enough for our purposes
        let elapsed_milliseconds: u64 = {
            use std::convert::TryInto;

            elapsed_milliseconds.try_into().unwrap_or_default()
        };

        let mut extensions_mut = span.extensions_mut();
        let visitor = extensions_mut
            .get_mut::<JsonStorage>()
            .expect("Visitor not found on 'record', this is a bug");

        if let Ok(elapsed) = serde_json::to_value(elapsed_milliseconds) {
            visitor.values.insert("elapsed_milliseconds", elapsed);
        }
    }
/// When we close a span, register how long it took in milliseconds.
When we close a span, register how long it took in milliseconds.
When we close a span register how long it took in milliseconds .
fn on_close(&self, span: Id, ctx: Context<'_, S>) {
        let span = ctx.span(&span).expect("Span not found, this is a bug");
        // Using a block to drop the immutable reference to extensions
        // given that we want to borrow it mutably just below
        let elapsed_milliseconds = {
            let extensions = span.extensions();
            extensions
                .get::<Instant>()
                .map(|i| i.elapsed().as_millis())
                // If `Instant` is not in the span extensions it means that the span was never
                // entered into.
                .unwrap_or(0)
        };
        #[cfg(not(feature = "arbitrary-precision"))]
        // without the arbitrary_precision feature u128 values are not supported,
        // but u64 is still more than enough for our purposes
        let elapsed_milliseconds: u64 = {
            use std::convert::TryInto;
            elapsed_milliseconds.try_into().unwrap_or_default()
        };
        let mut extensions_mut = span.extensions_mut();
        let visitor = extensions_mut
            .get_mut::<JsonStorage>()
            .expect("Visitor not found on 'record', this is a bug");
        if let Ok(elapsed) = serde_json::to_value(elapsed_milliseconds) {
            visitor.values.insert("elapsed_milliseconds", elapsed);
        }
    }
fn on_close ( & self , span : Id , ctx : Context < ' _ , S > ) { let span = ctx . span ( & span ) . expect ( " " ) ; // Using a block to drop the immutable reference to extensions // given that we want to borrow it mutably just below let elapsed_milliseconds = { let extensions = span . extensions ( ) ; extensions . get :: < Instant > ( ) . map ( | i | i . elapsed ( ) . as_millis ( ) ) // If `Instant` is not in the span extensions it means that the span was never // entered into. . unwrap_or ( 0 ) } ; # [ cfg ( not ( feature " " ) ) ] // without the arbitrary_precision feature u128 values are not supported, // but u64 is still more than enough for our purposes let elapsed_milliseconds : u64 = { use std :: convert :: TryInto ; elapsed_milliseconds . try_into ( ) . unwrap_or_default ( ) } ; let mut extensions_mut = span . extensions_mut ( ) ; let visitor = extensions_mut . get_mut :: < JsonStorage > ( ) . expect ( " " ) ; if let Ok ( elapsed ) = serde_json :: to_value ( elapsed_milliseconds ) { visitor . values . insert ( " " , elapsed ) ; } }
When we close a span, register how long it took in milliseconds.
When we close a span register how long it took in milliseconds .
&self
span
Id
ctx
Context<'_, S>
&self
span
Id
ctx
Context<'_, S>