OpenTelemetry span kind
A span can be assigned a span kind at creation. Span kind describes the relationship between the span, its parents, and its children in a trace.
You can choose between five different span kinds: Client, Server, Internal, Producer, or Consumer
For example, the parent of a server span should always be a client span, and the parent of a consumer span should always be a producer. If you do not explicitly assign a span kind, it is assigned Internal by default.
For a broader description of the different span kinds, see the official OpenTelemetry documentation.
Span kind implications
In addition to the above, span kind describes:
- Whether a span is a remote child or parent (has a remote call incoming or outgoing)
- Whether a child span represents a synchronous call. When a child span is synchronous, the parent is expected to wait for it to complete.
Span Kind | Synchronous | Asynchronous | Remote Incoming | Remote Outgoing |
---|---|---|---|---|
CLIENT | Yes | Yes | ||
SERVER | Yes | Yes | ||
PRODUCER | Yes | Maybe | ||
CONSUMER | Yes | Maybe | ||
INTERNAL |
Set a span kind
You can assign a span kind to a span at span start. This confines span kind to manual instrumentations, as you do not start your own spans in an automatic approach.
Each language has its own way of setting span kind. For example:
-
In Java, you would call the following code:
Span span = tracer.spanBuilder("/resource/path").setSpanKind(SpanKind.CLIENT).startSpan();
-
In .NET, you need to set it on your ActivitySource as ActivityKind.
-
In Ruby, you do it like you would define attributes:
tracer.in_span('foo', attributes: { "my-key-1" => "my-value-1" }, kind: :internal) do |span| # ... end