Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 9d22f48

Browse files
author
Bogdan Drutu
authored
Add details about Span creation and context interaction. (#20)
1 parent d03fd18 commit 9d22f48

4 files changed

Lines changed: 66 additions & 18 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ Here is a layering structure of the proposed OpenCensus library:
6363
![Library components][LibraryComponents]
6464

6565
#### Context
66-
67-
Some of the features for distributed tracing and tagging need a way
68-
to propagate a specific context (trace, tags) in-process (possibly between threads)
69-
and between function calls.
66+
Some of the features for distributed tracing and tagging need a way to propagate a specific
67+
context (trace, tags) in-process (possibly between threads) and between function calls.
7068

7169
The key elements of the context support are:
7270

7371
* Every implementation MUST offer an explicit or implicit generic Context propagation mechanism
7472
that allows different sub-contexts to be propagated.
75-
* Languages that already have this support, like Go ([context.Context][goContext]) or C# ([Activity][activity]),
76-
MUST use the language supported generic context instead of building their own.
77-
* For an explicit generic context implementation you can look at the Java [io.grpc.Context][gRPCContext].
73+
* Languages that already have this support, like Go ([context.Context][goContext]) or C#
74+
([Activity][activity]), MUST use the language supported generic context instead of building their
75+
own.
76+
* For an explicit generic context implementation you can look at the Java
77+
[io.grpc.Context][gRPCContext].
7878

7979
#### Trace
8080

trace/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# OpenCensus Library Trace API
1+
# OpenCensus Library Trace
22
This document serves to document the "look and feel" of the open source trace API's. It describes
33
the key types (classes, structures, etc.) and functions (methods, etc.).
44

55
## Main APIs
6-
* [Span API](Span.md)
7-
* [TraceConfig API](TraceConfig.md)
6+
* [Span](Span.md)
7+
* [TraceConfig](TraceConfig.md)
88

99
## Utils
10-
* [Sampling logic](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/Sampling.md)
10+
* [Sampling logic](Sampling.md)

trace/Span.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# Span API
1+
# Span
22

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].
69

710
## Span structure
811

@@ -27,6 +30,51 @@ Represents the options for a trace. It is represented as 1 byte (bitmap).
2730
##### Supported bits
2831
* Sampling bit - Bit to represent whether trace is sampled or not (mask `0x1`).
2932

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.
3137

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
76+
propagation.
77+
78+
[goContext]: https://golang.org/pkg/context
79+
[javaContext]: https://github.com/grpc/grpc-java/blob/master/context/src/main/java/io/grpc/Context.java
80+
[SpanDataModel]: https://github.com/census-instrumentation/opencensus-proto/blob/master/trace/trace.proto

trace/TraceConfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# TraceConfig API
1+
# TraceConfig
22

33
Global configuration of the trace service. This allows users to change configs for the default
44
sampler, maximum events to be kept, etc.

0 commit comments

Comments
 (0)