You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: trace/Span.md
+54-6Lines changed: 54 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,11 @@
1
-
# Span API
1
+
# Span
2
2
3
-
This class represents a Span. A span contains a SpanContext and allows users to record
4
-
tracing events based on the data model defined [here](https://github.com/census-instrumentation/opencensus-proto/blob/master/opencensus/proto/trace/trace.proto).
5
-
All Span implementations MUST not allow users to read the recorded data,
3
+
Span represents a single operation within a trace. Spans can be nested to form a trace tree.
4
+
Often, a trace contains a root span that describes the end-to-end latency and, optionally, one or
5
+
more sub-spans for its sub-operations.
6
+
7
+
A span contains a SpanContext and allows users to record tracing events based on the data model
8
+
defined [here][SpanDataModel].
6
9
7
10
## Span structure
8
11
@@ -27,6 +30,51 @@ Represents the options for a trace. It is represented as 1 byte (bitmap).
27
30
##### Supported bits
28
31
* Sampling bit - Bit to represent whether trace is sampled or not (mask `0x1`).
29
32
30
-
## Span creation API
33
+
## Span creation
34
+
The implementation MUST allow users to create two types of Spans:
35
+
* Root Spans - spans that do not have a parent.
36
+
* Child Spans - the parent can be explicitly set or inherit from the Context.
31
37
32
-
TODO(bdrutu): Add details here.
38
+
When creating a Span the implementation MUST allow users to create the Span attached or detached
39
+
from the Context, this allows users to manage the interaction with the Context independently of
40
+
the Span lifetime:
41
+
* Attached to the Context - the newly created Span is attached to the Context.
42
+
* Detached from the Context - the newly created Span is not attached to any Context.
43
+
44
+
### How Span interacts with Context?
45
+
Context interaction represents the process of attaching/detaching a Span to the Context
46
+
in order to propagate it in-process (possibly between threads) and between function calls.
47
+
48
+
There are two supported implementations for the Context based on how the propagation is implemented:
49
+
* With implicit propagation - implicitly passed between function calls and threads, usually
50
+
implemented using thread-local variables (e.g. Java [io.grpc.Context][javaContext])
51
+
* With explicit propagation - explicitly passed between function calls and threads (e.g. Go
52
+
[context.Context][goContext])
53
+
54
+
When an implicit propagated Context is used, the implementation MUST use scoped objects to
55
+
attach/detach a Span (scoped objects represent auto closable objects, e.g. stack allocated
56
+
objects in C++):
57
+
* When attach/detach an already created Span the API MAY be called `WithSpan`.
58
+
* When attach/detach at the creation time the API MAY be called `StartSpan` or `StartScopedSpan`.
59
+
60
+
When an explicit propagated Context is used, the implementation MUST create a new Context when a
61
+
Span is attached (immutable Context):
62
+
* When attach/detach an already created Span the API MAY be called `WithSpan`.
63
+
* When attach/detach at the creation time the API MAY be called `StartSpan` or `StartScopedSpan`.
64
+
65
+
### What is Span lifetime?
66
+
Span lifetime represents the process of recording the start and the end timestamps to the Span
67
+
object:
68
+
* The start time is recorded when the Span is created.
69
+
* The end time needs to be recorded when the operation is ended.
70
+
71
+
### Why support Spans that are not attached to the Context?
72
+
* Allow users to use the OpenCensus library without using a Context.
73
+
* Allow users to have more control for the lifetime of the Span.
74
+
* There are cases, for example HTTP/RPC interceptors, where the Span creation and usage happens in
75
+
different places, and the user does not have control of the framework to control the Context
0 commit comments