Skip to content

Commit affe589

Browse files
authored
Merge branch 'main' into benlandrum-default-construct
2 parents 8968a4a + 6b87300 commit affe589

File tree

17 files changed

+226
-91
lines changed

17 files changed

+226
-91
lines changed

.github/workflows/ci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,28 @@ jobs:
216216
- name: run tests
217217
run: ./ci/do_ci.sh bazel.noexcept
218218

219+
bazel_nortti:
220+
name: Bazel nortti
221+
runs-on: ubuntu-latest
222+
steps:
223+
- uses: actions/checkout@v3
224+
with:
225+
submodules: 'recursive'
226+
- name: Mount Bazel Cache
227+
uses: actions/cache@v3
228+
env:
229+
cache-name: bazel_cache
230+
with:
231+
path: /home/runner/.cache/bazel
232+
key: bazel_nortti
233+
- name: setup
234+
run: |
235+
sudo ./ci/setup_thrift.sh dependencies_only
236+
sudo ./ci/setup_ci_environment.sh
237+
sudo ./ci/install_bazelisk.sh
238+
- name: run tests
239+
run: ./ci/do_ci.sh bazel.nortti
240+
219241
bazel_asan:
220242
name: Bazel asan config
221243
runs-on: ubuntu-latest

api/include/opentelemetry/common/macros.h

+16
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@
2424
#else
2525
# define OPENTELEMETRY_MAYBE_UNUSED
2626
#endif
27+
28+
#ifndef OPENTELEMETRY_RTTI_ENABLED
29+
# if defined(__clang__)
30+
# if __has_feature(cxx_rtti)
31+
# define OPENTELEMETRY_RTTI_ENABLED
32+
# endif
33+
# elif defined(__GNUG__)
34+
# if defined(__GXX_RTTI)
35+
# define OPENTELEMETRY_RTTI_ENABLED
36+
# endif
37+
# elif defined(_MSC_VER)
38+
# if defined(_CPPRTTI)
39+
# define OPENTELEMETRY_RTTI_ENABLED
40+
# endif
41+
# endif
42+
#endif

ci/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh
1212
* `bazel.legacy.test`: build bazel targets and run tests for the targets meant
1313
to work with older compilers.
1414
* `bazel.noexcept`: build bazel targets and run tests with exceptions disabled.
15+
* `bazel.nortti`: build bazel targets and run tests with runtime type
16+
identification disabled.
1517
* `bazel.asan`: build bazel targets and run tests with AddressSanitizer.
1618
* `bazel.tsan`: build bazel targets and run tests with ThreadSanitizer.
1719
* `bazel.valgrind`: build bazel targets and run tests under the valgrind memory

