/proc/self/cwd/opencensus/trace/span_id.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_ID_H_ |
16 | | #define OPENCENSUS_TRACE_SPAN_ID_H_ |
17 | | |
18 | | #include <cstdint> |
19 | | #include <string> |
20 | | |
21 | | namespace opencensus { |
22 | | namespace trace { |
23 | | |
24 | | // SpanId represents an opaque 64-bit span identifier that uniquely identifies a |
25 | | // span within a trace. SpanId is immutable. |
26 | | class SpanId final { |
27 | | public: |
28 | | // The size in bytes of the SpanId. |
29 | | static constexpr size_t kSize = 8; |
30 | | |
31 | | // An invalid SpanId (all zeros). |
32 | 60 | SpanId() : rep_{0} {} |
33 | | |
34 | | // Creates a SpanId by copying the first kSize bytes from the buffer. |
35 | | explicit SpanId(const uint8_t* buf); |
36 | | |
37 | | // Returns a 16-char hex string of the SpanId value. |
38 | | std::string ToHex() const; |
39 | | |
40 | | // Returns a pointer to the opaque value. |
41 | | const void* Value() const; |
42 | | |
43 | | bool operator==(const SpanId& that) const; |
44 | | |
45 | | // Returns false if the SpanId is all zeros. |
46 | | bool IsValid() const; |
47 | | |
48 | | // Copies the opaque SpanId data to a buffer, which must hold kSize bytes. |
49 | | void CopyTo(uint8_t* buf) const; |
50 | | |
51 | | private: |
52 | | uint8_t rep_[kSize]; |
53 | | }; |
54 | | |
55 | | } // namespace trace |
56 | | } // namespace opencensus |
57 | | |
58 | | #endif // OPENCENSUS_TRACE_SPAN_ID_H_ |