/proc/self/cwd/opencensus/trace/trace_options.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_TRACE_OPTIONS_H_ |
16 | | #define OPENCENSUS_TRACE_TRACE_OPTIONS_H_ |
17 | | |
18 | | #include <cstdint> |
19 | | #include <string> |
20 | | |
21 | | namespace opencensus { |
22 | | namespace trace { |
23 | | |
24 | | class SpanGenerator; |
25 | | class SpanTestPeer; |
26 | | |
27 | | // TraceOptions represents the options for a trace. These options are propagated |
28 | | // to all child spans within the given trace. Currently only the IsSampled |
29 | | // option is supported. TraceOptions is thread-compatible. |
30 | | class TraceOptions final { |
31 | | public: |
32 | | // The size in bytes of the TraceOptions. |
33 | | static constexpr size_t kSize = 1; |
34 | | |
35 | | // No options are enabled by default. |
36 | 60 | TraceOptions() : rep_{0} {} |
37 | | |
38 | | // Creates TraceOptions from a buffer of exactly kSize bytes. |
39 | | explicit TraceOptions(const uint8_t* buf); |
40 | | |
41 | | // IsSampled means that the trace should be sampled for exporting outside of |
42 | | // the process, e.g. to Stackdriver/Zipkin. |
43 | | bool IsSampled() const; |
44 | | |
45 | | bool operator==(const TraceOptions& that) const; |
46 | | |
47 | | // Returns a 2-char hex string of the TraceOptions value. |
48 | | std::string ToHex() const; |
49 | | |
50 | | // Copies the TraceOptions data to a buffer, which must hold kSize bytes. |
51 | | void CopyTo(uint8_t* buf) const; |
52 | | |
53 | | // Returns a copy of these TraceOptions with the sampled bit set to |
54 | | // is_sampled. |
55 | | TraceOptions WithSampling(bool is_sampled) const; |
56 | | |
57 | | private: |
58 | | uint8_t rep_[kSize]; |
59 | | }; |
60 | | |
61 | | } // namespace trace |
62 | | } // namespace opencensus |
63 | | |
64 | | #endif // OPENCENSUS_TRACE_TRACE_OPTIONS_H_ |