Documentation
¶
Overview ¶
Package rpctrace carries a caller's trace context across a CEDAR command, so the server's work can be recorded as a child of the client's span.
cedar does not import a tracing library. It defines the W3C trace context it carries (TraceContext), how a process hands one to cedar and gets one back (ContextWithTraceContext, TraceContextFromContext), and the outcome classes its client and server trace hooks report (ErrorClass). The embedder, which owns the OpenTelemetry dependency, converts at the edge and records spans.
See protocol/RPC_TRACING.md for where the context rides on the wire and which commands can carry it.
Index ¶
Constants ¶
const TraceParentLen = 55
TraceParentLen is the length of a version-00 traceparent: "00-" + 32 hex + "-" + 16 hex + "-" + 2 hex.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTraceContext ¶
func ContextWithTraceContext(ctx context.Context, t TraceContext) context.Context
ContextWithTraceContext returns ctx carrying t. The server does this for the handler of a command whose trace context it trusts.
Types ¶
type ErrorClass ¶
type ErrorClass uint8
ErrorClass is a traced command's outcome, coarse enough to be a span attribute.
const ( // ErrorNone is a command that completed. ErrorNone ErrorClass = iota // ErrorDial is a client that could not connect: TCP, shared port or CCB. ErrorDial // ErrorHandshake is a security negotiation, authentication or session // resumption that failed. ErrorHandshake // ErrorDenied is a command the server refused: an authorization failure, // an unregistered command, or a session that does not meet the command's // security level. ErrorDenied // ErrorCanceled is a command whose context ended first. ErrorCanceled // ErrorHandler is a server handler that returned an error. ErrorHandler )
func (ErrorClass) String ¶
func (c ErrorClass) String() string
type TraceContext ¶
type TraceContext struct {
TraceID [16]byte
SpanID [8]byte
Flags byte // W3C trace-flags; bit 0 is "sampled"
}
TraceContext is a W3C trace context in binary form: the identity of the caller's span.
The fields are laid out as OpenTelemetry's trace.TraceID, trace.SpanID and trace.TraceFlags are, so converting in either direction copies arrays and allocates nothing.
func ParseTraceParent ¶
func ParseTraceParent(s string) (TraceContext, bool)
ParseTraceParent parses a W3C traceparent header value. It accepts version 00 exactly, and a later version when its first 55 characters have version 00's layout and anything after them starts with '-', as the W3C specification asks of a version it does not know. Version ff, upper-case hex and an all-zero trace or span ID are refused.
func TraceContextFromContext ¶
func TraceContextFromContext(ctx context.Context) (TraceContext, bool)
TraceContextFromContext returns the trace context carried by ctx, if any.
Its signature matches security.SecurityConfig.TraceContext, so a process that both serves and calls CEDAR commands can forward a trusted incoming trace to its own calls with TraceContext: rpctrace.TraceContextFromContext and no tracing library.
func (TraceContext) IsValid ¶
func (t TraceContext) IsValid() bool
IsValid reports whether t identifies a span: W3C treats an all-zero trace ID or span ID as absent.
func (TraceContext) Sampled ¶
func (t TraceContext) Sampled() bool
Sampled reports whether the caller chose to record this trace.
func (TraceContext) TraceParent ¶
func (t TraceContext) TraceParent() string
TraceParent formats t as a W3C traceparent header value, version 00: "00-<trace-id>-<span-id>-<flags>" in lower-case hex.