Skip to content

feat(telemetry): USDT probes for tracing spans end - #257

Open
jsitnicki wants to merge 2 commits into
cloudflare:mainfrom
jsitnicki:jakub/PERF-2835-span-with-probe
Open

feat(telemetry): USDT probes for tracing spans end#257
jsitnicki wants to merge 2 commits into
cloudflare:mainfrom
jsitnicki:jakub/PERF-2835-span-with-probe

Conversation

@jsitnicki

Copy link
Copy Markdown

Problem

Code bases which use foundations are already instrumented with tracing spans, but there is no easy way to measure the duration of a specific span with a BPF-based tracer, like bpftrace or ebpf_exporter. One would have to craft custom uprobes at code offsets that shift with every build, and match span start/end events across await points and thread hops.

Solution

span_with_probe!("span::name") — a drop-in replacement for tracing::span("...") that additionally emits a per-span USDT probe at span end, span_end_<sanitized name>, receiving the span duration (ns) as an argument.

Key features:

  • Attaching is zero-cost for everything else: each call site gets a probe semaphore that tracers bump on attach; unattached spans don't even record a timestamp.
  • Works regardless of span sampling — probes fire with tracing disabled.
  • linux/x86_64 only; other platforms degrade to plain tracing::span. aarch64 support to follow.
  • Comes with a demo workload + bpftrace script, examples/span_with_probe, to show the intended use.

Our code bases are already instrumented with tracing spans, but there is
no easy way to attach a BPF tracer to a specific span's start/end and
measure its duration: one would have to craft custom uprobes at specific
code offsets, which shift with every build, and then match span start and
end events to each other across await points and thread hops, since an
async span can be suspended and resumed on a different thread.

This macro emits a per-span USDT probe at span end which receives the
span duration as an argument, so a tracer can attach to a single span by
name while all other spans pay no cost. The probe is armed via a per-span
semaphore only while a tracer is attached and works regardless of span
sampling.
Runs two spans instrumented with span_with_probe! in a loop, with
distinct delay ranges so their durations can be told apart. Comes with a
bpftrace script that attaches to both span end probes and prints duration
histograms.
/// semaphore in `.probes`). The two `{}` operands are the semaphore symbol
/// and the duration argument.
///
/// `usdt_provider` must not contain `:` (bpftrace attach points are

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a check for this when expanding the macro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants