Expand description
Distributed tracing with Apache SkyWalking — a start/end node pair
wrapped around the upstream node.
Ported from APISIX’s skywalking.lua. The wire propagation format is the
SkyWalking sw8 header (see crate::plugins::util::trace).
- The start node (
phase: start, placed beforeupstream) extracts an incomingsw8header to continue an existing trace, or begins a new one and makes the sampling decision. It creates this hop’sSpanContext, stores it incontext.message, and injects a fresh downstreamsw8header so the upstream service joins the trace. - The end node (
phase: end, placed afterupstream) loads the span, and — when sampled — fire-and-forget POSTs a SkyWalking trace segment to<endpoint_addr>/v3/segmentson a detached task. The request path is never blocked by the export.
Both nodes always continue through the success port; neither ever routes
to the error port.
§Wiring
... -> skywalking(start) -> upstream -> skywalking(end) -> ...§Deviations / simplifications from APISIX
Full SkyWalking correlation (segment references, multi-span segments, the
ngx.ctx entry/exit span pair, the background report timer) is
intentionally reduced to a faithful subset:
- Each request exports a single-span segment (
spanId: 0,parentSpanId: -1,spanType: "Entry",spanLayer: "Http"). The incomingsw8’s parent segment/service are honored for propagation (trace id + sampling flag are continued) but are not emitted as a formalrefssegment-reference on the exported span. - Export is per-request and immediate (a detached
tokio::spawn), not buffered on APISIX’sreport_intervaltimer. - The segment is POSTed as a single JSON object to
/v3/segments; the real OAP endpoint also accepts a batch array — the single-object form is the documented subset here. componentIdis reported as49(generic HTTP) rather than APISIX’s6002.
Structs§
- Skywalking
Plugin - SkyWalking tracing node (a start or end half, selected by
phase).
Enums§
- Phase 🔒
- Which node of the start/end pair this instance is.
Constants§
- COMPONENT_
ID_ 🔒HTTP - SkyWalking
componentIdreported for the entry span (49 = generic HTTP).
Functions§
- build_
segment 🔒 - Builds the SkyWalking trace segment JSON for a finished span (pure; does no I/O). A single Entry/Http span mirroring the OAP HTTP segment protocol.
- build_
sw8 🔒 - Builds a downstream
sw8header value forspan(8 hyphen-separated fields, matching the SkyWalking cross-process propagation header):sample-traceId-parentSegmentId-parentSpanId-service-instance-endpoint-peer. All fields except the sample flag and the plain-integer parent span id are base64-encoded. - roll_
fraction 🔒 - Draws a pseudo-random fraction in
[0.0, 1.0)for sampling — the same cheap, non-cryptographic sourceproxy-mirror/fault-injectionuse.