Skip to content

Commit 1de2123

Browse files
authored
Merge branch 'main' into make-get_span-return-static-invalid
2 parents 7ff6178 + f30ab92 commit 1de2123

File tree

40 files changed

+953
-285
lines changed

40 files changed

+953
-285
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/include/opentelemetry/metrics/meter.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class Histogram;
2121
template <typename T>
2222
class UpDownCounter;
2323

24+
template <typename T>
25+
class Gauge;
26+
2427
class ObservableInstrument;
2528

2629
/**
@@ -91,6 +94,27 @@ class Meter
9194
nostd::string_view description = "",
9295
nostd::string_view unit = "") noexcept = 0;
9396

97+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
98+
/**
99+
* Creates a Gauge with the passed characteristics and returns a unique_ptr to that Gauge.
100+
*
101+
* @param name the name of the new Gauge.
102+
* @param description a brief description of what the Gauge is used for.
103+
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
104+
* @return a unique pointer to the created Gauge.
105+
*/
106+
107+
virtual nostd::unique_ptr<Gauge<int64_t>> CreateInt64Gauge(
108+
nostd::string_view name,
109+
nostd::string_view description = "",
110+
nostd::string_view unit = "") noexcept = 0;
111+
112+
virtual nostd::unique_ptr<Gauge<double>> CreateDoubleGauge(
113+
nostd::string_view name,
114+
nostd::string_view description = "",
115+
nostd::string_view unit = "") noexcept = 0;
116+
#endif
117+
94118
/**
95119
* Creates a Asynchronous (Observable) Gauge with the passed characteristics and returns a
96120
* shared_ptr to that Observable Gauge

api/include/opentelemetry/metrics/noop.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ class NoopUpDownCounter : public UpDownCounter<T>
7171
{}
7272
};
7373

74+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
75+
template <class T>
76+
class NoopGauge : public Gauge<T>
77+
{
78+
public:
79+
NoopGauge(nostd::string_view /* name */,
80+
nostd::string_view /* description */,
81+
nostd::string_view /* unit */) noexcept
82+
{}
83+
~NoopGauge() override = default;
84+
void Record(T /* value */) noexcept override {}
85+
void Record(T /* value */, const context::Context & /* context */) noexcept override {}
86+
void Record(T /* value */, const common::KeyValueIterable & /* attributes */) noexcept override {}
87+
void Record(T /* value */,
88+
const common::KeyValueIterable & /* attributes */,
89+
const context::Context & /* context */) noexcept override
90+
{}
91+
};
92+
#endif
93+
7494
class NoopObservableInstrument : public ObservableInstrument
7595
{
7696
public:
@@ -140,6 +160,22 @@ class NoopMeter final : public Meter
140160
return nostd::unique_ptr<Histogram<double>>{new NoopHistogram<double>(name, description, unit)};
141161
}
142162

163+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
164+
nostd::unique_ptr<Gauge<int64_t>> CreateInt64Gauge(nostd::string_view name,
165+
nostd::string_view description = "",
166+
nostd::string_view unit = "") noexcept override
167+
{
168+
return nostd::unique_ptr<Gauge<int64_t>>{new NoopGauge<int64_t>(name, description, unit)};
169+
}
170+
171+
nostd::unique_ptr<Gauge<double>> CreateDoubleGauge(nostd::string_view name,
172+
nostd::string_view description = "",
173+
nostd::string_view unit = "") noexcept override
174+
{
175+
return nostd::unique_ptr<Gauge<double>>{new NoopGauge<double>(name, description, unit)};
176+
}
177+
#endif
178+
143179
nostd::shared_ptr<ObservableInstrument> CreateInt64ObservableGauge(
144180
nostd::string_view name,
145181
nostd::string_view description = "",

api/include/opentelemetry/metrics/sync_instruments.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,82 @@ class UpDownCounter : public SynchronousInstrument
247247
}
248248
};
249249

250+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
251+
/* A Gauge instrument that records values. */
252+
template <class T>
253+
class Gauge : public SynchronousInstrument
254+
{
255+
256+
public:
257+
/**
258+
* Record a value
259+
*
260+
* @param value The measurement value. May be positive, negative or zero.
261+
*/
262+
virtual void Record(T value) noexcept = 0;
263+
264+
/**
265+
* Record a value
266+
*
267+
* @param value The measurement value. May be positive, negative or zero.
268+
* @param context The explicit context to associate with this measurement.
269+
*/
270+
virtual void Record(T value, const context::Context &context) noexcept = 0;
271+
272+
/**
273+
* Record a value with a set of attributes.
274+
*
275+
* @param value The measurement value. May be positive, negative or zero.
276+
* @param attributes A set of attributes to associate with the value.
277+
*/
278+
279+
virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0;
280+
281+
/**
282+
* Record a value with a set of attributes.
283+
*
284+
* @param value The measurement value. May be positive, negative or zero.
285+
* @param attributes A set of attributes to associate with the value.
286+
* @param context The explicit context to associate with this measurement.
287+
*/
288+
virtual void Record(T value,
289+
const common::KeyValueIterable &attributes,
290+
const context::Context &context) noexcept = 0;
291+
292+
template <class U,
293+
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
294+
void Record(T value, const U &attributes) noexcept
295+
{
296+
this->Record(value, common::KeyValueIterableView<U>{attributes});
297+
}
298+
299+
template <class U,
300+
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
301+
void Record(T value, const U &attributes, const context::Context &context) noexcept
302+
{
303+
this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
304+
}
305+
306+
void Record(T value,
307+
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
308+
attributes) noexcept
309+
{
310+
this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
311+
attributes.begin(), attributes.end()});
312+
}
313+
314+
void Record(
315+
T value,
316+
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
317+
const context::Context &context) noexcept
318+
{
319+
this->Record(value,
320+
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
321+
attributes.begin(), attributes.end()},
322+
context);
323+
}
324+
};
325+
#endif
326+
250327
} // namespace metrics
251328
OPENTELEMETRY_END_NAMESPACE

