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

Commit 52a0a4b

Browse files
authored
Documentation updates. (#263)
* Add README for context/ and tags/ dirs. * Add links to new materials on https://opencensus.io/. * Improve span.h comments about thread safety and immutability.
1 parent 5596caf commit 52a0a4b

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

opencensus/context/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OpenCensus C++ Context library.
2+
3+
Context is an object that holds information that is specific to an operation
4+
such as an RPC.
5+
6+
Please refer to the [context documentation](../doc/context.md) for an
7+
explanation of how it's used.

opencensus/stats/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Stats API
22

3-
The primary stats API documentation is in the headers in `opencensus/stats`.
3+
The primary stats API documentation is in the headers in this directory.
4+
5+
There is also a stats [tutorial](https://opencensus.io/quickstart/cpp/metrics/)
6+
on the OpenCensus webpage.
7+
48
See the following classes and headers for the top-level interfaces:
59

610
### Recording data
7-
- A [`Measure`](measure.h) specifyies the resources against which data is
11+
- A [`Measure`](measure.h) specifies the resources against which data is
812
recorded.
913
- [`recording.h`](recording.h) defines the recording function.
1014

opencensus/tags/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# OpenCensus C++ Tags library.
2+
3+
This directory tree contains the C++ API and implementation of OpenCensus
4+
tagging.
5+
6+
Please refer to the [tags documentation](https://opencensus.io/tag/) on the
7+
OpenCensus website.
8+
9+
## API overview
10+
11+
`TagMap` is an immutable map of `TagKey`s to tag values (strings).
12+
13+
`TagKey` is a lightweight, immutable representation of a tag key (string).

opencensus/trace/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
This directory tree contains the C++ API and implementation of OpenCensus
44
tracing.
55

6-
The main entry point to tracing is the `span.h` file.
6+
The main entry point to tracing is the [`span.h`](span.h) file.
7+
It's a relatively short file and the comments are a reference guide
8+
to the tracing API.
79

810
For a quick use guide, look at the `examples/` directory.
911

12+
Also see the tracing
13+
[tutorial](https://opencensus.io/quickstart/cpp/tracing/) on the OpenCensus
14+
website.
15+
1016
## Directory structure
1117

1218
* `./` - headers that are the public API for tracing.
@@ -17,9 +23,12 @@ in-process storage.
1723
* `internal/` - internal implementation details and tests. Do not include or
1824
rely on headers from this directory!
1925

26+
* `propagation/` - headers that are the public API for trace propagation, using
27+
different encodings.
28+
2029
## API overview
2130

22-
`span.h` defines the central unit of tracing: Traces are made of Spans.
31+
`Span` is the central unit of tracing: Traces are made of Spans.
2332

2433
`TraceId` is an opaque token that uniquely identifies a trace.
2534

@@ -32,7 +41,7 @@ rely on headers from this directory!
3241
`TraceConfig` is a global that holds `TraceParams`.
3342

3443
`TraceParams` configures the maximum number of Annotations, Attributes,
35-
MessageEvents, and Links, as well as the sampler.
44+
MessageEvents, and Links, as well as the currently active `Sampler`.
3645

3746
---
3847

opencensus/trace/span.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,23 @@ struct StartSpanOptions {
6969
const std::vector<Span*> parent_links;
7070
};
7171

72-
// Span represents a sub-operation in a larger Trace.
72+
// Span represents an operation. A Trace consists of one or more Spans.
7373
//
74-
// A Span is uniquely identified by a SpanContext. The Span object is just a
75-
// handle to add Annotations and Attributes in an implementation-defined data
76-
// structure, hence all these operations are marked const. The Span must be
77-
// explicitly End()ed when the suboperation is complete. Span is thread-safe.
74+
// A Span is uniquely identified by a SpanContext.
75+
//
76+
// A Span must be explicitly End()ed when the operation is complete.
77+
//
78+
// The Span object is just a handle to e.g. add Annotations in an
79+
// implementation-defined data structure, hence all operations on it are marked
80+
// const.
81+
//
82+
// Span is thread-compatible. If swap() and operator= are avoided, everything
83+
// else is thread-safe. Avoid mutating Span objects in-place; treat them like
84+
// read-only handles. When using multiple threads, give each thread a copy of
85+
// the Span.
86+
//
87+
// As an alternative to explicitly passing Span objects between functions,
88+
// consider using Context. (see the ../context/ directory).
7889
class Span final {
7990
public:
8091
// Constructs a no-op Span with an invalid context. Attempts to add
@@ -170,12 +181,13 @@ class Span final {
170181
friend void swap(Span& a, Span& b);
171182

172183
// Spans that aren't sampled still have a valid SpanContext that propagates,
173-
// but no span_impl_.
184+
// but no span_impl_. The SpanContext should be treated as read-only but we
185+
// can't mark it const because we need to swap() Spans.
174186
SpanContext context_;
175187

176188
// Shared pointer to the underlying Span representation. This is nullptr for
177189
// Spans which are not recording events. This is an implementation detail, not
178-
// part of the public API.
190+
// part of the public API. We don't mark it const so that we can swap() Spans.
179191
std::shared_ptr<SpanImpl> span_impl_;
180192

181193
friend class ::opencensus::context::Context;

0 commit comments

Comments
 (0)