Skip to content

Commit 34de484

Browse files
authored
Merge branch 'main' into cmake-config-find-dependencies
2 parents 6252f46 + 7402ed9 commit 34de484

File tree

14 files changed

+200
-47
lines changed

14 files changed

+200
-47
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF)
287287
option(WITH_METRICS_EXEMPLAR_PREVIEW
288288
"Whether to enable exemplar within metrics" OFF)
289289

290+
option(OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS
291+
"Whether to build test libraries that are always linked as shared libs"
292+
OFF)
293+
290294
#
291295
# Verify options dependencies
292296
#

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module(
55
name = "opentelemetry-cpp",
6-
version = "1.16.1",
6+
version = "1.17.0",
77
compatibility_level = 0,
88
repo_name = "io_opentelemetry_cpp",
99
)

api/test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ add_subdirectory(metrics)
1010
add_subdirectory(logs)
1111
add_subdirectory(common)
1212
add_subdirectory(baggage)
13-
add_subdirectory(singleton)
13+
14+
if(NOT OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS)
15+
add_subdirectory(singleton)
16+
endif()

examples/plugin/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
add_subdirectory(load)
5-
add_subdirectory(plugin)
5+
6+
if(NOT OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS)
7+
add_subdirectory(plugin)
8+
endif()

exporters/memory/src/in_memory_metric_data.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void SimpleAggregateInMemoryMetricData::Add(std::unique_ptr<ResourceMetrics> res
3131
const auto &metric = m.instrument_descriptor.name_;
3232
for (const auto &pda : m.point_data_attr_)
3333
{
34-
data_[{scope, metric}].insert({pda.attributes, pda.point_data});
34+
// NOTE: Explicit type conversion added for C++11 (gcc 4.8)
35+
data_[std::tuple<std::string, std::string>{scope, metric}].insert(
36+
{pda.attributes, pda.point_data});
3537
}
3638
}
3739
}
@@ -41,7 +43,8 @@ const SimpleAggregateInMemoryMetricData::AttributeToPoint &SimpleAggregateInMemo
4143
const std::string &scope,
4244
const std::string &metric)
4345
{
44-
return data_[{scope, metric}];
46+
// NOTE: Explicit type conversion added for C++11 (gcc 4.8)
47+
return data_[std::tuple<std::string, std::string>{scope, metric}];
4548
}
4649

4750
void SimpleAggregateInMemoryMetricData::Clear()

exporters/memory/src/in_memory_metric_exporter_factory.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter
4949
OTEL_INTERNAL_LOG_ERROR("[In Memory Metric Exporter] Exporting failed, exporter is shutdown");
5050
return ExportResult::kFailure;
5151
}
52-
data_->Add(std::make_unique<ResourceMetrics>(data));
52+
data_->Add(std::unique_ptr<ResourceMetrics>(new ResourceMetrics{data}));
5353
return ExportResult::kSuccess;
5454
}
5555

@@ -78,14 +78,15 @@ class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter
7878
std::unique_ptr<PushMetricExporter> InMemoryMetricExporterFactory::Create(
7979
const std::shared_ptr<InMemoryMetricData> &data)
8080
{
81-
return Create(data, [](auto) { return AggregationTemporality::kCumulative; });
81+
return Create(data,
82+
[](sdk::metrics::InstrumentType) { return AggregationTemporality::kCumulative; });
8283
}
8384

8485
std::unique_ptr<PushMetricExporter> InMemoryMetricExporterFactory::Create(
8586
const std::shared_ptr<InMemoryMetricData> &data,
8687
const AggregationTemporalitySelector &temporality)
8788
{
88-
return std::make_unique<InMemoryMetricExporter>(data, temporality);
89+
return std::unique_ptr<InMemoryMetricExporter>(new InMemoryMetricExporter{data, temporality});
8990
}
9091

9192
} // namespace memory

exporters/memory/test/in_memory_metric_data_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ TEST(InMemoryMetricDataTest, CircularBuffer)
2323
{
2424
CircularBufferInMemoryMetricData buf(10);
2525
Resource resource = Resource::GetEmpty();
26-
buf.Add(std::make_unique<ResourceMetrics>(
27-
&resource, std::vector<ScopeMetrics>{{nullptr, std::vector<MetricData>{}}}));
26+
buf.Add(std::unique_ptr<ResourceMetrics>(new ResourceMetrics{
27+
&resource, std::vector<ScopeMetrics>{{nullptr, std::vector<MetricData>{}}}}));
2828
EXPECT_EQ((*buf.Get().begin())->resource_, &resource);
2929
}
3030