ci/do_ci.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ mkdir -p "${BUILD_DIR}"
5959
[ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin
6060
mkdir -p "${PLUGIN_DIR}"
6161

62-
BAZEL_OPTIONS="--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST"
62+
BAZEL_OPTIONS="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST"
63+
# Previous legacy metrics use virtual drive, which can not be used without RTTI
64+
if [[ "$1" != "bazel.nortti" ]]; then
65+
BAZEL_OPTIONS="$BAZEL_OPTIONS --copt=-DENABLE_METRICS_PREVIEW"
66+
fi
6367
BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"
6468

6569
# https://github.com/bazelbuild/bazel/issues/4341
@@ -221,6 +225,12 @@ elif [[ "$1" == "bazel.noexcept" ]]; then
221225
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/...
222226
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/...
223227
exit 0
228+
elif [[ "$1" == "bazel.nortti" ]]; then
229+
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
230+
# that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here.
231+
bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/...
232+
bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/...
233+
exit 0
224234
elif [[ "$1" == "bazel.asan" ]]; then
225235
bazel $BAZEL_STARTUP_OPTIONS test --config=asan $BAZEL_TEST_OPTIONS //...
226236
exit 0

examples/multi_processor/main.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ namespace trace_api = opentelemetry::trace;
2020
namespace trace_sdk = opentelemetry::sdk::trace;
2121
namespace nostd = opentelemetry::nostd;
2222

23-
InMemorySpanExporter *memory_span_exporter;
24-
2523
namespace
2624
{
27-
void initTracer()
25+
InMemorySpanExporter *initTracer()
2826
{
2927
auto exporter1 = std::unique_ptr<trace_sdk::SpanExporter>(
3028
new opentelemetry::exporter::trace::OStreamSpanExporter);
3129
auto processor1 = std::unique_ptr<trace_sdk::SpanProcessor>(
3230
new trace_sdk::SimpleSpanProcessor(std::move(exporter1)));
3331

34-
auto exporter2 = std::unique_ptr<trace_sdk::SpanExporter>(new InMemorySpanExporter());
32+
InMemorySpanExporter *memory_span_exporter = new InMemorySpanExporter();
33+
auto exporter2 = std::unique_ptr<trace_sdk::SpanExporter>(memory_span_exporter);
3534

3635
// fetch the exporter for dumping data later
37-
memory_span_exporter = dynamic_cast<InMemorySpanExporter *>(exporter2.get());
3836

3937
auto processor2 = std::unique_ptr<trace_sdk::SpanProcessor>(
4038
new trace_sdk::SimpleSpanProcessor(std::move(exporter2)));
@@ -44,6 +42,8 @@ void initTracer()
4442
provider->AddProcessor(std::move(processor2));
4543
// Set the global trace provider
4644
trace_api::Provider::SetTracerProvider(std::move(provider));
45+
46+
return memory_span_exporter;
4747
}
4848

4949
void dumpSpans(std::vector<std::unique_ptr<trace_sdk::SpanData>> &spans)
@@ -81,7 +81,7 @@ void dumpSpans(std::vector<std::unique_ptr<trace_sdk::SpanData>> &spans)
8181
int main()
8282
{
8383
// Removing this line will leave the default noop TracerProvider in place.
84-
initTracer();
84+
InMemorySpanExporter *memory_span_exporter = initTracer();
8585

8686
foo_library();
8787
auto memory_spans = memory_span_exporter->GetData()->GetSpans();

exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Logger : public opentelemetry::logs::Logger
110110
common::SystemTimestamp timestamp) noexcept override
111111
{
112112

113-
# ifdef RTTI_ENABLED
113+
# ifdef OPENTELEMETRY_RTTI_ENABLED
114114
common::KeyValueIterable &attribs = const_cast<common::KeyValueIterable &>(attributes);
115115
Properties *evt = dynamic_cast<Properties *>(&attribs);
116116
// Properties *res = dynamic_cast<Properties *>(&resr);

exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class Tracer : public opentelemetry::trace::Tracer
377377
const opentelemetry::trace::SpanContextKeyValueIterable &links,
378378
const opentelemetry::trace::StartSpanOptions &options = {}) noexcept override
379379
{
380-
#ifdef RTTI_ENABLED
380+
#ifdef OPENTELEMETRY_RTTI_ENABLED
381381
common::KeyValueIterable &attribs = const_cast<common::KeyValueIterable &>(attributes);
382382
Properties *evt = dynamic_cast<Properties *>(&attribs);
383383
if (evt != nullptr)
@@ -531,7 +531,7 @@ class Tracer : public opentelemetry::trace::Tracer
531531
common::SystemTimestamp timestamp,
532532
const common::KeyValueIterable &attributes) noexcept
533533
{
534-
#ifdef RTTI_ENABLED
534+
#ifdef OPENTELEMETRY_RTTI_ENABLED
535535
common::KeyValueIterable &attribs = const_cast<common::KeyValueIterable &>(attributes);
536536
Properties *evt = dynamic_cast<Properties *>(&attribs);
537537
if (evt != nullptr)

exporters/etw/include/opentelemetry/exporters/etw/utils.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <sstream>
1313
#include <string>
1414

15+
#include "opentelemetry/common/macros.h"
1516
#include "opentelemetry/exporters/etw/uuid.h"
1617
#include "opentelemetry/version.h"
1718

@@ -25,22 +26,6 @@
2526
# pragma comment(lib, "Ole32.Lib")
2627
#endif
2728

28-
#ifndef RTTI_ENABLED
29-
# if defined(__clang__)
30-
# if __has_feature(cxx_rtti)
31-
# define RTTI_ENABLED
32-
# endif
33-
# elif defined(__GNUG__)
34-
# if defined(__GXX_RTTI)
35-
# define RTTI_ENABLED
36-
# endif
37-
# elif defined(_MSC_VER)
38-
# if defined(_CPPRTTI)
39-
# define RTTI_ENABLED
40-
# endif
41-
# endif
42-
#endif
43-
4429
OPENTELEMETRY_BEGIN_NAMESPACE
4530

4631
namespace utils

exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte
5454
for (auto &recordable : recordables)
5555
{
5656
auto span = std::unique_ptr<sdk::trace::SpanData>(
57-
dynamic_cast<sdk::trace::SpanData *>(recordable.release()));
57+
static_cast<sdk::trace::SpanData *>(recordable.release()));
5858
if (span != nullptr)
5959
{
6060
data_->Add(std::move(span));

sdk/include/opentelemetry/sdk/_metrics/controller.h

+6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# include <sstream>
1010
# include <thread>
1111
# include <vector>
12+
1213
# include "opentelemetry/_metrics/instrument.h"
14+
# include "opentelemetry/common/macros.h"
1315
# include "opentelemetry/nostd/unique_ptr.h"
1416
# include "opentelemetry/sdk/_metrics/exporter.h"
1517
# include "opentelemetry/sdk/_metrics/meter.h"
@@ -120,7 +122,11 @@ class PushController
120122
void tick()
121123
{
122124
this->mu_.lock();
125+
# ifdef OPENTELEMETRY_RTTI_ENABLED
123126
std::vector<Record> collected = dynamic_cast<Meter *>(meter_.get())->Collect();
127+
# else
128+
std::vector<Record> collected = static_cast<Meter *>(meter_.get())->Collect();
129+
# endif
124130
for (const auto &rec : collected)
125131
{
126132
processor_->process(rec);

sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h

+14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# include <sstream>
1010
# include <stdexcept>
1111
# include <vector>
12+
1213
# include "opentelemetry/_metrics/sync_instruments.h"
14+
# include "opentelemetry/common/macros.h"
1315
# include "opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h"
1416
# include "opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h"
1517
# include "opentelemetry/sdk/_metrics/instrument.h"
@@ -156,7 +158,11 @@ class Counter final : public SynchronousInstrument<T>, public opentelemetry::met
156158
{
157159
toDelete.push_back(x.first);
158160
}
161+
# ifdef OPENTELEMETRY_RTTI_ENABLED
159162
auto agg_ptr = dynamic_cast<BoundCounter<T> *>(x.second.get())->GetAggregator();
163+
# else
164+
auto agg_ptr = static_cast<BoundCounter<T> *>(x.second.get())->GetAggregator();
165+
# endif
160166
if (agg_ptr->is_updated())
161167
{
162168
agg_ptr->checkpoint();
@@ -287,7 +293,11 @@ class UpDownCounter final : public SynchronousInstrument<T>,
287293
{
288294
toDelete.push_back(x.first);
289295
}
296+
# ifdef OPENTELEMETRY_RTTI_ENABLED
290297
auto agg_ptr = dynamic_cast<BoundUpDownCounter<T> *>(x.second.get())->GetAggregator();
298+
# else
299+
auto agg_ptr = static_cast<BoundUpDownCounter<T> *>(x.second.get())->GetAggregator();
300+
# endif
291301
if (agg_ptr->is_updated())
292302
{
293303
agg_ptr->checkpoint();
@@ -417,7 +427,11 @@ class ValueRecorder final : public SynchronousInstrument<T>,
417427
{
418428
toDelete.push_back(x.first);
419429
}
430+
# ifdef OPENTELEMETRY_RTTI_ENABLED
420431
auto agg_ptr = dynamic_cast<BoundValueRecorder<T> *>(x.second.get())->GetAggregator();
432+
# else
433+
auto agg_ptr = static_cast<BoundValueRecorder<T> *>(x.second.get())->GetAggregator();
434+
# endif
421435
if (agg_ptr->is_updated())
422436
{
423437
agg_ptr->checkpoint();

0 commit comments

Comments
 (0)