Skip to main content

Module skywalking

Module skywalking 

Source
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 before upstream) extracts an incoming sw8 header to continue an existing trace, or begins a new one and makes the sampling decision. It creates this hop’s SpanContext, stores it in context.message, and injects a fresh downstream sw8 header so the upstream service joins the trace.
  • The end node (phase: end, placed after upstream) loads the span, and — when sampled — fire-and-forget POSTs a SkyWalking trace segment to <endpoint_addr>/v3/segments on 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 incoming sw8’s parent segment/service are honored for propagation (trace id + sampling flag are continued) but are not emitted as a formal refs segment-reference on the exported span.
  • Export is per-request and immediate (a detached tokio::spawn), not buffered on APISIX’s report_interval timer.
  • 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.
  • componentId is reported as 49 (generic HTTP) rather than APISIX’s 6002.

Structs§

SkywalkingPlugin
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 componentId reported 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 sw8 header value for span (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 source proxy-mirror/fault-injection use.