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 {
19 public:
20 explicit InPlaceSpan(std::string&& name,
21 utils::impl::SourceLocation source_location =
22 utils::impl::SourceLocation::Current());
23
24 explicit InPlaceSpan(std::string&& name, std::string&& trace_id,
25 std::string&& parent_span_id,
26 utils::impl::SourceLocation source_location =
27 utils::impl::SourceLocation::Current());
28
29 InPlaceSpan(InPlaceSpan&&) = delete;
30 InPlaceSpan& operator=(InPlaceSpan&&) = delete;
31 ~InPlaceSpan();
32
33 tracing::Span& Get() noexcept;
34
35 private:
36 struct Impl;
37 utils::FastPimpl<Impl, 4224, 8> impl_;
38};
39
40} // namespace tracing
41
42USERVER_NAMESPACE_END