|
4 | 4 | #pragma once |
5 | 5 |
|
6 | 6 | #include "opentelemetry/common/attribute_value.h" |
| 7 | +#include "opentelemetry/sdk/common/attribute_utils.h" |
7 | 8 | #include "opentelemetry/exporters/fluentd/common/fluentd_logging.h" |
8 | 9 | #include "opentelemetry/nostd/string_view.h" |
9 | 10 | #include "opentelemetry/version.h" |
@@ -99,6 +100,93 @@ void inline PopulateAttribute( |
99 | 100 | } |
100 | 101 | } |
101 | 102 |
|
| 103 | +void inline PopulateOwnedAttribute( |
| 104 | + nlohmann::json &attribute, nostd::string_view key, |
| 105 | + const opentelemetry::sdk::common::OwnedAttributeValue &value) { |
| 106 | + // Assert size of variant to ensure that this method gets updated if the |
| 107 | + // variant definition changes |
| 108 | + static_assert( |
| 109 | + nostd::variant_size<opentelemetry::common::AttributeValue>::value == |
| 110 | + kAttributeValueSize + 1, |
| 111 | + "AttributeValue contains unknown type"); |
| 112 | + |
| 113 | + namespace common = opentelemetry::sdk::common; |
| 114 | + switch(value.index()) { |
| 115 | + case common::kTypeBool: |
| 116 | + attribute[key.data()] = nostd::get<bool>(value); |
| 117 | + break; |
| 118 | + case common::kTypeInt: |
| 119 | + attribute[key.data()] = nostd::get<int>(value); |
| 120 | + break; |
| 121 | + case common::kTypeUInt: |
| 122 | + attribute[key.data()] = nostd::get<unsigned int>(value); |
| 123 | + break; |
| 124 | + case common::kTypeInt64: |
| 125 | + attribute[key.data()] = nostd::get<int64_t>(value); |
| 126 | + break; |
| 127 | + case common::kTypeDouble: |
| 128 | + attribute[key.data()] = nostd::get<double>(value); |
| 129 | + break; |
| 130 | + case common::kTypeString: |
| 131 | + attribute[key.data()] = nostd::get<std::string>(value); |
| 132 | + break; |
| 133 | + case common::kTypeSpanBool: |
| 134 | + attribute[key.data()] = {}; |
| 135 | + for (const auto &val : nostd::get<std::vector<bool>>(value)) { |
| 136 | + attribute[key.data()].push_back(val); |
| 137 | + } |
| 138 | + break; |
| 139 | + case common::kTypeSpanInt: |
| 140 | + attribute[key.data()] = {}; |
| 141 | + for (const auto &val : nostd::get<std::vector<int>>(value)) { |
| 142 | + attribute[key.data()].push_back(val); |
| 143 | + } |
| 144 | + break; |
| 145 | + case common::kTypeSpanUInt: |
| 146 | + attribute[key.data()] = {}; |
| 147 | + for (const auto &val : nostd::get<std::vector<unsigned int>>(value)) { |
| 148 | + attribute[key.data()].push_back(val); |
| 149 | + } |
| 150 | + break; |
| 151 | + case common::kTypeSpanInt64: |
| 152 | + attribute[key.data()] = {}; |
| 153 | + for (const auto &val : nostd::get<std::vector<int64_t>>(value)) { |
| 154 | + attribute[key.data()].push_back(val); |
| 155 | + } |
| 156 | + break; |
| 157 | + case common::kTypeSpanDouble: |
| 158 | + attribute[key.data()] = {}; |
| 159 | + for (const auto &val : nostd::get<std::vector<double>>(value)) { |
| 160 | + attribute[key.data()].push_back(val); |
| 161 | + } |
| 162 | + break; |
| 163 | + case common::kTypeSpanString: |
| 164 | + attribute[key.data()] = {}; |
| 165 | + for (const auto &val : |
| 166 | + nostd::get<std::vector<std::string>>(value)) { |
| 167 | + attribute[key.data()].push_back(val); |
| 168 | + } |
| 169 | + break; |
| 170 | + case common::kTypeUInt64: |
| 171 | + attribute[key.data()] = nostd::get<uint64_t>(value); |
| 172 | + break; |
| 173 | + case common::kTypeSpanUInt64: |
| 174 | + attribute[key.data()] = {}; |
| 175 | + for (const auto &val : nostd::get<std::vector<uint64_t>>(value)) { |
| 176 | + attribute[key.data()].push_back(val); |
| 177 | + } |
| 178 | + break; |
| 179 | + case common::kTypeSpanByte: |
| 180 | + attribute[key.data()] = {}; |
| 181 | + for (const auto &val : nostd::get<std::vector<uint8_t>>(value)) { |
| 182 | + attribute[key.data()].push_back(val); |
| 183 | + } |
| 184 | + break; |
| 185 | + default: |
| 186 | + break; |
| 187 | + } |
| 188 | +} |
| 189 | + |
102 | 190 | inline std::string AttributeValueToString( |
103 | 191 | const opentelemetry::common::AttributeValue &value) { |
104 | 192 | std::string result; |
|
0 commit comments