userver: userver/tracing/in_place_span.hpp Source File
Loading...
Searching...
No Matches
in_place_span.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/tracing/in_place_span.hpp
4/// @brief @copybrief tracing::InPlaceSpan
5
6#include <string>
7
8#include <userver/tracing/span.hpp>
9#include <userver/utils/fast_pimpl.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace tracing {
14
15/// @brief Avoids an extra allocation by storing tracing::Span data in-place
16/// @warning Never put InPlaceSpan on the stack! It has a large size and can
17/// cause stack overflow.
18class InPlaceSpan final {
19public:
20 explicit InPlaceSpan(
21 std::string&& name,
22 utils::impl::SourceLocation source_location = utils::impl::SourceLocation::Current()
23 );
24
25 explicit InPlaceSpan(
26 std::string&& name,
27 std::string&& trace_id,
28 std::string&& parent_span_id,
29 utils::impl::SourceLocation source_location = utils::impl::SourceLocation::Current()
30 );
31
32 InPlaceSpan(InPlaceSpan&&) = delete;
33 InPlaceSpan& operator=(InPlaceSpan&&) = delete;
34 ~InPlaceSpan();
35
36 tracing::Span& Get() noexcept;
37
38private:
39 struct Impl;
40 utils::FastPimpl<Impl, 4224, 8> impl_;
41};
42
43} // namespace tracing
44
45USERVER_NAMESPACE_END