userver: userver/tracing/any_value.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
any_value.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/tracing/any_value.hpp
4/// @brief @copybrief tracing::AnyValue
5
6#include <cstdint>
7#include <string>
8#include <variant>
9
10#include <userver/formats/json_fwd.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace tracing {
15
16/// @see
17/// https://github.com/open-telemetry/opentelemetry-proto/blob/v1.3.2/opentelemetry/proto/common/v1/common.proto#L28
18class AnyValue {
19 using Data = std::variant<std::string, bool, std::int64_t, double>;
20
21public:
22 explicit AnyValue(std::string string_value);
23 explicit AnyValue(const char* string_value);
24 explicit AnyValue(bool bool_value);
25 explicit AnyValue(int int_value);
26 explicit AnyValue(long int_value);
27 explicit AnyValue(long long int_value);
28 explicit AnyValue(unsigned int int_value);
29 explicit AnyValue(unsigned long int_value);
30 explicit AnyValue(unsigned long long int_value);
31 explicit AnyValue(float double_value);
32 explicit AnyValue(double double_value);
33
34 /// @cond
35 const Data& GetData() const;
36 /// @endcond
37
38private:
39 Data value_;
40};
41
42AnyValue Parse(const formats::json::Value& value, formats::parse::To<AnyValue>);
43
44void WriteToStream(const AnyValue& any_value, formats::json::StringBuilder& sw);
45
46} // namespace tracing
47
48USERVER_NAMESPACE_END