@@ -45,8 +45,8 @@ TEST(InMemoryMetricDataTest, SimpleAggregate)
4545
md.instrument_descriptor.name_ = "my-metric";
4646
md.point_data_attr_.push_back(pda);
4747

48-
agg.Add(std::make_unique<ResourceMetrics>(
49-
&resource, std::vector<ScopeMetrics>{{scope.get(), std::vector<MetricData>{md}}}));
48+
agg.Add(std::unique_ptr<ResourceMetrics>(new ResourceMetrics{
49+
&resource, std::vector<ScopeMetrics>{{scope.get(), std::vector<MetricData>{md}}}}));
5050
auto it = agg.Get("my-scope", "my-metric").begin();
5151

5252
auto saved_point = opentelemetry::nostd::get<SumPointData>(it->second);

exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_options.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ struct PrometheusExporterOptions
2828

2929
// Populating otel_scope_name/otel_scope_labels attributes
3030
bool without_otel_scope = false;
31+
32+
// Option to export metrics without the unit suffix
33+
bool without_units = false;
34+
35+
// Option to export metrics without the type suffix
36+
bool without_type_suffix = false;
3137
};
3238

3339
} // namespace metrics

exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter_utils.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ class PrometheusExporterUtils
3030
* @param populate_target_info whether to populate target_info
3131
* @param without_otel_scope whether to populate otel_scope_name and otel_scope_version
3232
* attributes
33+
* @param without_units exporter configuration controlling whether to append unit suffix in
34+
* the exported metrics.
35+
* @param without_type_suffix exporter configuration controlling whether to append type suffix in
36+
* the exported metrics.
3337
* @return a collection of translated metrics that is acceptable by Prometheus
3438
*/
3539
static std::vector<::prometheus::MetricFamily> TranslateToPrometheus(
3640
const sdk::metrics::ResourceMetrics &data,
3741
bool populate_target_info = true,
38-
bool without_otel_scope = false);
42+
bool without_otel_scope = false,
43+
bool without_units = false,
44+
bool without_type_suffix = false);
3945

4046
private:
4147
/**
@@ -61,7 +67,9 @@ class PrometheusExporterUtils
6167

6268
static std::string MapToPrometheusName(const std::string &name,
6369
const std::string &unit,
64-
::prometheus::MetricType prometheus_type);
70+
::prometheus::MetricType prometheus_type,
71+
bool without_units,
72+
bool without_type_suffix);
6573

6674
/**
6775
* A utility function that returns the equivalent Prometheus name for the provided OTLP metric

exporters/prometheus/src/exporter_options.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,33 @@ inline bool GetPrometheusPopulateTargetInfo()
4848
return exists ? setting : true;
4949
}
5050

51+
inline bool GetPrometheusWithoutUnits()
52+
{
53+
constexpr char kPrometheusWithoutUnits[] = "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_UNITS";
54+
bool setting;
55+
const auto exists =
56+
opentelemetry::sdk::common::GetBoolEnvironmentVariable(kPrometheusWithoutUnits, setting);
57+
58+
return exists ? setting : false;
59+
}
60+
61+
inline bool GetPrometheusWithoutTypeSuffix()
62+
{
63+
constexpr char kPrometheusWithoutTypeSuffix[] =
64+
"OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_TYPE_SUFFIX";
65+
bool setting;
66+
const auto exists =
67+
opentelemetry::sdk::common::GetBoolEnvironmentVariable(kPrometheusWithoutTypeSuffix, setting);
68+
69+
return exists ? setting : false;
70+
}
71+
5172
PrometheusExporterOptions::PrometheusExporterOptions()
5273
: url(GetPrometheusDefaultHttpEndpoint()),
5374
populate_target_info(GetPrometheusPopulateTargetInfo()),
54-
without_otel_scope(GetPrometheusWithoutOtelScope())
75+
without_otel_scope(GetPrometheusWithoutOtelScope()),
76+
without_units(GetPrometheusWithoutUnits()),
77+
without_type_suffix(GetPrometheusWithoutTypeSuffix())
5578
{}
5679

5780
} // namespace metrics

0 commit comments

Comments
 (0)