add distributed tracing core (std.trace)#449
Merged
Merged
Conversation
second phase of observability support: spans. a span records one unit of work
(name, timing, attributes, status) and its place in a trace. spans nest through
a per-os-thread "current" span, so starting a span inside another parents it
automatically with no context threaded through calls:
span := trace.start("handle_request")
span.set_attr("http.route", "/api")
span.end()
built on the pieces already in place: the per-thread current span uses a
threadlocal global (#438); ids come from log.new_trace_id / new_span_id; timing
uses time.mono_nanos for a precise duration on a wall-clock base. tracing is off
until set_active(true) (std.obs.init flips it from the environment), so start()
is a cheap no-op in an uninstrumented program.
- crossing a spawn: capture current_context() and re-establish it in the task
with with_context() (the one place propagation is explicit)
- crossing a process: W3C traceparent format/parse for http/grpc headers
- ended spans collect in a bounded buffer that the OTLP exporter drains next
verified: 3 unit tests (nesting via the current span, no-op when inactive,
traceparent round-trip) plus a cross-spawn program confirming a child task joins
the parent's trace and parents under the root; 85 examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
second phase of observability: spans. a span records one unit of work (name,
timing, attributes, status) and its place in a trace. spans nest through a
per-os-thread "current" span, so starting a span inside another parents it
automatically — no context threaded through calls:
built on pieces already in place: the per-thread current span uses a
threadlocalglobal (#438); ids come fromlog.new_trace_id/new_span_id;time.mono_nanosgives a precise duration on a wall-clock base. tracing is OFFuntil
set_active(true)(std.obs.initwill flip it from the environment), sostart()is a cheap no-op in an uninstrumented program.spawn: capturecurrent_context()and re-establish it in the taskwith
with_context()(the one place propagation is explicit)traceparentformat/parse for http/grpc headerswhat was tested
traceparentround-trip
spawnprogram confirming a child task joins the parent's trace andparents under the root
pure-additive stdlib; no compiler change, no bootstrap seed refresh.