api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ struct VoidTImpl {
106106
using type = void;
107107
};
108108

109-
// This trick to retrieve a default alignment is necessary for our
110-
// implementation of aligned_storage_t to be consistent with any implementation
111-
// of std::aligned_storage.
112-
template <size_t Len, typename T = std::aligned_storage<Len>>
113-
struct default_alignment_of_aligned_storage;
114-
115-
template <size_t Len, size_t Align>
116-
struct default_alignment_of_aligned_storage<Len,
117-
std::aligned_storage<Len, Align>> {
118-
static constexpr size_t value = Align;
119-
};
120-
121109
////////////////////////////////
122110
// Library Fundamentals V2 TS //
123111
////////////////////////////////
@@ -619,10 +607,6 @@ using remove_extent_t = typename std::remove_extent<T>::type;
619607
template <typename T>
620608
using remove_all_extents_t = typename std::remove_all_extents<T>::type;
621609

622-
template <size_t Len, size_t Align = type_traits_internal::
623-
default_alignment_of_aligned_storage<Len>::value>
624-
using aligned_storage_t = typename std::aligned_storage<Len, Align>::type;
625-
626610
template <typename T>
627611
using decay_t = typename std::decay<T>::type;
628612

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()

cmake/opentelemetry-cpp-config.cmake.in

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,39 @@ set(OPENTELEMETRY_VERSION
7070

7171
# ##############################################################################
7272

73-
find_package(Threads)
73+
include(CMakeFindDependencyMacro)
74+
75+
find_dependency(Threads)
76+
77+
if(@WITH_ABSEIL@)
78+
find_dependency(absl)
79+
endif()
80+
81+
if(@WITH_OTLP_GRPC@)
82+
find_dependency(gRPC)
83+
endif()
84+
85+
if("@OpenTracing_FOUND@")
86+
find_dependency(OpenTracing)
87+
endif()
88+
89+
if("@prometheus-cpp_FOUND@")
90+
find_dependency(prometheus-cpp)
91+
endif()
92+
93+
if("@Protobuf_FOUND@" OR "@PROTOBUF_FOUND@")
94+
find_dependency(Protobuf)
95+
endif()
96+
97+
if (@WITH_HTTP_CLIENT_CURL@ AND NOT @BUILD_SHARED_LIBS@)
98+
if("@CURL_FOUND@")
99+
find_dependency(CURL)
100+
endif()
101+
102+
if("@ZLIB_FOUND@")
103+
find_dependency(ZLIB)
104+
endif()
105+
endif()
74106

75107
set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@")
76108
set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@")

examples/common/metrics_foo_library/foo_library.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,22 @@ void foo_library::histogram_example(const std::string &name)
107107
std::this_thread::sleep_for(std::chrono::milliseconds(250));
108108
}
109109
}
110+
111+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
112+
void foo_library::gauge_example(const std::string &name)
113+
{
114+
std::string gauge_name = name + "_gauge";
115+
auto provider = metrics_api::Provider::GetMeterProvider();
116+
opentelemetry::nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0");
117+
auto gauge = meter->CreateInt64Gauge(gauge_name, "des", "unit");
118+
auto context = opentelemetry::context::Context{};
119+
for (uint32_t i = 0; i < 20; ++i)
120+
{
121+
int64_t val = (rand() % 100) + 100;
122+
std::map<std::string, std::string> labels = get_random_attr();
123+
auto labelkv = opentelemetry::common::KeyValueIterableView<decltype(labels)>{labels};
124+
gauge->Record(val, labelkv, context);
125+
std::this_thread::sleep_for(std::chrono::milliseconds(250));
126+
}
127+
}
128+
#endif

examples/common/metrics_foo_library/foo_library.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ class foo_library
1111
static void counter_example(const std::string &name);
1212
static void histogram_example(const std::string &name);
1313
static void observable_counter_example(const std::string &name);
14+
#if OPENTELEMETRY_ABI_VERSION_NO >= 2
15+
static void gauge_example(const std::string &name);
16+
#endif
1417
};

0 commit comments

Comments
 (0)