6 #if defined(HAVE_OPENTELEMETRY_CPP) && HAVE_OPENTELEMETRY_CPP
7 # include "opentelemetry/exporters/ostream/span_exporter_factory.h"
8 # include "opentelemetry/sdk/trace/batch_span_processor_factory.h"
9 # include "opentelemetry/sdk/trace/batch_span_processor_options.h"
10 # include "opentelemetry/sdk/trace/tracer_provider_factory.h"
11 # include "opentelemetry/sdk/trace/batch_span_processor.h"
12 # include "opentelemetry/sdk/trace/exporter.h"
13 # include "opentelemetry/trace/provider.h"
16 #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF
19 # if defined(_MSC_VER)
20 # pragma warning(push)
21 # if ((defined(__cplusplus) && __cplusplus >= 201704L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201704L))
22 # pragma warning(disable : 4996)
23 # pragma warning(disable : 4309)
25 # pragma warning(disable : 5054)
30 # pragma warning(disable : 4800)
32 # pragma warning(disable : 4244)
33 # pragma warning(disable : 4251)
34 # pragma warning(disable : 4267)
37 # if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
38 # if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460
39 # pragma GCC diagnostic push
41 # pragma GCC diagnostic ignored "-Wunused-parameter"
42 # pragma GCC diagnostic ignored "-Wtype-limits"
43 # elif defined(__clang__) || defined(__apple_build_version__)
44 # pragma clang diagnostic push
45 # pragma clang diagnostic ignored "-Wunused-parameter"
46 # pragma clang diagnostic ignored "-Wtype-limits"
49 # include "test_pb.pb.h"
51 # if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
52 # if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460
53 # pragma GCC diagnostic pop
55 # elif defined(__clang__) || defined(__apple_build_version__)
56 # pragma clang diagnostic pop
59 # if defined(_MSC_VER)
65 #if defined(HAVE_OPENTELEMETRY_CPP) && HAVE_OPENTELEMETRY_CPP
67 constexpr
int kOpentelemetryNumSpans = 3;
71 static void OpentelemetryInitTracer() {
72 auto exporter = opentelemetry::exporter::trace::OStreamSpanExporterFactory::Create();
76 opentelemetry::sdk::trace::BatchSpanProcessorOptions
options;
79 options.max_queue_size = kOpentelemetryNumSpans * 2 + 1;
81 options.schedule_delay_millis = std::chrono::milliseconds(3000);
83 options.max_export_batch_size = kOpentelemetryNumSpans;
85 auto processor = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(std::move(exporter),
options);
87 auto provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor));
89 opentelemetry::trace::Provider::SetTracerProvider(std::move(provider));
92 opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer() {
93 auto provider = opentelemetry::trace::Provider::GetTracerProvider();
94 return provider->GetTracer(
"cmake-toolset-test");
97 static void OpentelemetryStartAndEndSpans() {
98 for (
int i = 1; i <= kOpentelemetryNumSpans; ++i) {
99 std::string msg =
"cmake-toolset-test-batch: ";
100 msg +=
static_cast<char>(i +
'0');
101 GetTracer()->StartSpan(msg);
105 static void OpentelemetryTest() {
106 OpentelemetryInitTracer();
107 OpentelemetryStartAndEndSpans();
108 OpentelemetryStartAndEndSpans();
111 OpentelemetryStartAndEndSpans();
119 #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF
121 cmake_toolset::test_message msg;
124 msg.set_str(
"Hello World!");
126 std::cout << msg.DebugString() << std::endl;
128 std::cout <<
"Hello World!" << std::endl;
130 #if defined(HAVE_OPENTELEMETRY_CPP) && HAVE_OPENTELEMETRY_CPP