From 9b1725b39a49748ef83682ae46aee69c5182dca1 Mon Sep 17 00:00:00 2001 From: Max Golovanov Date: Wed, 7 Jul 2021 20:47:10 -0700 Subject: [PATCH 1/2] Build farm for Windows (#839) --- tools/build-benchmark.cmd | 2 +- tools/build-clang-12.cmd | 7 ++ tools/build-clang.cmd | 7 ++ tools/build-vs2015.cmd | 32 +++++++-- tools/build-vs2017.cmd | 13 +++- tools/build-vs2019.cmd | 8 +-- tools/build.cmd | 100 ++++++++++++++++----------- tools/ports/benchmark/portfile.cmake | 4 -- tools/setup-buildtools.cmd | 20 ++++-- tools/vcvars.cmd | 52 ++++++++++++-- 10 files changed, 174 insertions(+), 71 deletions(-) create mode 100644 tools/build-clang-12.cmd create mode 100644 tools/build-clang.cmd diff --git a/tools/build-benchmark.cmd b/tools/build-benchmark.cmd index 39b9f180d9..379cb1313a 100644 --- a/tools/build-benchmark.cmd +++ b/tools/build-benchmark.cmd @@ -1,5 +1,5 @@ @echo off -set VS_TOOLS_VERSION=vs2019 +set BUILDTOOLS_VERSION=vs2019 set CMAKE_GEN="Visual Studio 16 2019" echo Building Google Benchmark (test only dependency)... @setlocal ENABLEEXTENSIONS diff --git a/tools/build-clang-12.cmd b/tools/build-clang-12.cmd new file mode 100644 index 0000000000..a41c5bb6c1 --- /dev/null +++ b/tools/build-clang-12.cmd @@ -0,0 +1,7 @@ +@echo off +pushd %~dp0 +set "PATH=%ProgramFiles%\LLVM-12\bin;%PATH%" +set BUILDTOOLS_VERSION=clang-12 +set CMAKE_GEN=Ninja +call build.cmd %* +popd diff --git a/tools/build-clang.cmd b/tools/build-clang.cmd new file mode 100644 index 0000000000..c160fd661b --- /dev/null +++ b/tools/build-clang.cmd @@ -0,0 +1,7 @@ +@echo off +pushd %~dp0 +set "PATH=%ProgramFiles%\LLVM\bin;%PATH%" +set BUILDTOOLS_VERSION=clang +set CMAKE_GEN=Ninja +call build.cmd %* +popd diff --git a/tools/build-vs2015.cmd b/tools/build-vs2015.cmd index 30bb41c3c9..ed230d1559 100644 --- a/tools/build-vs2015.cmd +++ b/tools/build-vs2015.cmd @@ -1,11 +1,33 @@ REM Build with Visual Studio 2015 -set "VS_TOOLS_VERSION=vs2015" -set ARCH=Win64 +set "PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin;%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\bin;%PATH%" + +REM ### Note that vcpkg built with 2019/2017 can't be used with 2015! +REM ### Consider to specify custom VCPKG_ROOT for 2015 as follows: +REM +REM set VCPKG_ROOT=C:\vcpkg.2015 +REM + +set BUILDTOOLS_VERSION=vs2015 +set ARCH=x64 if NOT "%1"=="" ( set ARCH=%1 ) -set "CMAKE_GEN=Visual Studio 14 2015 %ARCH%" +set "CMAKE_GEN=Ninja" +set "VCPKG_VISUAL_STUDIO_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0" + +REM Building with Windows SDK 8.1 +set "PATH=%ProgramFiles(x86)%\Windows Kits\8.1\bin\%ARCH%;%PATH%" +set WINSDK_VERSION=8.1 +set CMAKE_SYSTEM_VERSION=8.1 +set VCPKG_PLATFORM_TOOLSET=v140 + +REM ### Replace above Windows SDK 8.1 by Windows 10 SDK if necessary. +REM ### Resulting binaries may not be compatible with Windows 8 +REM +REM set WINSDK_VERSION=10.0.19041.0 +REM set "PATH=%ProgramFiles(x86)%\Windows Kits\10\bin\10.0.19041.0\%ARCH%\;%PATH%" +REM + cd %~dp0 call setup-buildtools.cmd -REM TODO: currently we cannot build without Abseil variant for Visual Studio 2015 -call build.cmd -DWITH_ABSEIL:BOOL=ON +call build.cmd -DMSVC_TOOLSET_VERSION=140 diff --git a/tools/build-vs2017.cmd b/tools/build-vs2017.cmd index de84593123..3a95d9b110 100644 --- a/tools/build-vs2017.cmd +++ b/tools/build-vs2017.cmd @@ -1,10 +1,17 @@ REM Build with Visual Studio 2017 -set "VS_TOOLS_VERSION=vs2017" -set ARCH=Win64 +set "BUILDTOOLS_VERSION=vs2017" +set ARCH=x64 if NOT "%1"=="" ( set ARCH=%1 ) -set "CMAKE_GEN=Visual Studio 15 2017 %ARCH%" + +REM ### Uncomment below to use Visual Studio MSBuild solution. +REM ### Ninja generator produces much faster builds. But it is +REM ### easier to debug MSBuild solution in vs2017 IDE : +REM +REM set "CMAKE_GEN=Visual Studio 15 2017" +REM + cd %~dp0 call setup-buildtools.cmd call build.cmd diff --git a/tools/build-vs2019.cmd b/tools/build-vs2019.cmd index b4a39938a3..2fd6dbc59e 100644 --- a/tools/build-vs2019.cmd +++ b/tools/build-vs2019.cmd @@ -1,15 +1,13 @@ REM Build with Visual Studio 2017 -set "VS_TOOLS_VERSION=vs2019" -set ARCH=Win64 +set "BUILDTOOLS_VERSION=vs2019" +set ARCH=x64 if NOT "%1"=="" ( set ARCH=%1 ) -if "%ARCH%"=="Win64" ( +if "%ARCH%"=="x64" ( REM Parameter needed for CMake Visual Studio 2019 generator set CMAKE_ARCH=x64 ) - -set "CMAKE_GEN=Visual Studio 16 2019" cd %~dp0 call setup-buildtools.cmd call build.cmd diff --git a/tools/build.cmd b/tools/build.cmd index 14da784661..7558f4efff 100644 --- a/tools/build.cmd +++ b/tools/build.cmd @@ -1,6 +1,6 @@ @echo off REM ########################################################################################## -REM # Build SDK with Visual Studio + CMake + MSBUild or Ninja. # +REM # Build SDK with (msvc or clang) + CMake + (MSBuild or Ninja). # REM # # REM # CMake arguments may be passed as parameters to this script. # REM # If Visual Studio is not installed, then this script falls back to LLVM-CLang, # @@ -10,7 +10,7 @@ REM ############################################################################ REM # # REM # Options passed as environment variables: # REM # # -REM # VS_TOOLS_VERSION - specify visual studio version. See `vcvars.cmd` for details. # +REM # BUILDTOOLS_VERSION - specify build tools version. See `vcvars.cmd` for details. # REM # CMAKE_GEN - specify CMake generator. # REM # VCPKG_ROOT - path to vcpkg root # REM # ARCH - architecture to build for (default: x64) # @@ -20,36 +20,43 @@ set "PATH=%PATH%;%ProgramFiles%\CMake\bin" pushd %~dp0 setlocal enableextensions setlocal enabledelayedexpansion -if not defined VS_TOOLS_VERSION ( - set VS_TOOLS_VERSION=vs2019 +if not defined BUILDTOOLS_VERSION ( + set BUILDTOOLS_VERSION=vs2019 ) REM ########################################################################################## REM Set up CMake generator. Use Ninja if available. REM ########################################################################################## -if not defined CMAKE_GEN ( - set CMAKE_GEN=Visual Studio 16 2019 - for /f "tokens=*" %%F in ('where ninja') do ( - set NINJA=%%F - ) - if defined VCPKG_ROOT ( - if not defined NINJA ( - for /f "tokens=*" %%F in ('where /R %VCPKG_ROOT%\vcpkg\downloads\tools ninja') do ( - set NINJA=%%F - ) - popd - ) - ) +for /f "tokens=*" %%F in ('where ninja') do ( + set NINJA=%%F +) + +if defined VCPKG_ROOT ( if not defined NINJA ( - for /f "tokens=*" %%F in ('where /R %CD%\vcpkg\downloads\tools ninja') do ( + for /f "tokens=*" %%F in ('where /R %VCPKG_ROOT%\vcpkg\downloads\tools ninja') do ( set NINJA=%%F ) + popd ) - if defined NINJA ( - echo Using ninja at !NINJA! +) + +if not defined NINJA ( + for /f "tokens=*" %%F in ('where /R %CD%\vcpkg\downloads\tools ninja') do ( + set NINJA=%%F + ) +) + +if defined NINJA ( + echo Found ninja: !NINJA! + if not defined CMAKE_GEN ( set CMAKE_GEN=Ninja ) ) + +if not defined CMAKE_GEN ( + set CMAKE_GEN=Visual Studio 16 2019 +) + set "ROOT=%~dp0\.." if not defined ARCH ( set ARCH=x64 @@ -80,23 +87,18 @@ REM The following two configurations are built below: REM - nostd - build with OpenTelemetry C++ Template library REM - stl - build with Standard Template Library REM ########################################################################################## -REM Build with nostd implementation. Supported VS_TOOLS_VERSION: -REM - vs2015 (C++11) -REM - vs2017 (C++14) -REM - vs2019 (C++20) +REM Build with nostd implementation. REM ########################################################################################## set CONFIG=-DWITH_STL:BOOL=OFF %* -set "OUTDIR=%ROOT%\out\%VS_TOOLS_VERSION%\nostd" +set "OUTDIR=%ROOT%\out\%BUILDTOOLS_VERSION%\nostd" call :build_config REM ########################################################################################## -REM Build with STL implementation (only for vs2017+). Supported VS_TOOLS_VERSION: -REM - vs2017 (C++14) -REM - vs2019 (C++20) - optimal config with all OpenTelemetry API classes using STL only. +REM Build with STL implementation. This option does not yield benefits for vs2015 build. REM ########################################################################################## -if "%VS_TOOLS_VERSION%" neq "vs2015" ( +if "%BUILDTOOLS_VERSION%" neq "vs2015" ( set CONFIG=-DWITH_STL:BOOL=ON %* - set "OUTDIR=%ROOT%\out\%VS_TOOLS_VERSION%\stl" + set "OUTDIR=%ROOT%\out\%BUILDTOOLS_VERSION%\stl" call :build_config ) @@ -110,18 +112,36 @@ REM TODO: consider rmdir for clean builds if not exist "%OUTDIR%" mkdir "%OUTDIR%" cd "%OUTDIR%" -if "!VS_TOOLS_VERSION!" == "vs2019" ( - REM Prefer ninja if available - if "!CMAKE_GEN!" == "Ninja" ( - call :build_config_ninja - exit /b - ) - REM Only latest vs2019 generator supports and requires -A parameter +REM Prefer ninja if available +if "!CMAKE_GEN!" == "Ninja" ( + call :build_config_ninja + exit /b +) + +if "!BUILDTOOLS_VERSION!" == "vs2015" ( cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" -) else ( - REM Old vs2017 generator does not support -A parameter - cmake -G "!CMAKE_GEN!" -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + call :build_msbuild + exit /b ) + +if "!BUILDTOOLS_VERSION!" == "vs2017" ( + cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + call :build_msbuild + exit /b +) + +if "!BUILDTOOLS_VERSION!" == "vs2019" ( + cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + call :build_msbuild + exit /b +) + +REM ########################################################################################## +REM Exotic CMake generators, like MSYS and MinGW MAY work, but untested +REM ########################################################################################## +cmake -G "!CMAKE_GEN!" -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + +:build_msbuild set "SOLUTION=%OUTDIR%\opentelemetry-cpp.sln" msbuild "%SOLUTION%" /p:Configuration=Release /p:VcpkgEnabled=true exit /b diff --git a/tools/ports/benchmark/portfile.cmake b/tools/ports/benchmark/portfile.cmake index dba57ab53d..fdb988c538 100644 --- a/tools/ports/benchmark/portfile.cmake +++ b/tools/ports/benchmark/portfile.cmake @@ -1,11 +1,7 @@ if (VCPKG_PLATFORM_TOOLSET STREQUAL "v140") - # set(CMAKE_C_COMPILER_WORKS 1) - # set(CMAKE_CXX_COMPILER_WORKS 1) set(CMAKE_C_COMPILER cl.exe) set(CMAKE_CXX_COMPILER cl.exe) set(MSVC_TOOLSET_VERSION 140) - # set(VCPKG_VISUAL_STUDIO_PATH "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0") - # set(VCPKG_PLATFORM_TOOLSET v140) else() # Make sure vs2019 compiled binaries are compat with vs2017 set(VCPKG_CXX_FLAGS "/Zc:__cplusplus /d2FH4-") diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index fd31eb21fd..956c8ddfe4 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -1,8 +1,12 @@ @echo off setlocal enableextensions setlocal enabledelayedexpansion -set "PATH=%ProgramFiles%\CMake\bin;%~dp0;%~dp0vcpkg;%ProgramData%\chocolatey\bin;%PATH%" -if "%VCPKG_ROOT%" NEQ "" set "PATH=%VCPKG_ROOT%;%PATH%" +set "PATH=%ProgramFiles%\CMake\bin;%~dp0;%ProgramData%\chocolatey\bin;%PATH%" +if defined VCPKG_ROOT ( + set "PATH=%VCPKG_ROOT%;%PATH%" +) else ( + set "PATH=%~dp0vcpkg;%PATH%" +) pushd %~dp0 net session >nul 2>&1 @@ -22,11 +26,13 @@ if %errorLevel% == 0 ( echo Running without Administrative privilege... ) -REM Print current Visual Studio installations detected -where /Q vswhere -if %ERRORLEVEL% == 0 ( - echo Visual Studio installations detected: - vswhere -property installationPath +if not defined BUILDTOOLS_VERSION ( + REM Print current Visual Studio installations detected + where /Q vswhere + if %ERRORLEVEL% == 0 ( + echo Visual Studio installations detected: + vswhere -property installationPath + ) ) REM This script allows to pass architecture in ARCH env var diff --git a/tools/vcvars.cmd b/tools/vcvars.cmd index 69308778a7..94f5cca95a 100644 --- a/tools/vcvars.cmd +++ b/tools/vcvars.cmd @@ -1,7 +1,7 @@ @echo off REM +-------------------------------------------------------------------+ -REM | Autodetect and set up the build environment for Visual Studio. | -REM | Visual Studio version may be specified as 1st argument. | +REM | Autodetect and set up the build environment. | +REM | Build Tools version may be specified as 1st argument. | REM +-------------------------------------------------------------------+ REM | Description | Argument value | REM +-----------------------------------------+-------------------------+ @@ -18,6 +18,12 @@ REM | Visual Studio 2017 Community | vs2017_community | REM | Visual Studio 2017 Build Tools (no IDE) | vs2017_buildtools | REM | | | REM | Visual Studio 2015 Build Tools (no IDE) | vs2015 | +REM | | | +REM | LLVM Clang (any version) | clang | +REM | LLVM Clang 9 | clang-9 | +REM | LLVM Clang 10 | clang-10 | +REM | LLVM Clang 11 | clang-11 | +REM | LLVM Clang 11 | clang-12 | REM +-----------------------------------------+-------------------------+ set "VSCMD_START_DIR=%CD%" @@ -29,8 +35,8 @@ if "%1" neq "" ( goto %1 ) -if defined VS_TOOLS_VERSION ( - goto %VS_TOOLS_VERSION% +if defined BUILDTOOLS_VERSION ( + goto %BUILDTOOLS_VERSION% ) :vs2019 @@ -100,10 +106,10 @@ if exist %TOOLS_VS2017% ( ) :vs2015 -set TOOLS_VS2015="%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\bin\vcvarsall.bat" +set TOOLS_VS2015="%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" if exist %TOOLS_VS2015% ( echo Building with vs2015 BuildTools... - call %TOOLS_VS2015% %ARCH% + call %TOOLS_VS2015% %ARCH% %WINSDK_VERSION% set "VCPKG_VISUAL_STUDIO_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0" set VCPKG_PLATFORM_TOOLSET=v140 goto tools_configured @@ -115,4 +121,38 @@ REM is not set up by checking TOOLS_VS_NOTFOUND set TOOLS_VS_NOTFOUND=1 exit /b 0 +REM +-------------------------------------------------------------------+ +REM | There is no auto-detection of LLVM Clang version. | +REM | LLVM Clang of any version is installed in the same directory | +REM | at %ProgramFiles%\LLVM\bin . Developers choose their own custom | +REM | layout for installing multiple clang toolchains side-by-side. | +REM | | +REM | Example layout (merely a guideline, layout could differ): | +REM | | +REM | %ProgramFiles%\LLVM-9\bin | +REM | %ProgramFiles%\LLVM-10\bin | +REM | %ProgramFiles%\LLVM-11\bin | +REM | %ProgramFiles%\LLVM-12\bin | +REM +-------------------------------------------------------------------+ +REM +REM ## Example 1: use clang-10 located in LLVM-10 directory: +REM set BUILDTOOLS_VERSION=clang-10 +REM set "PATH=%ProgramFiles%\LLVM-10\bin;%PATH%" +REM tools\build.cmd +REM +REM ## Example 2: use whatever clang located in LLVM directory: +REM set BUILDTOOLS_VERSION=clang +REM set "PATH=%ProgramFiles%\LLVM\bin;%PATH%" +REM tools\build.cmd +REM +REM BUILDTOOLS_VERSION determines the output directory location. +REM Store build artifacts produced by different toolchains - +REM side-by-side, each in its own separate output directory. +REM +:clang +:clang-9 +:clang-10 +:clang-11 +:clang-12 + :tools_configured From 51b6b1940452717a10ded8422857940f3bca193b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 8 Jul 2021 21:56:18 +0530 Subject: [PATCH 2/2] Handle span events for jaeger exporter (#895) --- .../exporters/jaeger/recordable.h | 15 +++-- exporters/jaeger/src/recordable.cc | 65 ++++++++++++------- exporters/jaeger/src/thrift_sender.cc | 1 + .../jaeger/test/jaeger_recordable_test.cc | 34 ++++++++++ 4 files changed, 84 insertions(+), 31 deletions(-) diff --git a/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h b/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h index 01a4bb0d79..bd827f7669 100644 --- a/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h +++ b/exporters/jaeger/include/opentelemetry/exporters/jaeger/recordable.h @@ -56,6 +56,7 @@ class Recordable final : public sdk::trace::Recordable thrift::Span *Span() noexcept { return span_.release(); } std::vector Tags() noexcept { return std::move(tags_); } + std::vector Logs() noexcept { return std::move(logs_); } const std::string &ServiceName() const noexcept { return service_name_; } void SetIdentity(const opentelemetry::trace::SpanContext &span_context, @@ -88,18 +89,20 @@ class Recordable final : public sdk::trace::Recordable &instrumentation_library) noexcept override; private: - void AddTag(const std::string &key, const std::string &value); - void AddTag(const std::string &key, const char *value); - void AddTag(const std::string &key, bool value); - void AddTag(const std::string &key, int64_t value); - void AddTag(const std::string &key, double value); + void AddTag(const std::string &key, const std::string &value, std::vector &tags); + void AddTag(const std::string &key, const char *value, std::vector &tags); + void AddTag(const std::string &key, bool value, std::vector &tags); + void AddTag(const std::string &key, int64_t value, std::vector &tags); + void AddTag(const std::string &key, double value, std::vector &tags); void PopulateAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value); + const opentelemetry::common::AttributeValue &value, + std::vector &tags); private: std::unique_ptr span_; std::vector tags_; + std::vector logs_; std::string service_name_; }; diff --git a/exporters/jaeger/src/recordable.cc b/exporters/jaeger/src/recordable.cc index c9425b963b..38370ba8a2 100644 --- a/exporters/jaeger/src/recordable.cc +++ b/exporters/jaeger/src/recordable.cc @@ -14,27 +14,29 @@ using namespace opentelemetry::sdk::resource; Recordable::Recordable() : span_{new thrift::Span} {} -void Recordable::PopulateAttribute(nostd::string_view key, const common::AttributeValue &value) +void Recordable::PopulateAttribute(nostd::string_view key, + const common::AttributeValue &value, + std::vector &tags) { if (nostd::holds_alternative(value)) { - AddTag(std::string{key}, nostd::get(value)); + AddTag(std::string{key}, nostd::get(value), tags); } else if (nostd::holds_alternative(value)) { - AddTag(std::string{key}, nostd::get(value)); + AddTag(std::string{key}, nostd::get(value), tags); } else if (nostd::holds_alternative(value)) { - AddTag(std::string{key}, nostd::get(value)); + AddTag(std::string{key}, nostd::get(value), tags); } else if (nostd::holds_alternative(value)) { - AddTag(std::string{key}, std::string{nostd::get(value)}); + AddTag(std::string{key}, std::string{nostd::get(value)}, tags); } else if (nostd::holds_alternative(value)) { - AddTag(std::string{key}, std::string{nostd::get(value)}); + AddTag(std::string{key}, std::string{nostd::get(value)}, tags); } // TODO: extend other AttributeType to the types supported by Jaeger. } @@ -67,22 +69,33 @@ void Recordable::SetIdentity(const trace::SpanContext &span_context, void Recordable::SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept { - PopulateAttribute(key, value); + PopulateAttribute(key, value, tags_); } void Recordable::AddEvent(nostd::string_view name, common::SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept { - // TODO: convert event to Jaeger Log + std::vector tags; + PopulateAttribute("event", name.data(), tags); + + attributes.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept { + PopulateAttribute(key, value, tags); + return true; + }); + thrift::Log log; + log.__set_fields(tags); + log.__set_timestamp( + std::chrono::duration_cast(timestamp.time_since_epoch()).count()); + logs_.push_back(log); } void Recordable::SetInstrumentationLibrary( const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept { - AddTag("otel.library.name", instrumentation_library.GetName()); - AddTag("otel.library.version", instrumentation_library.GetVersion()); + AddTag("otel.library.name", instrumentation_library.GetName(), tags_); + AddTag("otel.library.version", instrumentation_library.GetVersion(), tags_); } void Recordable::AddLink(const trace::SpanContext &span_context, @@ -100,15 +113,15 @@ void Recordable::SetStatus(trace::StatusCode code, nostd::string_view descriptio if (code == trace::StatusCode::kOk) { - AddTag("otel.status_code", "OK"); + AddTag("otel.status_code", "OK", tags_); } else if (code == trace::StatusCode::kError) { - AddTag("otel.status_code", "ERROR"); - AddTag("error", true); + AddTag("otel.status_code", "ERROR", tags_); + AddTag("error", true, tags_); } - AddTag("otel.status_description", std::string{description}); + AddTag("otel.status_description", std::string{description}, tags_); } void Recordable::SetName(nostd::string_view name) noexcept @@ -166,11 +179,13 @@ void Recordable::SetSpanKind(trace::SpanKind span_kind) noexcept if (span_kind_str != nullptr) { - AddTag("span.kind", span_kind_str); + AddTag("span.kind", span_kind_str, tags_); } } -void Recordable::AddTag(const std::string &key, const std::string &value) +void Recordable::AddTag(const std::string &key, + const std::string &value, + std::vector &tags) { thrift::Tag tag; @@ -178,15 +193,15 @@ void Recordable::AddTag(const std::string &key, const std::string &value) tag.__set_vType(thrift::TagType::STRING); tag.__set_vStr(value); - tags_.push_back(tag); + tags.push_back(tag); } -void Recordable::AddTag(const std::string &key, const char *value) +void Recordable::AddTag(const std::string &key, const char *value, std::vector &tags) { - AddTag(key, std::string{value}); + AddTag(key, std::string{value}, tags); } -void Recordable::AddTag(const std::string &key, bool value) +void Recordable::AddTag(const std::string &key, bool value, std::vector &tags) { thrift::Tag tag; @@ -194,10 +209,10 @@ void Recordable::AddTag(const std::string &key, bool value) tag.__set_vType(thrift::TagType::BOOL); tag.__set_vBool(value); - tags_.push_back(tag); + tags.push_back(tag); } -void Recordable::AddTag(const std::string &key, int64_t value) +void Recordable::AddTag(const std::string &key, int64_t value, std::vector &tags) { thrift::Tag tag; @@ -205,10 +220,10 @@ void Recordable::AddTag(const std::string &key, int64_t value) tag.__set_vType(thrift::TagType::LONG); tag.__set_vLong(value); - tags_.push_back(tag); + tags.push_back(tag); } -void Recordable::AddTag(const std::string &key, double value) +void Recordable::AddTag(const std::string &key, double value, std::vector &tags) { thrift::Tag tag; @@ -216,7 +231,7 @@ void Recordable::AddTag(const std::string &key, double value) tag.__set_vType(thrift::TagType::DOUBLE); tag.__set_vDouble(value); - tags_.push_back(tag); + tags.push_back(tag); } } // namespace jaeger diff --git a/exporters/jaeger/src/thrift_sender.cc b/exporters/jaeger/src/thrift_sender.cc index 8cca180609..9a0b5fae6d 100644 --- a/exporters/jaeger/src/thrift_sender.cc +++ b/exporters/jaeger/src/thrift_sender.cc @@ -36,6 +36,7 @@ int ThriftSender::Append(std::unique_ptr &&span) noexcept thrift::Span &jaeger_span = *span->Span(); jaeger_span.__set_tags(span->Tags()); + jaeger_span.__set_logs(span->Logs()); const uint32_t span_size = CalcSizeOfSerializedThrift(jaeger_span); if (span_size > max_span_bytes) diff --git a/exporters/jaeger/test/jaeger_recordable_test.cc b/exporters/jaeger/test/jaeger_recordable_test.cc index 73a089556e..e3ef6b07bf 100644 --- a/exporters/jaeger/test/jaeger_recordable_test.cc +++ b/exporters/jaeger/test/jaeger_recordable_test.cc @@ -123,6 +123,40 @@ TEST(JaegerSpanRecordable, SetStatus) EXPECT_EQ(tags[2].vStr, error_description); } +TEST(JaegerSpanRecordable, AddEvent) +{ + opentelemetry::exporter::jaeger::Recordable rec; + + nostd::string_view name = "Test Event"; + + std::chrono::system_clock::time_point event_time = std::chrono::system_clock::now(); + opentelemetry::common::SystemTimestamp event_timestamp(event_time); + uint64_t epoch_us = + std::chrono::duration_cast(event_time.time_since_epoch()).count(); + + const int kNumAttributes = 3; + std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3"}; + int64_t values[kNumAttributes] = {4, 7, 23}; + std::map attributes = { + {keys[0], values[0]}, {keys[1], values[1]}, {keys[2], values[2]}}; + + rec.AddEvent( + "Test Event", event_timestamp, + opentelemetry::common::KeyValueIterableView>(attributes)); + thrift::Log log = rec.Logs().at(0); + EXPECT_EQ(log.timestamp, epoch_us); + auto tags = log.fields; + size_t index = 0; + EXPECT_EQ(tags[index].key, "event"); + EXPECT_EQ(tags[index++].vStr, "Test Event"); + while (index <= kNumAttributes) + { + EXPECT_EQ(tags[index].key, keys[index - 1]); + EXPECT_EQ(tags[index].vLong, values[index - 1]); + index++; + } +} + TEST(JaegerSpanRecordable, SetInstrumentationLibrary) { opentelemetry::exporter::jaeger::Recordable rec;