/proc/self/cwd/opencensus/trace/span_context.h
Line | Count | Source |
1 | | // Copyright 2017, OpenCensus Authors |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef OPENCENSUS_TRACE_SPAN_CONTEXT_H_ |
16 | | #define OPENCENSUS_TRACE_SPAN_CONTEXT_H_ |
17 | | |
18 | | #include <cstdint> |
19 | | #include <string> |
20 | | |
21 | | #include "opencensus/trace/span_id.h" |
22 | | #include "opencensus/trace/trace_id.h" |
23 | | #include "opencensus/trace/trace_options.h" |
24 | | |
25 | | namespace opencensus { |
26 | | namespace trace { |
27 | | |
28 | | // SpanContext contains the state that must propagate to child spans and across |
29 | | // process boundaries. It contains the TraceId and SpanId associated with the |
30 | | // span and a set of TraceOptions. SpanContext is immutable. |
31 | | class SpanContext final { |
32 | | public: |
33 | | // Blank SpanContext: TraceId, SpanId, and TraceOptions are 0. |
34 | 60 | SpanContext() {} |
35 | | |
36 | | // SpanContext is copyable and movable. |
37 | | SpanContext(const SpanContext&) = default; |
38 | | SpanContext(SpanContext&&) = default; |
39 | | SpanContext& operator=(const SpanContext&) = default; |
40 | | SpanContext& operator=(SpanContext&&) = default; |
41 | | |
42 | | SpanContext(TraceId trace_id, SpanId span_id, |
43 | | TraceOptions trace_options = TraceOptions()) |
44 | 1.08k | : trace_id_(trace_id), span_id_(span_id), trace_options_(trace_options) {} |
45 | | |
46 | | // Returns the TraceId associated with this SpanContext. |
47 | 860 | TraceId trace_id() const { return trace_id_; } |
48 | | |
49 | | // Returns the SpanId associated with this SpanContext. |
50 | 860 | SpanId span_id() const { return span_id_; } |
51 | | |
52 | | // Returns the TraceOptions associated with this SpanContext. |
53 | 860 | TraceOptions trace_options() const { return trace_options_; } |
54 | | |
55 | | // Compares two SpanContexts for equality. Only compares TraceId and SpanId, |
56 | | // not TraceOptions! |
57 | | bool operator==(const SpanContext& that) const; |
58 | | |
59 | | // Compares two SpanContexts for inequality. Only compares TraceId and SpanId, |
60 | | // not TraceOptions! |
61 | | bool operator!=(const SpanContext& that) const; |
62 | | |
63 | | // Returns true if SpanId and TraceId are valid. |
64 | | bool IsValid() const; |
65 | | |
66 | | // Returns hex strings separated with hyphens, e.g. "trace_id-span_id-options" |
67 | | std::string ToString() const; |
68 | | |
69 | | private: |
70 | | TraceId trace_id_; |
71 | | SpanId span_id_; |
72 | | TraceOptions trace_options_; |
73 | | }; |
74 | | |
75 | | } // namespace trace |
76 | | } // namespace opencensus |
77 | | |
78 | | #endif // OPENCENSUS_TRACE_SPAN_CONTEXT_H_ |