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 {
21 public:
22 explicit TagScope(std::string key, logging::LogExtra::Value value,
23 logging::LogExtra::ExtendType extend_type =
25
26 explicit TagScope(Span& parent, std::string key,
27 logging::LogExtra::Value value,
28 logging::LogExtra::ExtendType extend_type =
30
31 explicit TagScope(logging::LogExtra&& extra);
32
33 explicit TagScope(Span& parent, logging::LogExtra&& extra);
34
35 ~TagScope();
36
37 TagScope(const TagScope& other) = delete;
38 TagScope& operator=(const TagScope& other) = delete;
39
40 TagScope(TagScope&& other) = delete;
41 TagScope& operator=(TagScope&& other) = delete;
42
43 private:
44 void AddTag(std::string&& key, logging::LogExtra::ProtectedValue&& value);
45
46 static constexpr std::size_t kNewKeysVectorSize = 8;
47
48 Span& parent_;
49 std::size_t new_tags_begin_index_;
50 std::size_t new_tags_end_index_;
51 std::vector<std::pair<std::size_t, logging::LogExtra::ProtectedValue>>
52 previous_values_;
53};
54
55} // namespace tracing
56
57USERVER_NAMESPACE_END