Utopia Span
[!IMPORTANT] This repository is a read-only mirror of
crates/utopia/spanin appwrite/appwrite. Development happens there — please open issues and pull requests against appwrite/appwrite.
Span tracing: attributes on the current span of each task, W3C trace context, and exporters to stdout, a terminal and Sentry.
This library is maintained by the Appwrite team.
Getting started
[]
= { = "https://github.com/appwrite/appwrite" }
A span records one unit of work, such as a request, a job or a query: what it was, the attributes that describe it, how long it took and whether it failed. Start a span when the work starts, add attributes from anywhere while it runs, and finish it to send it to your exporters.
Trace a request
Choose where the current span lives once at startup, start a span per request, and add attributes without passing the span around.
use Arc;
use ;
set_storage;
let span = init;
add;
add;
add;
assert_eq!;
span.finish;
assert_eq!;
Keep one span per task
In an async server, each request runs in its own task. The Task storage keeps one current span per task scope, and Auto falls back to the process's span outside one.
use Arc;
use ;
set_storage;
let first = scope;
let second = scope;
let = ;
assert_eq!;
assert_eq!;
Continue a trace across services
Pass the current span's traceparent header to the services you call; they start their spans from it, so all spans share one trace id.
use Span;
let incoming = new;
let header = incoming.traceparent;
let downstream = init;
assert_eq!;
assert_eq!;
Export spans
Exporters receive finished spans. Stdout writes JSON lines for log collectors, Pretty writes readable output for local development, and Sentry reports failed spans. Each takes a sampler to choose which spans it exports.
use Arc;
use ;
let errors_only = new.sampler;
let ok = new;
let failed = new;
failed.set_error;
assert!;
assert!;
set_exporters;
Report errors to Sentry
The Sentry exporter sends spans at warning level or above that carry an error. Attributes become contexts by default; a classifier turns low-cardinality ones into searchable tags.
use SentryField;
use ;
let sentry = new?
.environment
.classifier;
let span = new;
span.set;
span.finish_with;
assert!;
Contributing
Development happens in appwrite/appwrite, where this crate lives at crates/utopia/span. Run these commands from a checkout of it. The contributing guide covers each step.
Test
Compare with PHP
Replay the results PHP recorded for every case against Rust, without PHP:
COMPAT_LIB=span
Run every case on both runtimes, fuzz both with generated inputs, then run the whole conversion check. These need the dev stack (docker compose up -d):
Benchmark
This times every benchmark on PHP and on a release build of Rust, both in containers on the dev stack. It fails if Rust is slower. Add --write to record the run in tests/compat/span/bench.json. Run it on a quiet machine, one library at a time.
License
BSD-3-Clause. See LICENSE.