Skip to content

Consider adding atomic new_span_and_enter and exit_and_close span events? #1280

Open
@matklad

Description

@matklad

In near/nearcore#4033 (comment), I've noticed that tracing reports spurious idle time. That is, my code looks like this:

{
  let _s = tracing::info_span("blurb").entered();
  do_important_blockchain_stuff()
}

and the logs look like this:

blurb: close time.busy=18.2ms time.idle=1.15µs

Note how the idle time is non-zero.

The reason for that is that tracing emits separate events for span exiting and span closing (and for span creation and exiting). In both callbacs, tracing calls Instant::now and the diff between the two (which is overhead of the tracing itself) gets counted as idle time.

I think the fix here is to allow atomically exit and close span, so that only one time measurement can be taken. Not sure what's the appropriate abstraction to add this API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/coreRelated to the `tracing-core` cratecrate/tracingRelated to the `tracing` cratekind/featureNew feature or requestneeds/designAdditional design discussion is required.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions