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 <cstddef>
7#include <string>
8
9#include <userver/compiler/select.hpp>
10#include <userver/tracing/span.hpp>
11#include <userver/utils/fast_pimpl.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace tracing {
16
17/// @brief Avoids an extra allocation by storing tracing::Span data in-place
18/// @warning Never put InPlaceSpan on the stack! It has a large size and can
19/// cause stack overflow.
20class InPlaceSpan final {
21public:
22 struct DetachedTag {};
23
24 explicit InPlaceSpan(
25 std::string&& name,
26 const utils::impl::SourceLocation& source_location = utils::impl::SourceLocation::Current()
27 );
28
29 explicit InPlaceSpan(
30 std::string&& name,
31 std::string_view trace_id,
32 std::string_view parent_span_id,
33 const utils::impl::SourceLocation& source_location = utils::impl::SourceLocation::Current()
34 );
35
36 explicit InPlaceSpan(
37 std::string&& name,
39 const utils::impl::SourceLocation& source_location = utils::impl::SourceLocation::Current()
40 );
41
42 InPlaceSpan(InPlaceSpan&&) = delete;
43 InPlaceSpan& operator=(InPlaceSpan&&) = delete;
44 ~InPlaceSpan();
45
46 const tracing::Span& Get() const noexcept;
47
48 tracing::Span& Get() noexcept;
49
50private:
51 struct Impl;
52
53 static constexpr std::size_t kImplSize = compiler::SelectSize().For64Bit(4584).ForLibCpp64(3760).For32Bit(4632);
54 utils::FastPimpl<Impl, kImplSize, 8> impl_;
55};
56
57} // namespace tracing
58
59USERVER_NAMESPACE_END