xref: /aosp_15_r20/external/federated-compute/fcp/tracing/tracing_span_ref.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1*14675a02SAndroid Build Coastguard Worker // Copyright 2019 Google LLC
2*14675a02SAndroid Build Coastguard Worker //
3*14675a02SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*14675a02SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*14675a02SAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*14675a02SAndroid Build Coastguard Worker //
7*14675a02SAndroid Build Coastguard Worker //      http://www.apache.org/licenses/LICENSE-2.0
8*14675a02SAndroid Build Coastguard Worker //
9*14675a02SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*14675a02SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*14675a02SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*14675a02SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*14675a02SAndroid Build Coastguard Worker // limitations under the License.
14*14675a02SAndroid Build Coastguard Worker 
15*14675a02SAndroid Build Coastguard Worker #ifndef FCP_TRACING_TRACING_SPAN_REF_H_
16*14675a02SAndroid Build Coastguard Worker #define FCP_TRACING_TRACING_SPAN_REF_H_
17*14675a02SAndroid Build Coastguard Worker 
18*14675a02SAndroid Build Coastguard Worker #include <memory>
19*14675a02SAndroid Build Coastguard Worker #include <utility>
20*14675a02SAndroid Build Coastguard Worker 
21*14675a02SAndroid Build Coastguard Worker #include "fcp/tracing/tracing_span_id.h"
22*14675a02SAndroid Build Coastguard Worker 
23*14675a02SAndroid Build Coastguard Worker namespace fcp {
24*14675a02SAndroid Build Coastguard Worker 
25*14675a02SAndroid Build Coastguard Worker namespace tracing_internal {
26*14675a02SAndroid Build Coastguard Worker class TracingRecorderImpl;
27*14675a02SAndroid Build Coastguard Worker }
28*14675a02SAndroid Build Coastguard Worker 
29*14675a02SAndroid Build Coastguard Worker // Reference to a tracing span.
30*14675a02SAndroid Build Coastguard Worker class TracingSpanRef {
31*14675a02SAndroid Build Coastguard Worker   // Reference to the tracing recorder this reference was issued by:
32*14675a02SAndroid Build Coastguard Worker   std::shared_ptr<fcp::tracing_internal::TracingRecorderImpl> recorder_;
33*14675a02SAndroid Build Coastguard Worker   // Identifier of the span
34*14675a02SAndroid Build Coastguard Worker   TracingSpanId span_id_;
35*14675a02SAndroid Build Coastguard Worker 
36*14675a02SAndroid Build Coastguard Worker  public:
TracingSpanRef(std::shared_ptr<fcp::tracing_internal::TracingRecorderImpl> provider,TracingSpanId span_id)37*14675a02SAndroid Build Coastguard Worker   TracingSpanRef(
38*14675a02SAndroid Build Coastguard Worker       std::shared_ptr<fcp::tracing_internal::TracingRecorderImpl> provider,
39*14675a02SAndroid Build Coastguard Worker       TracingSpanId span_id)
40*14675a02SAndroid Build Coastguard Worker       : recorder_(std::move(provider)), span_id_(span_id) {}
41*14675a02SAndroid Build Coastguard Worker 
recorder()42*14675a02SAndroid Build Coastguard Worker   std::shared_ptr<tracing_internal::TracingRecorderImpl> recorder() {
43*14675a02SAndroid Build Coastguard Worker     return recorder_;
44*14675a02SAndroid Build Coastguard Worker   }
45*14675a02SAndroid Build Coastguard Worker 
span_id()46*14675a02SAndroid Build Coastguard Worker   TracingSpanId span_id() const { return span_id_; }
47*14675a02SAndroid Build Coastguard Worker 
48*14675a02SAndroid Build Coastguard Worker   // Returns reference to the top tracing span on the current
49*14675a02SAndroid Build Coastguard Worker   // thread/fiber. If there's no tracing span established, a
50*14675a02SAndroid Build Coastguard Worker   // reference to the root span of global tracing recorder is returned.
51*14675a02SAndroid Build Coastguard Worker   static TracingSpanRef Top();
52*14675a02SAndroid Build Coastguard Worker };
53*14675a02SAndroid Build Coastguard Worker 
54*14675a02SAndroid Build Coastguard Worker }  // namespace fcp
55*14675a02SAndroid Build Coastguard Worker #endif  // FCP_TRACING_TRACING_SPAN_REF_H_
56