1 // Copyright 2019 Google LLC 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 FCP_TRACING_TRACING_RECORDER_H_ 16 #define FCP_TRACING_TRACING_RECORDER_H_ 17 18 #include "fcp/tracing/tracing_span.h" 19 namespace fcp { 20 21 // Interface to be implemented by tracing recorders, which are responsible 22 // for implementation behind the TracingSpan API. 23 // A tracing recorder provides ability to create root span. 24 class TracingRecorder { 25 public: 26 // TracingRecorder is neither copyable nor movable. 27 TracingRecorder(const TracingRecorder&) = delete; 28 TracingRecorder& operator=(const TracingRecorder&) = delete; 29 30 TracingRecorder() = default; 31 32 // It is OK to destruct this facade API object anytime, since underlying 33 // implementation lifetime is independent from the facade and automatically 34 // prolonged by active tracing span (in this or other threads) 35 virtual ~TracingRecorder() = default; 36 37 // Installs tracing recorder as global instance. 38 // It uninstalls automatically upon destruction of underlying implementation. 39 // Only one instance can be installed and this operation will fail if other 40 // recorder is installed as global. 41 virtual void InstallAsGlobal() = 0; 42 43 // Uninstalls tracing recorder as global instance. Allowed to be called only 44 // if InstallAsGlobal() was called. 45 // NOTE: if some concurrent threads have active tracing spans on their stacks, 46 // they can continue tracing with the tracing recorder even after uninstalling 47 // it as global. 48 virtual void UninstallAsGlobal() = 0; 49 50 // Installs tracing recorder as thread local instance. 51 // Only one instance can be installed per thread, and this operation will fail 52 // if other recorder is installed for the current thread. 53 virtual void InstallAsThreadLocal() = 0; 54 55 // Uninstalls tracing recorder as thread local instance. Allowed to be called 56 // only if InstallAsThreadLocal has been called. 57 virtual void UninstallAsThreadLocal() = 0; 58 }; 59 60 } // namespace fcp 61 62 #endif // FCP_TRACING_TRACING_RECORDER_H_ 63