@@ -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).
7889class 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