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 struct DetachedTag {};
21
22 explicit InPlaceSpan(
23 std::string&& name,
24 const utils::impl::SourceLocation& source_location = utils::impl::SourceLocation::Current()
25 );
26
27 explicit InPlaceSpan(
28 std::string&& name,
29 std::string_view trace_id,
30 std::string_view parent_span_id,
31 const utils::impl::SourceLocation& source_location = utils::impl::SourceLocation::Current()
32 );
33
34 explicit InPlaceSpan(
35 std::string&& name,
37 const utils::impl::SourceLocation& source_location = utils::impl::SourceLocation::Current()
38 );
39
40 InPlaceSpan(InPlaceSpan&&) = delete;
41 InPlaceSpan& operator=(InPlaceSpan&&) = delete;
42 ~InPlaceSpan();
43
44 const tracing::Span& Get() const noexcept;
45
46 tracing::Span& Get() noexcept;
47
48private:
49 struct Impl;
50 utils::FastPimpl<Impl, 4392, 8> impl_;
51};
52
53} // namespace tracing
54
55USERVER_NAMESPACE_END