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

Commit 08c43ef

Browse files
author
Bogdan Drutu
authored
Add details about sampling and minimal details about Span and TraceConfig. (#6)
* Add details about sampling and minimal details about Span and TraceConfig. * Fix comments.
1 parent e2ce75a commit 08c43ef

5 files changed

Lines changed: 97 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* For details about the library structured see [Namespace and Package](https://github.com/census-instrumentation/opencensus-specs/blob/master/NamespaceAndPackage.md)
55

66
## Trace Design
7+
* Trace API is described [here](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/README.md)
8+
79
* Data model is defined [here](https://github.com/census-instrumentation/opencensus-proto/blob/master/trace/trace.proto)
810

911
## Tags Design

trace/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OpenCensus Library Trace API
2+
This document serves to document the "look and feel" of the open source trace API's. It describes
3+
the key types (classes, structures, etc.) and functions (methods, etc.). This document uses
4+
terminology (MUST, SHOULD, etc) from [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt).
5+
6+
## Main APIs
7+
* [Span API]()
8+
* [TraceConfig API]()
9+
10+
## Utils
11+
* [Sampling logic](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace
12+
/Sampling.md)

trace/Sampling.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Sampling
2+
3+
This document is about the sampling bit, sampling decision, samplers and how and when does
4+
OpenCensus sample traces. A sampled traces is a traces that gets exported via the configured
5+
exporters.
6+
7+
## Sampling Bit (propagated via TraceOptions)
8+
9+
Sampling bit is always set only at the start of a Span, and is using a `Sampler`
10+
11+
### What kind of samplers does OpenCensus support?
12+
* `AlwaysSample` - sampler that always makes a "yes" decision every time.
13+
* `NeverSample` - sampler that always makes a "no" decision every time.
14+
* `Probability` - sampler that tries to uniformly sample traces with a given probability. When
15+
applied to a child `Span` of a **sampled** parent `Span` then it keeps the sampling decision.
16+
17+
### How can users control the Sampler that is used for sampling?
18+
There are 2 ways to control the `Sampler` used when the library does sampling:
19+
* Controlling the global default `Sampler` via [TraceConfig](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/TraceConfig.md).
20+
* Pass a specific `Sampler` when start the [Span](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/Span.md)
21+
(a.k.a. "span-scoped").
22+
* For example `AlwaysSample` and `NeverSample` can be used to implement request-specific
23+
decisions such as those based on http paths.
24+
25+
### When does OpenCensus sample traces?
26+
The OpenCensus library does sampling based on the following rules:
27+
1. If the span is a root `Span` then a `Sampler` will be used to make the sampling decision:
28+
* If a "span-scoped" `Sampler` is provided, use it to determine the sampling decision.
29+
* Else use the global default `Sampler` to determine the sampling decision.
30+
2. If the span is a child of a remote `Span` the sampling decision will be:
31+
* If a "span-scoped" `Sampler` is provided, use it to determine the sampling decision.
32+
* Else use the global default `Sampler` to determine the sampling decision.
33+
2. If the span is a child of a local `Span` the sampling decision will be:
34+
* If a "span-scoped" `Sampler` is provided, use it to determine the sampling decision.
35+
* Else keep the sampling from the parent.

trace/Span.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Span API
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/trace/trace.proto).
5+
All Span implementations MUST not allow users to read the recorded data,
6+
7+
## Span structure
8+
9+
### SpanContext
10+
Represents all the information that MUST be propagated to child Spans and across process boundaries.
11+
A span context contains the tracing identifiers and the options that are propagated from parent
12+
to child Spans.
13+
14+
#### TraceId
15+
Is the identifier for a trace. It is worldwide unique with practically sufficient
16+
probability by being made as 16 randomly generated bytes. TraceId is used to group all spans for
17+
a specific trace together across all processes.
18+
19+
#### SpanId
20+
Is the identifier for a span. It is globally unique with practically sufficient probability by
21+
being made as 8 randomly generated bytes. When passed to a child Span this identifier becomes the
22+
parent span id for the child Span.
23+
24+
#### TraceOptions
25+
Represents the options for a trace. It is represented as 1 byte (bitmap).
26+
27+
##### Supported bits
28+
* Sampling bit - Bit to represent whether trace is sampled or not (mask `0x1`).
29+
30+
## Span creation API
31+
32+
TODO(bdrutu): Add details here.

trace/TraceConfig.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# TraceConfig API
2+
3+
Global configuration of the trace service. This allows users to change configs for the default
4+
sampler, maximum events to be kept, etc.
5+
6+
## TraceParams
7+
Represents the set of parameters that users can control
8+
* Default `Sampler` - used when creating a Span if no specific sampler is given.
9+
10+
TODO(bdrutu): Define the rest of the params.
11+
12+
## API Summary
13+
* Permanently update the active TraceParams.
14+
* Temporary update the active TraceParams. This API allows changing of the active params for a
15+
certain period of time. No more than one active temporary update can exist at any moment.
16+
* Get current active TraceParams.

0 commit comments

Comments
 (0)