Skip to content

Commit 4559186

Browse files
committed
Code cleanup
1 parent e27bbf1 commit 4559186

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

sdk/src/configuration/configured_sdk.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <utility>
88

99
#include "opentelemetry/context/propagation/global_propagator.h"
10+
#include "opentelemetry/context/propagation/text_map_propagator.h"
1011
#include "opentelemetry/logs/logger_provider.h"
1112
#include "opentelemetry/logs/provider.h"
1213
#include "opentelemetry/metrics/meter_provider.h"

sdk/src/configuration/sdk_builder.cc

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#include <stddef.h>
45
#include <stdint.h>
56
#include <chrono>
67
#include <map>
@@ -11,9 +12,11 @@
1112
#include <vector>
1213

1314
#include "opentelemetry/common/attribute_value.h"
15+
#include "opentelemetry/common/kv_properties.h"
1416
#include "opentelemetry/context/propagation/composite_propagator.h"
1517
#include "opentelemetry/context/propagation/text_map_propagator.h"
1618
#include "opentelemetry/nostd/span.h"
19+
#include "opentelemetry/nostd/string_view.h"
1720
#include "opentelemetry/sdk/common/global_log_handler.h"
1821
#include "opentelemetry/sdk/configuration/aggregation_configuration.h"
1922
#include "opentelemetry/sdk/configuration/aggregation_configuration_visitor.h"
@@ -159,20 +162,20 @@ namespace sdk
159162
namespace configuration
160163
{
161164

162-
class AttributeValueSetter
165+
class ResourceAttributeValueSetter
163166
: public opentelemetry::sdk::configuration::AttributeValueConfigurationVisitor
164167
{
165168
public:
166-
AttributeValueSetter(const SdkBuilder *b,
167-
opentelemetry::sdk::resource::ResourceAttributes &resource_attributes,
168-
const std::string &name)
169-
: m_sdk_builder(b), resource_attributes_(resource_attributes), name_(name)
169+
ResourceAttributeValueSetter(
170+
opentelemetry::sdk::resource::ResourceAttributes &resource_attributes,
171+
const std::string &name)
172+
: resource_attributes_(resource_attributes), name_(name)
170173
{}
171-
AttributeValueSetter(AttributeValueSetter &&) = delete;
172-
AttributeValueSetter(const AttributeValueSetter &) = delete;
173-
AttributeValueSetter &operator=(AttributeValueSetter &&) = delete;
174-
AttributeValueSetter &operator=(const AttributeValueSetter &other) = delete;
175-
~AttributeValueSetter() override = default;
174+
ResourceAttributeValueSetter(ResourceAttributeValueSetter &&) = delete;
175+
ResourceAttributeValueSetter(const ResourceAttributeValueSetter &) = delete;
176+
ResourceAttributeValueSetter &operator=(ResourceAttributeValueSetter &&) = delete;
177+
ResourceAttributeValueSetter &operator=(const ResourceAttributeValueSetter &other) = delete;
178+
~ResourceAttributeValueSetter() override = default;
176179

177180
void VisitString(
178181
const opentelemetry::sdk::configuration::StringAttributeValueConfiguration *model) override
@@ -209,7 +212,10 @@ class AttributeValueSetter
209212
size_t length = model->value.size();
210213
std::vector<nostd::string_view> string_view_array(length);
211214

212-
for (int i = 0; i < length; i++)
215+
// We have: std::vector<std::string>
216+
// We need: nostd::span<const nostd::string_view>
217+
218+
for (size_t i = 0; i < length; i++)
213219
{
214220
string_view_array[i] = model->value[i];
215221
}
@@ -227,7 +233,10 @@ class AttributeValueSetter
227233
size_t length = model->value.size();
228234
std::vector<int64_t> int_array(length);
229235

230-
for (int i = 0; i < length; i++)
236+
// We have: std::vector<size_t>
237+
// We need: nostd::span<const int64_t>
238+
239+
for (size_t i = 0; i < length; i++)
231240
{
232241
int_array[i] = model->value[i];
233242
}
@@ -242,15 +251,11 @@ class AttributeValueSetter
242251
const opentelemetry::sdk::configuration::DoubleArrayAttributeValueConfiguration *model)
243252
override
244253
{
245-
size_t length = model->value.size();
246-
std::vector<double> double_array(length);
247-
248-
for (int i = 0; i < length; i++)
249-
{
250-
double_array[i] = model->value[i];
251-
}
254+
// We have: std::vector<double>
255+
// We need: nostd::span<const double>
256+
// so no data conversion needed
252257

253-
nostd::span<const double> span(double_array.data(), double_array.size());
258+
nostd::span<const double> span(model->value.data(), model->value.size());
254259

255260
opentelemetry::common::AttributeValue attribute_value(span);
256261
resource_attributes_.SetAttribute(name_, attribute_value);
@@ -266,7 +271,10 @@ class AttributeValueSetter
266271
// it has no data() to convert it to a span
267272
std::unique_ptr<bool[]> bool_array(new bool[length]);
268273

269-
for (int i = 0; i < length; i++)
274+
// We have: std::vector<bool>
275+
// We need: nostd::span<const bool>
276+
277+
for (size_t i = 0; i < length; i++)
270278
{
271279
bool_array[i] = model->value[i];
272280
}
@@ -280,7 +288,6 @@ class AttributeValueSetter
280288
opentelemetry::common::AttributeValue attribute_value;
281289

282290
private:
283-
const SdkBuilder *m_sdk_builder;
284291
opentelemetry::sdk::resource::ResourceAttributes &resource_attributes_;
285292
std::string name_;
286293
};
@@ -1642,7 +1649,7 @@ void SdkBuilder::SetResourceAttribute(
16421649
const std::string &name,
16431650
const opentelemetry::sdk::configuration::AttributeValueConfiguration *model) const
16441651
{
1645-
AttributeValueSetter setter(this, resource_attributes, name);
1652+
ResourceAttributeValueSetter setter(resource_attributes, name);
16461653
// Invokes resource_attributes.SetAttribute(name, <proper value from model>)
16471654
model->Accept(&setter);
16481655
}

0 commit comments

Comments
 (0)