From 1467d663a9fb2f419b127d94c22ee2eb4d24f0a2 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 18 Jan 2024 13:52:12 -0800 Subject: [PATCH 1/3] [EXAMPLES] Use logs API instead of logs bridge API in the example (#2494) --- examples/common/logs_foo_library/foo_library.cc | 5 ++--- examples/logs_simple/README.md | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/common/logs_foo_library/foo_library.cc b/examples/common/logs_foo_library/foo_library.cc index 5fd274193c..d77cd058dc 100644 --- a/examples/common/logs_foo_library/foo_library.cc +++ b/examples/common/logs_foo_library/foo_library.cc @@ -32,7 +32,6 @@ void foo_library() auto scoped_span = trace::Scope(get_tracer()->StartSpan("foo_library")); auto ctx = span->GetContext(); auto logger = get_logger(); - logger->EmitLogRecord(opentelemetry::logs::Severity::kDebug, "body", ctx.trace_id(), - ctx.span_id(), ctx.trace_flags(), - opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); + + logger->Debug("body", ctx.trace_id(), ctx.span_id(), ctx.trace_flags()); } diff --git a/examples/logs_simple/README.md b/examples/logs_simple/README.md index 24db84bc08..7e4a1dfc78 100644 --- a/examples/logs_simple/README.md +++ b/examples/logs_simple/README.md @@ -1,16 +1,16 @@ - # Simple Logs Example In this example, the application in `main.cc` initializes an `OStreamLogRecordExporter` instance and registers a logger provider, as well as initializes a `StdoutSpanExporter` instance and registers a -tracer provider from the [OpenTelemetry +tracer provider from the [OpenTelemetry C++ SDK](https://github.com/open-telemetry/opentelemetry-cpp). -The application then calls a `logs_foo_library` which has been instrumented -using the [OpenTelemetry -API](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/api). -Resulting logs and traces are directed to stdout. +The application then calls into +[`logs_foo_library`](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/examples/common/logs_foo_library/foo_library.cc) +which has been instrumented using the [OpenTelemetry Logs +API](../../api/include/opentelemetry/logs/logger.h). Resulting logs and traces +are directed to stdout. See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example. From 589dd2ac6b4a33af145cea911e8e28cc16d79743 Mon Sep 17 00:00:00 2001 From: bcsgh <33939446+bcsgh@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:47:24 -0800 Subject: [PATCH 2/3] [BUILD] Fix checks on __cplusplus under MSVC, do not assume /Zc (#2493) --- .../nostd/internal/absl/base/policy_checks.h | 12 +++++++----- .../nostd/internal/absl/meta/type_traits.h | 3 ++- .../opentelemetry/exporters/ostream/common_utils.h | 9 ++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h b/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h index 02bdda4b63..f86c264fc4 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h @@ -71,13 +71,15 @@ // C++ Version Check // ----------------------------------------------------------------------------- -// Enforce C++11 as the minimum. Note that Visual Studio has not -// advanced __cplusplus despite being good enough for our purposes, so -// so we exempt it from the check. -#if defined(__cplusplus) && !defined(_MSC_VER) +// Enforce C++11 as the minimum. +#if defined(_MSVC_LANG) +#if _MSVC_LANG < 201103L +#error "C++ versions less than C++11 are not supported." +#endif // _MSVC_LANG < 201103L +#elif defined(__cplusplus) #if __cplusplus < 201103L #error "C++ versions less than C++11 are not supported." -#endif +#endif // __cplusplus < 201103L #endif // ----------------------------------------------------------------------------- diff --git a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h index 489f6d47f9..8430f0087c 100644 --- a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h +++ b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h @@ -618,7 +618,8 @@ using underlying_type_t = typename std::underlying_type::type; namespace type_traits_internal { -#if __cplusplus >= 201703L +#if (!defined(_MSVC_LANG) && (__cplusplus >= 201703L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // std::result_of is deprecated (C++17) or removed (C++20) template struct result_of; template diff --git a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h index 11e098c5c0..ec1ee2d367 100644 --- a/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h +++ b/exporters/ostream/include/opentelemetry/exporters/ostream/common_utils.h @@ -58,7 +58,8 @@ void print_value(const nostd::span &vec, std::ostream &sout) } // Prior to C++14, generic lambda is not available so fallback to functor. -#if __cplusplus < 201402L +#if (!defined(_MSVC_LANG) && (__cplusplus < 201402L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG < 201402L)) class OwnedAttributeValueVisitor { @@ -97,7 +98,8 @@ class AttributeValueVisitor inline void print_value(const opentelemetry::sdk::common::OwnedAttributeValue &value, std::ostream &sout) { -#if __cplusplus < 201402L +#if (!defined(_MSVC_LANG) && (__cplusplus < 201402L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG < 201402L)) opentelemetry::nostd::visit(OwnedAttributeValueVisitor(sout), value); #else opentelemetry::nostd::visit( @@ -111,7 +113,8 @@ inline void print_value(const opentelemetry::sdk::common::OwnedAttributeValue &v inline void print_value(const opentelemetry::common::AttributeValue &value, std::ostream &sout) { -#if __cplusplus < 201402L +#if (!defined(_MSVC_LANG) && (__cplusplus < 201402L)) || \ + (defined(_MSVC_LANG) && (_MSVC_LANG < 201402L)) opentelemetry::nostd::visit(AttributeValueVisitor(sout), value); #else opentelemetry::nostd::visit( From 2b5c2b404448d8b675c2d645e27e9affd609ccb7 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Fri, 19 Jan 2024 00:10:55 -0800 Subject: [PATCH 3/3] [BUILD] Add DLL build CI pipeline with CXX20 (#2465) --- .github/workflows/ci.yml | 2 ++ CHANGELOG.md | 2 ++ ci/do_ci.ps1 | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9ec728a62..a0b0121f56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -732,6 +732,8 @@ jobs: ./ci/install_windows_protobuf.ps1 - name: run cmake test (DLL build) run: ./ci/do_ci.ps1 cmake.dll.test + - name: run cmake cxx20 test (DLL build) + run: ./ci/do_ci.ps1 cmake.dll.cxx20.test - name: run otprotocol test (DLL build) run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.dll.test diff --git a/CHANGELOG.md b/CHANGELOG.md index 89624f88cf..478e24edb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Increment the: [#2449](https://github.com/open-telemetry/opentelemetry-cpp/pull/2449) * [BUILD] Introduce CXX 20 CI pipeline for MSVC/Windows [#2450](https://github.com/open-telemetry/opentelemetry-cpp/pull/2450) +* [BUILD] Add DLL build CI pipeline with CXX20 + [#2465](https://github.com/open-telemetry/opentelemetry-cpp/pull/2465) * [EXPORTER] Set `is_monotonic` flag for Observable Counters [#2478](https://github.com/open-telemetry/opentelemetry-cpp/pull/2478) * [PROTO] Upgrade to opentelemetry-proto v1.1.0 diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index a1e8c10014..bdab94ae04 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -90,6 +90,44 @@ switch ($action) { exit $exit } } + "cmake.dll.cxx20.test" { + cd "$BUILD_DIR" + cmake $SRC_DIR ` + -DCMAKE_CXX_STANDARD=20 ` + -DVCPKG_TARGET_TRIPLET=x64-windows ` + -DOPENTELEMETRY_BUILD_DLL=1 ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + cmake --build . -j $nproc + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + ctest -C Debug + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + $env:PATH = "$BUILD_DIR\ext\src\dll\Debug;$env:PATH" + examples\simple\Debug\example_simple.exe + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + examples\metrics_simple\Debug\metrics_ostream_example.exe + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + examples\logs_simple\Debug\example_logs_simple.exe + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + } "cmake.maintainer.test" { cd "$BUILD_DIR" cmake $SRC_DIR `