OpenCensus is being archived! Read the blog post to learn more

SpanKind

SpanKind

SpanKind details the relationships between spans in addition to the parent/child relationship. SpanKind is enumerated by the following values:

Type Value Meaning
SERVER 1 The span covers the server-side handling of an RPC
CLIENT 2 The span covers the client-side handling of an RPC
UNSPECIFIED 0 Unspecified

For example, given two spans that share the same name and traceID, if a trace starts on the client and then progresses to the server for continuity, their Kind can be set as CLIENT and SERVER respectively

Source code example

// Started on the client
ctx, cSpan := trace.StartSpan(ctx, "SpanStarted", trace.WithSpanKind(trace.SpanKindClient))

// Received from the server
ctx, sSpan := trace.StartSpan(ctx, "SpanStarted", trace.WithSpanKind(trace.SpanKindServer))
import io.opencensus.common.Scope;
import io.opencensus.trace.Span.Kind;

// Started on the client
try (Scope ss = TRACER.spanBuilder("SpanStarted").setSpanKind(Kind.CLIENT).startSpan()) {
}

// Started on the server
try (Scope ss = TRACER.spanBuilder("SpanStarted").setSpanKind(Kind.SERVER).startSpan()) {
}
from opencensus.trace.span import SpanKind

// Started on the client
with tracer.span("SpanStarted", span_kind=SpanKind.CLIENT) as span:
    pass

// Started on the server
with tracer.span("SpanStarted", span_kind=SpanKind.SERVER) as span:
    pass
// Not yet available as per
// https://github.com/census-instrumentation/opencensus-cpp/issues/231
tracer.startRootSpan({name: 'SpanStarted', kind: 'SERVER'}, rootSpan => {
});

tracer.startRootSpan({name: 'SpanStarted', kind: 'CLIENT'}, rootSpan => {
});

References

Resource URL
SpanKind proto proto/trace/v1.Span.SpanKind
Go API WithSpanKind option
Java API Span.Kind JavaDoc
Python API span.SpanKind
Node.js API span.SpanKind