userver: userver/tracing/tag_scope.hpp Source File
Loading...
Searching...
No Matches
tag_scope.hpp
1#pragma once
2
3/// @file userver/tracing/scope_tag.hpp
4/// @brief @copybrief tracing::TagScope
5
6#include <string>
7
8#include <userver/logging/log_extra.hpp>
9#include <userver/tracing/span.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace tracing {
14
15/// @brief RAII object that calls Span::AddTag/Span::AddTagFrozen function
16/// in constructor and reverts these actions in destructor.
17///
18/// ## Example usage:
19/// @snippet tracing/tag_scope_test.cpp TagScope - sample
20class TagScope {
21public:
22 explicit TagScope(
23 std::string key,
24 logging::LogExtra::Value value,
25 logging::LogExtra::ExtendType extend_type = logging::LogExtra::ExtendType::kNormal
26 );
27
28 explicit TagScope(
29 Span& parent,
30 std::string key,
31 logging::LogExtra::Value value,
32 logging::LogExtra::ExtendType extend_type = logging::LogExtra::ExtendType::kNormal
33 );
34
35 explicit TagScope(logging::LogExtra&& extra);
36
37 explicit TagScope(Span& parent, logging::LogExtra&& extra);
38
39 ~TagScope();
40
41 TagScope(const TagScope& other) = delete;
42 TagScope& operator=(const TagScope& other) = delete;
43
44 TagScope(TagScope&& other) = delete;
45 TagScope& operator=(TagScope&& other) = delete;
46
47private:
48 void AddTag(std::string&& key, logging::LogExtra::ProtectedValue&& value);
49
50 static constexpr std::size_t kNewKeysVectorSize = 8;
51
52 Span& parent_;
53 std::size_t new_tags_begin_index_;
54 std::size_t new_tags_end_index_;
55 std::vector<std::pair<std::size_t, logging::LogExtra::ProtectedValue>> previous_values_;
56};
57
58} // namespace tracing
59
60USERVER_NAMESPACE_END