diff --git a/.github/workflows/failover.yml b/.github/workflows/failover.yml index 1c43e8980..0aa47cbf2 100644 --- a/.github/workflows/failover.yml +++ b/.github/workflows/failover.yml @@ -35,8 +35,8 @@ jobs: # Configure build environment/dependencies - name: Install MySQL client libs and include files run: | - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-winx64.zip -o mysql.zip - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-winx64-debug-test.zip -o mysql-debug.zip + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-winx64.zip -o mysql.zip + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-winx64-debug-test.zip -o mysql-debug.zip unzip -d C:/ mysql.zip mkdir C:/mysql-${{ vars.MYSQL_VERSION }}-winx64-debug unzip -d C:/mysql-${{ vars.MYSQL_VERSION }}-winx64-debug mysql-debug.zip @@ -120,97 +120,97 @@ jobs: name: windows-failover-results path: ${{ github.workspace }}/build/unit_testing/Testing/Temporary/LastTest.log -# build-linux: -# name: Linux -# runs-on: ubuntu-latest -# env: -# CMAKE_GENERATOR: Unix Makefiles -# CXX: g++-11 -# steps: -# - name: Checkout source code -# uses: actions/checkout@v4 -# -# # Configure build environment/dependencies -# - name: Install build dependencies -# run: sudo apt-get update && sudo apt-get install -# g++-11 -# build-essential -# libgtk-3-dev -# unixodbc -# unixodbc-dev -# libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev # AWS SDK dependencies -# -# - name: Install MySQL client libs and include files -# run: | -# curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-linux-glibc2.28-x86_64.tar.xz -o mysql.tar.gz -# tar xf mysql.tar.gz -# -# - name: Cache AWS SDK libraries -# id: cache-dynamic-aws-sdk -# uses: actions/cache@v4 -# with: -# path: | -# aws_sdk -# key: ${{ runner.os }}-aws-sdk-dynamic-lib -# -# - name: Build and install AWS SDK C++ -# working-directory: ./scripts -# if: steps.cache-dynamic-aws-sdk.outputs.cache-hit != 'true' -# run: | -# ./build_aws_sdk_unix.sh $LINUX_BUILD_TYPE -# -# - name: Create build environment -# shell: bash -# run: cmake -E make_directory ${{ github.workspace }}/build -# -# - name: Configure CMake -# shell: bash -# run: cmake -S . -B build -# -G "$CMAKE_GENERATOR" -# -DCMAKE_BUILD_TYPE=$LINUX_BUILD_TYPE -# -DMYSQLCLIENT_STATIC_LINKING=true -# -DWITH_UNIXODBC=1 -# -DCONNECTOR_PLATFORM=linux -# -DMYSQL_DIR=./mysql-${{ vars.MYSQL_VERSION }}-linux-glibc2.28-x86_64/ -# -DENABLE_UNIT_TESTS=TRUE -# -DENABLE_INTEGRATION_TESTS=FALSE -# -# - name: copy AWS SDK libraries to driver library -# run: | -# cp ./aws_sdk/install/lib/*.so ./build/lib/ -# -# # Build driver -# - name: Build driver -# working-directory: ${{ github.workspace }}/build -# shell: bash -# run: make -j4 -# -# # Test driver -# - name: Run failover tests on Linux -# if: success() -# working-directory: ${{ github.workspace }}/build/unit_testing -# shell: bash -# run: ctest --output-on-failure -# -# # Upload artifacts -# - name: Upload build artifacts - Binaries -# if: always() -# uses: actions/upload-artifact@v4 -# with: -# name: linux-failover-binaries -# path: ${{ github.workspace }}/build/bin/ -# - name: Upload build artifacts - Libraries -# if: always() -# uses: actions/upload-artifact@v2 -# with: -# name: linux-failover-libraries -# path: ${{ github.workspace }}/build/lib/ -# - name: Upload test artifacts -# if: always() -# uses: actions/upload-artifact@v2 -# with: -# name: linux-failover-results -# path: ${{ github.workspace }}/build/unit_testing/Testing/Temporary/LastTest.log + build-linux: + name: Linux + runs-on: ubuntu-latest + env: + CMAKE_GENERATOR: Unix Makefiles + CXX: g++-11 + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + # Configure build environment/dependencies + - name: Install build dependencies + run: sudo apt-get update && sudo apt-get install + g++-11 + build-essential + libgtk-3-dev + unixodbc + unixodbc-dev + libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev # AWS SDK dependencies + + - name: Install MySQL client libs and include files + run: | + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-linux-glibc2.28-x86_64.tar.xz -o mysql.tar.gz + tar xf mysql.tar.gz + + - name: Cache AWS SDK libraries + id: cache-dynamic-aws-sdk + uses: actions/cache@v4 + with: + path: | + aws_sdk + key: ${{ runner.os }}-aws-sdk-dynamic-lib + + - name: Build and install AWS SDK C++ + working-directory: ./scripts + if: steps.cache-dynamic-aws-sdk.outputs.cache-hit != 'true' + run: | + ./build_aws_sdk_unix.sh $LINUX_BUILD_TYPE + + - name: Create build environment + shell: bash + run: cmake -E make_directory ${{ github.workspace }}/build + + - name: Configure CMake + shell: bash + run: cmake -S . -B build + -G "$CMAKE_GENERATOR" + -DCMAKE_BUILD_TYPE=$LINUX_BUILD_TYPE + -DMYSQLCLIENT_STATIC_LINKING=true + -DWITH_UNIXODBC=1 + -DCONNECTOR_PLATFORM=linux + -DMYSQL_DIR=./mysql-${{ vars.MYSQL_VERSION }}-linux-glibc2.28-x86_64/ + -DENABLE_UNIT_TESTS=TRUE + -DENABLE_INTEGRATION_TESTS=FALSE + + - name: copy AWS SDK libraries to driver library + run: | + cp ./aws_sdk/install/lib/*.so ./build/lib/ + + # Build driver + - name: Build driver + working-directory: ${{ github.workspace }}/build + shell: bash + run: make -j4 + + # Test driver + - name: Run failover tests on Linux + if: success() + working-directory: ${{ github.workspace }}/build/unit_testing + shell: bash + run: ctest --output-on-failure + + # Upload artifacts + - name: Upload build artifacts - Binaries + if: always() + uses: actions/upload-artifact@v4 + with: + name: linux-failover-binaries + path: ${{ github.workspace }}/build/bin/ + - name: Upload build artifacts - Libraries + if: always() + uses: actions/upload-artifact@v2 + with: + name: linux-failover-libraries + path: ${{ github.workspace }}/build/lib/ + - name: Upload test artifacts + if: always() + uses: actions/upload-artifact@v2 + with: + name: linux-failover-results + path: ${{ github.workspace }}/build/unit_testing/Testing/Temporary/LastTest.log build-mac: name: MacOS @@ -250,7 +250,7 @@ jobs: source /Users/runner/.bash_profile - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-macos14-x86_64.tar.gz -o mysql.tar.gz + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-macos14-x86_64.tar.gz -o mysql.tar.gz tar -xzvf mysql.tar.gz - name: Cache AWS SDK libraries diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02f96bc1d..e2b255164 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: # Configure build environment/dependencies - name: Install MySQL client libs run: | - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-winx64.zip -o mysql.zip + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-winx64.zip -o mysql.zip unzip -d C:/ mysql.zip - name: Add msbuild to PATH @@ -162,11 +162,11 @@ jobs: brew update brew unlink unixodbc - brew install libiodbc mysql@8.3 mysql-client@8.3 + brew install libiodbc mysql@8.4 mysql-client@8.4 brew link --overwrite --force libiodbc - brew link --overwrite --force mysql@8.3 - echo 'export PATH="/usr/local/opt/mysql@8.3/bin:$PATH"' >> /Users/runner/.bash_profile - echo 'export PATH="/usr/local/opt/mysql-client@8.3/bin:$PATH"' >> /Users/runner/.bash_profile + brew link --overwrite --force mysql@8.4 + echo 'export PATH="/usr/local/opt/mysql@8.4/bin:$PATH"' >> /Users/runner/.bash_profile + echo 'export PATH="/usr/local/opt/mysql-client@8.4/bin:$PATH"' >> /Users/runner/.bash_profile brew install openssl@3 rm -f /usr/local/lib/libssl.3.dylib @@ -176,7 +176,7 @@ jobs: source /Users/runner/.bash_profile - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-macos14-x86_64.tar.gz -o mysql.tar.gz + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-macos14-x86_64.tar.gz -o mysql.tar.gz tar -xzvf mysql.tar.gz - name: Cache AWS SDK libraries diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ebd725e30..83a9859e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,7 +45,7 @@ jobs: ln -s /usr/local/opt/openssl@3/lib/libssl.3.dylib /usr/local/lib/ ln -s /usr/local/opt/openssl@3/lib/libcrypto.3.dylib /usr/local/lib/ - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-macos13-x86_64.tar.gz -o mysql.tar.gz + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-macos13-x86_64.tar.gz -o mysql.tar.gz tar -xzvf mysql.tar.gz - name: Build and install AWS SDK C++ @@ -107,7 +107,7 @@ jobs: # # - name: Install MySQL client libs and include files # run: | -# curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-linux-glibc2.28-x86_64.tar.xz -o mysql.tar.gz +# curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-linux-glibc2.28-x86_64.tar.xz -o mysql.tar.gz # tar xf mysql.tar.gz # # - name: Build and install AWS SDK C++ @@ -161,7 +161,7 @@ jobs: # Configure build environment/dependencies - name: Install MySQL client libs run: | - curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-${{ vars.MYSQL_VERSION }}-winx64.zip -o mysql.zip + curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${{ vars.MYSQL_VERSION }}-winx64.zip -o mysql.zip unzip -d C:/ mysql.zip - name: Add msbuild to PATH diff --git a/.gitignore b/.gitignore index fd9d25711..eb6d3b610 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ INFO_SRC Install.bat myodbc3.spec Uninstall.bat +CMakeUserPresets.json VersionInfo.h # Visual Studio files diff --git a/CMakeLists.txt b/CMakeLists.txt index ad2445e59..0675fe841 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,7 @@ include(CheckCSourceCompiles) include(CheckCXXSourceCompiles) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/character_sets.cmake) include(${CMAKE_SOURCE_DIR}/cmake/libutils.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/version_info.cmake) # We need some extra FAIL_REGEX patterns # Note that CHECK_C_SOURCE_COMPILES is a misnomer, it will also link. @@ -356,12 +357,9 @@ ENDIF(WIN32) #----------------------------------------------------- -#-------- configuring paths to odbc heders for compatibility checks --------- CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlcolattrib1.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib1.c @ONLY) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlcolattrib2.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib2.c @ONLY) -CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlparamopt1.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlparamopt1.c @ONLY) -CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlparamopt2.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlparamopt2.c @ONLY) -#----------------------------------------------------- + #------------------ check compatibility--------------- TRY_COMPILE(COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlcolattrib1.c) @@ -381,24 +379,33 @@ ELSE(COMPILE_RESULT) ENDIF(COMPILE_RESULT1) ENDIF(COMPILE_RESULT) -TRY_COMPILE(COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlparamopt1.c) -MESSAGE(STATUS "Checking if SQLParamOptions() 2nd and 3rd arg is compatible with SQLULEN - ${COMPILE_RESULT}") -IF(COMPILE_RESULT) - ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLULEN_PTR) -ELSE(COMPILE_RESULT) - TRY_COMPILE(COMPILE_RESULT1 ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlparamopt2.c) - MESSAGE(STATUS "Checking if SQLParamOptions() 2nd and 3rd arg is compatible with SQLUINTEGER - ${COMPILE_RESULT1}") +IF(NOT WIN32 AND NOT WITH_UNIXODBC) + # This should be done only for iODBC because it has problems mapping + # deprecated ODBC 1.0 functions to newer API. + CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlparamopt1.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlparamopt1.c @ONLY) + CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/sqlparamopt2.c.cmake ${CMAKE_BINARY_DIR}/cmake/sqlparamopt2.c @ONLY) - IF(COMPILE_RESULT1) - ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLUINTEGER_PTR) - ELSE(COMPILE_RESULT1) - # SQLULEN is a default - MESSAGE(STATUS "Apparently odbc headers could not be found. 2nd and 3rd parameters assumed to be (*)SQLULEN by default") - ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLULEN_PTR) - ENDIF(COMPILE_RESULT1) + TRY_COMPILE(COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlparamopt1.c) + MESSAGE(STATUS "Checking if SQLParamOptions() 2nd and 3rd arg is compatible with SQLULEN - ${COMPILE_RESULT}") + + IF(COMPILE_RESULT) + ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLULEN_PTR) + ELSE(COMPILE_RESULT) + TRY_COMPILE(COMPILE_RESULT1 ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/cmake/sqlparamopt2.c) + MESSAGE(STATUS "Checking if SQLParamOptions() 2nd and 3rd arg is compatible with SQLUINTEGER - ${COMPILE_RESULT1}") + + IF(COMPILE_RESULT1) + ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLUINTEGER_PTR) + ELSE(COMPILE_RESULT1) + # SQLULEN is a default + MESSAGE(STATUS "Apparently odbc headers could not be found. 2nd and 3rd parameters assumed to be (*)SQLULEN by default") + ADD_DEFINITIONS(-DUSE_SQLPARAMOPTIONS_SQLULEN_PTR) + ENDIF(COMPILE_RESULT1) + + ENDIF(COMPILE_RESULT) +ENDIF() -ENDIF(COMPILE_RESULT) #----------------------------------------------------- IF(NOT NO_THREADS) @@ -497,7 +504,15 @@ ELSE(WIN32) else() - add_compile_options( -w ) + add_compile_options( + -w + -Wno-error=implicit-function-declaration #(1) + ) + + # (1) -- this warning was turned into error in clang, see discussion + # at [1] + # + # [1] https://discourse.llvm.org/t/configure-script-breakage-with-the-new-werror-implicit-function-declaration/65213/3 endif() @@ -524,20 +539,9 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/ssl_setup.cmake) setup_ssl_libs() INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) - INCLUDE_DIRECTORIES(${ctpl_SOURCE_DIR}) -ADD_LIBRARY(otel_api INTERFACE) -# Note: For now make it phony target on platforms other than Linux -if(NOT (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME MATCHES "SunOS")) - message(STATUS "Adding OTel support") - set(TELEMETRY ON) - target_include_directories(otel_api INTERFACE - "${CMAKE_SOURCE_DIR}/extra/otel/opentelemetry-cpp-1.8.3/api/include" - ) - target_compile_definitions(otel_api INTERFACE TELEMETRY) -endif() - +add_subdirectory(extra/otel) ADD_SUBDIRECTORY(util) ADD_SUBDIRECTORY(driver) @@ -628,7 +632,7 @@ SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION}${EXTRA_NAME_SUFFIX2}${PACKAGE_DRIVER_TYPE_SUFFIX}-${CONNECTOR_PLATFORM}") IF(WIN32) SET(CPACK_GENERATOR "ZIP") - SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-noinstall-${CONNECTOR_VERSION}${EXTRA_NAME_SUFFIX2}${PACKAGE_DRIVER_TYPE_SUFFIX}-${CONNECTOR_PLATFORM}") + SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CONNECTOR_VERSION}${EXTRA_NAME_SUFFIX2}${PACKAGE_DRIVER_TYPE_SUFFIX}-${CONNECTOR_PLATFORM}") ELSEIF(APPLE) SET(CPACK_GENERATOR "productbuild") SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}") @@ -639,10 +643,10 @@ ELSEIF(APPLE) SET(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macosx/Welcome.html") SET(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macosx/ReadMe.html") SET(CPACK_POSTFLIGHT_UNSPECIFIED_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macosx/postflight") -ELSE() +ELSE(WIN32) SET(CPACK_GENERATOR "TGZ") SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}") -ENDIF() +ENDIF(WIN32) SET(CPACK_SOURCE_IGNORE_FILES \\\\.bzr/ @@ -760,7 +764,7 @@ set(AUTH_PLUGINS ) if(NOT CMAKE_SYSTEM_NAME MATCHES "SunOS") - list(APPEND AUTH_PLUGINS webauthn fido) + list(APPEND AUTH_PLUGINS webauthn) # Note: Kerberos authentication plugin is not supported on macOS if(NOT APPLE) list(APPEND AUTH_PLUGINS kerberos) @@ -774,7 +778,6 @@ endif() # will break... For example: `krb5support` must go before `krb5` set(AUTH_DEPS_webauthn fido2) -set(AUTH_DEPS_fido fido2) if(WIN32) set(AUTH_DEPS_kerberos @@ -793,7 +796,7 @@ if(NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "SunOS") set(AUTH_DEPS_ldap_sasl libsasl ${AUTH_DEPS_kerberos}) endif() if(WIN32) - list(APPEND AUTH_DEPS_ldap_sasl + list(APPEND AUTH_DEPS_ldap_sasl saslSCRAM saslGSSAPI.dll ${AUTH_DEPS_kerberos} ) endif() @@ -819,10 +822,16 @@ endif(APPLE) # List plugins and other libraries that can be found bundled with the server # but which are not relevant on client-side and can be safely ignored. -set(IGNORED_PLUGINS qa_auth_client telemetry_client) +set(IGNORED_PLUGINS + qa_auth_client + # note: we have our own telemetry code, not using the client library plugin + telemetry_client + authentication_fido_client # note: replaced by webauthn plugin +) set(IGNORED_LIBS - abseil_dll # Added in 8.0.37 + libabsl abseil_dll # Since 8.4.0 + libpolyglot # present on MacOS since 8.4.0 libmysql lber libprotobuf ldap # note: this is needed only by server-side plugin libcurl libmecab zlib @@ -916,7 +925,10 @@ macro(bundle_libs to_bundle ignored) # On windows, libs are in bin directory if(WIN32) - file(GLOB _bundled1 "${MYSQL_DIR}/bin/*${CMAKE_SHARED_LIBRARY_SUFFIX}*") + file(GLOB _bundled1 + "${MYSQL_DIR}/bin/*${CMAKE_SHARED_LIBRARY_SUFFIX}*" + "${MYSQL_DIR}/bin/sasl2/*${CMAKE_SHARED_LIBRARY_SUFFIX}*" # SASL plugins + ) endif() endif() diff --git a/cmake/version_info.cmake b/cmake/version_info.cmake new file mode 100644 index 000000000..f4bac3429 --- /dev/null +++ b/cmake/version_info.cmake @@ -0,0 +1,93 @@ + +if(NOT DEFINED SHOW_VERSION_INFO AND MAINTAINER_MODE) + set(SHOW_VERSION_INFO 1) +endif() + +get_filename_component(VERSION_INFO_HOME "${CMAKE_CURRENT_LIST_DIR}/version_info" ABSOLUTE CACHE) + + +# +# Add Windows version info resources to the library/executable file produced +# by target TGT. +# +# This is ignored on non-Windows platforms. The second argument is a string +# to use as `FileDescription` attribute. If another argument is given, it +# is used for `Comments` attribute. +# +# Note: Version information is taken from version.cmake file included by +# gen_version_info.cmake script that generates resource definitions. +# +# + +function(add_version_info TGT DESCR) + + if(NOT WIN32) + return() + endif() + + get_target_property(TYPE ${TGT} TYPE) + + # Currently setting version resources for static libraries does not work. + # Possibly because of the machinery we use to merge static library from + # several smaller ones. For now we can live without version info in static + # libraries. + + if(TYPE STREQUAL "STATIC_LIBRARY") + return() + endif() + + set(out "${CMAKE_CURRENT_BINARY_DIR}/${TGT}_version_info.rc") + + # Command to generate .rc file with version information. This is done + # by the gen_version_info.cmake script which uses version_info.rc.in template. + + add_custom_command(OUTPUT "${out}" + COMMAND ${CMAKE_COMMAND} + -D "RC=${out}" + -D "OUTPUT=$" + -D "TYPE=${TYPE}" + -D "DESCRIPTION=${DESCR}" + -D "COMMENTS=${ARGN}" + -D "VERSION=${CMAKE_SOURCE_DIR}/version.cmake" + -D "CONFIG=$" + -P "${VERSION_INFO_HOME}/gen_version_info.cmake" + ) + + # Add the generated .rc file to the sources of the target. + + target_sources(${TGT} PRIVATE "${out}") + + if(SHOW_VERSION_INFO) + show_version_info(${TGT}) + endif() + + #add_custom_command(TARGET ${TGT} POST_BUILD + # COMMAND ${CMAKE_COMMAND} -E rm -rf "${out}" + #) + + message(STATUS "generated version info for target ${TGT} (${TYPE}): ${out}") + +endfunction() + +# +# Arrange for a library/executable target TGT to show the version information +# resources once its file is generated. +# +# This command is ignored on non-Windows platforms or if the target does not +# exist. +# + +function(show_version_info TGT) + + if(NOT WIN32 OR NOT TARGET ${TGT}) + return() + endif() + + add_custom_command(TARGET ${TGT} POST_BUILD + COMMAND ${CMAKE_COMMAND} + -D FILE=$ + -P "${VERSION_INFO_HOME}/show_version_info.cmake" + ) + +endfunction() + diff --git a/cmake/version_info/gen_version_info.cmake b/cmake/version_info/gen_version_info.cmake new file mode 100644 index 000000000..e5c2ecd31 --- /dev/null +++ b/cmake/version_info/gen_version_info.cmake @@ -0,0 +1,32 @@ +message("Re-generating version info resource defintions: ${RC}") +message("For output file: ${OUTPUT}") +message("Of type: ${TYPE}") +message("Build configuration: ${CONFIG}") + +include("${VERSION}") + + +set(PATH "${OUTPUT}") +get_filename_component(BASE "${OUTPUT}" NAME) +get_filename_component(BASE_WE "${OUTPUT}" NAME_WE) + +set(ODBC_VERSION "${CONNECTOR_NUMERIC_VERSION}") +string(REPLACE "." "," ODBC_VERSION_RAW "${ODBC_VERSION}") + +if("STATIC_LIBRARY" STREQUAL TYPE) + set(FILETYPE "VFT_STATIC_LIB") +elseif(TYPE MATCHES "_LIBRARY") + set(FILETYPE "VFT_DLL") +elseif("EXECUTABLE" STREQUAL TYPE) + set(FILETYPE "VFT_APP") +else() + set(FILETYPE 0) +endif() + +set(FILEFLAGS 0) +if(CONFIG MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(FILEFLAGS "VS_FF_DEBUG") +endif() + + +configure_file("${CMAKE_CURRENT_LIST_DIR}/version_info.rc.in" "${RC}" @ONLY) diff --git a/cmake/version_info/show_version_info.cmake b/cmake/version_info/show_version_info.cmake new file mode 100644 index 000000000..fd0b9f4b4 --- /dev/null +++ b/cmake/version_info/show_version_info.cmake @@ -0,0 +1,5 @@ +find_program(PWS powershell) +if(PWS) + message("Version information for: ${FILE}") + execute_process(COMMAND ${PWS} -command "ls ${FILE} | % VersionInfo | fl *") +endif() \ No newline at end of file diff --git a/cmake/version_info/version_info.rc.in b/cmake/version_info/version_info.rc.in new file mode 100644 index 000000000..69e3180fb --- /dev/null +++ b/cmake/version_info/version_info.rc.in @@ -0,0 +1,39 @@ +// Version info resources for @BASE@ +// Note: This is a generated file -- see cmake/version_info.cmake in the source tree. + +#include +#define VER_PRIVATEBUILD 0x0L +#define VER_PRERELEASE 0x0L + + +VS_VERSION_INFO VERSIONINFO + FILEVERSION @ODBC_VERSION_RAW@,0 + PRODUCTVERSION @ODBC_VERSION_RAW@,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS @FILEFLAGS@ + FILEOS VOS__WINDOWS32 + FILETYPE @FILETYPE@ +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "Comments", "provides core driver functionality\0" + VALUE "CompanyName", "Amazon.com Inc. or affiliates.\0" + VALUE "FileDescription", "MySQL ODBC @CONNECTOR_MAJOR@.@CONNECTOR_MINOR@ @DRIVER_TYPE@ Driver\0" + VALUE "FileVersion", MYODBC_STRFILEVER + VALUE "InternalName", "awsmysqlodbc@CONNECTOR_DRIVER_TYPE_SHORT@\0" + VALUE "LegalCopyright", "Copyright (c) 1995, 2018, Oracle and/or its affiliates.\0" + VALUE "LegalTrademarks", "MySQL, MyODBC, Connector/ODBC are trademarks of Oracle Corporation\0" + VALUE "OriginalFilename", "awsmysqlodbc@CONNECTOR_DRIVER_TYPE_SHORT@.dll\0" + VALUE "PrivateBuild", "Production\0" + VALUE "ProductName", "Connector/ODBC @CONNECTOR_MAJOR@.@CONNECTOR_MINOR@\0" + VALUE "ProductVersion", MYODBC_STRPRODUCTVER + VALUE "SpecialBuild", "@CONNECTOR_QUALITY@ release\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/dltest/CMakeLists.txt b/dltest/CMakeLists.txt index 9e7ba6e35..3f04b6e36 100644 --- a/dltest/CMakeLists.txt +++ b/dltest/CMakeLists.txt @@ -32,6 +32,11 @@ ADD_EXECUTABLE(dltest dltest.c) set_target_properties(dltest PROPERTIES FOLDER Tests) set_target_properties(dltest PROPERTIES PDB_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/test/) +add_version_info(dltest + "MySQL Connector/ODBC driver module tester." + "Checks whether the driver can be correctly loaded at run-time." +) + IF(NOT WIN32) INCLUDE_DIRECTORIES(${DL_INCLUDES}) diff --git a/dltest/dltest.c b/dltest/dltest.c index b1c291745..8eb770f48 100644 --- a/dltest/dltest.c +++ b/dltest/dltest.c @@ -28,7 +28,7 @@ #include #include -#include +#include // for strncmp() #ifdef WIN32 #include diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index bdb9ca74e..4ebe8e5a7 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -153,6 +153,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) if(TELEMETRY) list(APPEND DRIVER_SRCS telemetry.h) endif() + ENDIF(WIN32) # Note: We build driver as a MODULE, because this is what it really is @@ -163,6 +164,11 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) ADD_LIBRARY(${DRIVER_NAME_STATIC} STATIC ${DRIVER_SRCS} ${AWSSDK_LIB_DIR}) ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR}) + add_version_info(${DRIVER_NAME} + "AWS ODBC ${DRIVER_TYPE} Driver For MySQL." + "Provides core driver functionality." + ) + ADD_COVERAGE(${DRIVER_NAME}) IF(WIN32) diff --git a/driver/ansi.cc b/driver/ansi.cc index 178d965e7..620621afd 100644 --- a/driver/ansi.cc +++ b/driver/ansi.cc @@ -111,17 +111,6 @@ SQLColAttributeImpl(SQLHSTMT hstmt, SQLUSMALLINT column, } -SQLRETURN SQL_API -SQLColAttributes(SQLHSTMT hstmt, SQLUSMALLINT column, SQLUSMALLINT field, - SQLPOINTER char_attr, SQLSMALLINT char_attr_max, - SQLSMALLINT *char_attr_len, SQLLEN *num_attr) -{ - LOCK_STMT(hstmt); - return SQLColAttributeImpl(hstmt, column, field, char_attr, char_attr_max, - char_attr_len, num_attr); -} - - SQLRETURN SQL_API SQLColumnPrivileges(SQLHSTMT hstmt, SQLCHAR *catalog, SQLSMALLINT catalog_len, @@ -307,36 +296,6 @@ SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR *in, SQLSMALLINT in_len, } -SQLRETURN SQL_API -SQLError(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, SQLCHAR *sqlstate, - SQLINTEGER *native_error, SQLCHAR *message, SQLSMALLINT message_max, - SQLSMALLINT *message_len) -{ - SQLRETURN rc= SQL_INVALID_HANDLE; - - if (hstmt) - { - rc= SQLGetDiagRecImpl(SQL_HANDLE_STMT, hstmt, NEXT_STMT_ERROR(hstmt), - sqlstate, native_error, message, message_max, - message_len); - } - else if (hdbc) - { - rc= SQLGetDiagRecImpl(SQL_HANDLE_DBC, hdbc, NEXT_DBC_ERROR(hdbc), - sqlstate, native_error, message, message_max, - message_len); - } - else if (henv) - { - rc= SQLGetDiagRecImpl(SQL_HANDLE_ENV, henv, NEXT_ENV_ERROR(henv), - sqlstate, native_error, message, message_max, - message_len); - } - - return rc; -} - - SQLRETURN SQL_API SQLExecDirect(SQLHSTMT hstmt, SQLCHAR *str, SQLINTEGER str_len) { @@ -426,17 +385,6 @@ SQLGetConnectAttrImpl(SQLHDBC hdbc, SQLINTEGER attribute, SQLPOINTER value, } -SQLRETURN SQL_API -SQLGetConnectOption(SQLHDBC hdbc, SQLUSMALLINT option, SQLPOINTER value) -{ - CHECK_HANDLE(hdbc); - - return SQLGetConnectAttrImpl(hdbc, option, value, - ((option == SQL_ATTR_CURRENT_CATALOG) ? - SQL_MAX_OPTION_STRING_LENGTH : 0), NULL); -} - - SQLRETURN SQL_API SQLGetCursorName(SQLHSTMT hstmt, SQLCHAR *cursor, SQLSMALLINT cursor_max, SQLSMALLINT *cursor_len) @@ -794,20 +742,6 @@ SQLSetConnectAttrImpl(SQLHDBC hdbc, SQLINTEGER attribute, } -SQLRETURN SQL_API -SQLSetConnectOption(SQLHDBC hdbc, SQLUSMALLINT option, SQLULEN param) -{ - SQLINTEGER value_len= 0; - - CHECK_HANDLE(hdbc); - - if (option == SQL_ATTR_CURRENT_CATALOG) - value_len= SQL_NTS; - - return SQLSetConnectAttrImpl(hdbc, option, (SQLPOINTER)param, value_len); -} - - SQLRETURN SQL_API SQLSetCursorName(SQLHSTMT hstmt, SQLCHAR *name, SQLSMALLINT name_len) { diff --git a/driver/connect.cc b/driver/connect.cc index 800ba532e..ad7f7cf51 100644 --- a/driver/connect.cc +++ b/driver/connect.cc @@ -437,53 +437,34 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled, bool is_monitor_ if(!fido_func && global_fido_callback) fido_func = global_fido_callback; - std::vector plugin_types = { - "fido", "webauthn" - }; - if (fido_func || fido_callback_is_set) { - int plugin_load_failures = 0; - for (std::string plugin_type : plugin_types) - { - std::string plugin_name = "authentication_" + plugin_type + - "_client"; - struct st_mysql_client_plugin* plugin = + std::string plugin_name = "authentication_webauthn_client"; + struct st_mysql_client_plugin* plugin = connection_proxy->client_find_plugin( plugin_name.c_str(), MYSQL_CLIENT_AUTHENTICATION_PLUGIN); - if (plugin) - { - std::string opt_name = (plugin_type == "webauthn" ? - "plugin_authentication_webauthn_client" : - plugin_type) + "_messages_callback"; + if (plugin) + { + std::string opt_name = "plugin_authentication_webauthn_client_messages_callback"; - if (mysql_plugin_options(plugin, opt_name.c_str(), - (const void*)fido_func)) - { - // If plugin is loaded, but the callback option fails to set - // the error is reported. - return set_error("HY000", - "Failed to set a FIDO authentication callback function", 0); - } - } - else + if (mysql_plugin_options(plugin, opt_name.c_str(), + (const void*)fido_func)) { - // Do not report an error yet. - // Just increment the failure count. - ++plugin_load_failures; + // If plugin is loaded, but the callback option fails to set + // the error is reported. + return set_error("HY000", + "Failed to set a WebAuthn authentication callback function", 0); } } - - if (plugin_load_failures == plugin_types.size()) + else { - // Report error only if all plugins failed to load - return set_error("HY000", "Failed to set a FIDO " - "authentication callback because none of FIDO " - "authentication plugins (fido, webauthn) could " - "be loaded", 0); + return set_error("HY000", "Failed to set a WebAuthn authentciation " + "callback beacause the WebAuthn authentication " + "plugin could not be loaded", 0); } + fido_callback_is_set = fido_func; } else @@ -1628,75 +1609,6 @@ SQLRETURN SQL_API SQLDisconnect(SQLHDBC hdbc) } -void DBC::execute_prep_stmt(MYSQL_STMT *pstmt, std::string &query, - std::vector ¶m_bind, MYSQL_BIND *result_bind) -{ - STMT stmt{this, param_bind.size()}; - telemetry::Telemetry stmt_telemetry; - - try - { - // Prepare the query - - stmt_telemetry.span_start(&stmt, "SQL prepare"); - - if (connection_proxy->stmt_prepare(pstmt, query.c_str(), (unsigned long)query.length())) - { - throw nullptr; - } - - stmt_telemetry.span_end(&stmt); - - // Execute it. - - stmt_telemetry.span_start(&stmt, "SQL execute"); - -#if MYSQL_VERSION_ID >= 80300 - - // Move attributes to `param_bind` if any. They are bound as named parameters on top of the regular anonymous ones. - - for (size_t pos = param_bind.size(); pos < stmt.param_bind.size(); ++pos) - param_bind.emplace_back(std::move(stmt.param_bind[pos])); - - if (!param_bind.empty() && - connection_proxy->stmt_bind_named_param(pstmt, param_bind.data(), - (unsigned int)stmt.query_attr_names.size(), - stmt.query_attr_names.data()) - ) -#else - if (!param_bind.empty() && mysql_stmt_bind_param(pstmt, param_bind.data())) -#endif - { - throw nullptr; - } - - if (connection_proxy->stmt_execute(pstmt) || - (result_bind && mysql_stmt_bind_result(pstmt, result_bind)) - ) - { - throw nullptr; - } - - // Fetch results - - if (result_bind && connection_proxy->stmt_store_result(pstmt)) - { - throw nullptr; - } - - stmt_telemetry.span_end(&stmt); - - } - catch(nullptr_t) - { - set_error("HY000"); - stmt_telemetry.set_error(&stmt, error.message); - stmt_telemetry.span_end(&stmt); - throw error; - } -} - - SQLRETURN DBC::execute_query(const char* query, SQLULEN query_length, my_bool req_lock) { diff --git a/driver/cursor.cc b/driver/cursor.cc index 165a74774..99f56e035 100644 --- a/driver/cursor.cc +++ b/driver/cursor.cc @@ -1699,6 +1699,12 @@ SQLRETURN SQL_API my_SQLSetPos(SQLHSTMT hstmt, SQLSETPOSIROW irow, stmt->cursor_row= (long)(stmt->current_row+irow); data_seek(stmt, (my_ulonglong)stmt->cursor_row); stmt->current_values = stmt->fetch_row(); + + // After moving through the resultset the lengths + // in IRD must be updated accordingly. + fill_ird_data_lengths(stmt->ird, fetch_lengths(stmt), + stmt->result->field_count); + stmt->reset_getdata_position(); if ( stmt->fix_fields ) stmt->current_values= (*stmt->fix_fields)(stmt,stmt->current_values); diff --git a/driver/dll.cc b/driver/dll.cc index 38d2227c4..86797926e 100644 --- a/driver/dll.cc +++ b/driver/dll.cc @@ -212,7 +212,7 @@ int APIENTRY LibMain(HANDLE inst, DWORD ul_reason_being_called, break; case DLL_THREAD_DETACH: #ifdef THREAD - my_thread_end(); + mysql_thread_end(); #endif break; diff --git a/driver/driver.def.cmake b/driver/driver.def.cmake index 199a36216..795f97eb4 100644 --- a/driver/driver.def.cmake +++ b/driver/driver.def.cmake @@ -42,13 +42,10 @@ VERSION 0@CONNECTOR_MAJOR@.@CONNECTOR_MINOR_PADDED@ ;INIT_TEXT PRELOAD ;DATA PRELOAD ;HEAPSIZE 10000 -; +; ; Export definitions EXPORTS ; -SQLAllocConnect -SQLAllocEnv -SQLAllocStmt SQLAllocHandle SQLBindCol SQLBindParameter @@ -58,7 +55,6 @@ SQLCancel SQLCancelHandle SQLCloseCursor SQLColAttribute@WIDECHARCALL@ -SQLColAttributes@WIDECHARCALL@ SQLColumnPrivileges@WIDECHARCALL@ SQLColumns@WIDECHARCALL@ SQLConnect@WIDECHARCALL@ @@ -68,19 +64,15 @@ SQLDescribeParam SQLDisconnect SQLDriverConnect@WIDECHARCALL@ SQLEndTran -SQLError@WIDECHARCALL@ SQLExecDirect@WIDECHARCALL@ SQLExecute SQLExtendedFetch SQLFetch SQLFetchScroll -SQLFreeConnect -SQLFreeEnv SQLFreeStmt SQLFreeHandle SQLForeignKeys@WIDECHARCALL@ SQLGetConnectAttr@WIDECHARCALL@ -SQLGetConnectOption@WIDECHARCALL@ SQLGetCursorName@WIDECHARCALL@ SQLGetDescField@WIDECHARCALL@ SQLGetDescRec@WIDECHARCALL@ @@ -91,14 +83,12 @@ SQLGetEnvAttr SQLGetFunctions SQLGetInfo@WIDECHARCALL@ SQLGetStmtAttr@WIDECHARCALL@ -SQLGetStmtOption SQLGetTypeInfo@WIDECHARCALL@ SQLMoreResults SQLNativeSql@WIDECHARCALL@ SQLNumParams SQLNumResultCols SQLParamData -SQLParamOptions SQLPrepare@WIDECHARCALL@ SQLPrimaryKeys@WIDECHARCALL@ SQLProcedureColumns@WIDECHARCALL@ @@ -110,17 +100,12 @@ SQLSetDescField@WIDECHARCALL@ SQLSetDescRec@WIDECHARCALL@ SQLSetEnvAttr SQLSetConnectAttr@WIDECHARCALL@ -SQLSetConnectOption@WIDECHARCALL@ -SQLSetParam SQLSetPos -SQLSetScrollOptions SQLSetStmtAttr@WIDECHARCALL@ -SQLSetStmtOption SQLSpecialColumns@WIDECHARCALL@ SQLStatistics@WIDECHARCALL@ SQLTables@WIDECHARCALL@ SQLTablePrivileges@WIDECHARCALL@ -SQLTransact ; DllMain LoadByOrdinal diff --git a/driver/driver.h b/driver/driver.h index b97d9890c..6e219bcd7 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -73,6 +73,8 @@ typedef unsigned int class_id_t; #endif +using std::nullptr_t; + #include "error.h" #include "parse.h" diff --git a/driver/driver.rc.cmake b/driver/driver.rc.cmake index e316458fd..fe7daf22a 100644 --- a/driver/driver.rc.cmake +++ b/driver/driver.rc.cmake @@ -47,51 +47,3 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) MYSQL_LOGO BITMAP DISCARDABLE "..\mysql.bmp" #endif // English (U.S.) resources - -///////////////////////////////////////////////////////////////////////////// -// -// \brief Version information -// -// \note We actually share our version with others (ie setup lib) so -// use the common VersionInfo.h file. -// -#include "..\VersionInfo.h" -VS_VERSION_INFO VERSIONINFO - FILEVERSION MYODBC_FILEVER - PRODUCTVERSION MYODBC_PRODUCTVER - FILEFLAGSMASK 0x3L -#ifdef _DEBUG - FILEFLAGS 0x29L -#else - FILEFLAGS 0x28L -#endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "Comments", "provides core driver functionality\0" - VALUE "CompanyName", "Amazon.com Inc. or affiliates.\0" - VALUE "FileDescription", "MySQL ODBC @CONNECTOR_MAJOR@.@CONNECTOR_MINOR@ @DRIVER_TYPE@ Driver\0" - VALUE "FileVersion", MYODBC_STRFILEVER - VALUE "InternalName", "awsmysqlodbc@CONNECTOR_DRIVER_TYPE_SHORT@\0" - VALUE "LegalCopyright", "Copyright (c) 1995, 2018, Oracle and/or its affiliates.\0" - VALUE "LegalTrademarks", "MySQL, MyODBC, Connector/ODBC are trademarks of Oracle Corporation\0" - VALUE "OriginalFilename", "awsmysqlodbc@CONNECTOR_DRIVER_TYPE_SHORT@.dll\0" - VALUE "PrivateBuild", "Production\0" - VALUE "ProductName", "Connector/ODBC @CONNECTOR_MAJOR@.@CONNECTOR_MINOR@\0" - VALUE "ProductVersion", MYODBC_STRPRODUCTVER - VALUE "SpecialBuild", "@CONNECTOR_QUALITY@ release\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END - - - diff --git a/driver/execute.cc b/driver/execute.cc index d05073fd0..2ac246e71 100644 --- a/driver/execute.cc +++ b/driver/execute.cc @@ -134,52 +134,13 @@ SQLRETURN do_query(STMT *stmt, std::string query) else if (ssps_used(stmt)) { - // This assertion will need to be revisited later. - // The situation when we can have at most one attribute is temporary. - assert( - (stmt->param_count == stmt->query_attr_names.size()) - || (1+stmt->param_count == stmt->query_attr_names.size()) - ); - - bool bind_failed = false; - - // FIXME: What if runtime client library version does not agree with version used here? - -#if MYSQL_VERSION_ID >= 80300 - // For older servers that don't support named params - // we just don't count them and specify the number of unnamed params. - unsigned int p_number = is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "8.3.0") ? - stmt->query_attr_names.size() : stmt->param_count; - - if (p_number) - { - bind_failed = stmt->dbc->connection_proxy->stmt_bind_named_param(stmt->ssps, - stmt->param_bind.data(), p_number, stmt->query_attr_names.data()); - } - -#else - if (stmt->param_bind.size() && stmt->param_count) - { - bind_failed = stmt->dbc->connection_proxy->stmt_bind_param(stmt->ssps, &stmt->param_bind[0]); - } -#endif - - if (!bind_failed) - { - native_error = stmt->dbc->connection_proxy->stmt_execute(stmt->ssps); - } - else - { - stmt->set_error("HY000", - stmt->dbc->connection_proxy->stmt_error(stmt->ssps), - stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); - - /* For some errors - translating to more appropriate status */ - translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_S1000, - stmt->error.native_error); + native_error = stmt->bind_query_attrs(true); + if (native_error == SQL_ERROR) { error = stmt->error.retcode; goto exit; } + + native_error = stmt->dbc->connection_proxy->stmt_execute(stmt->ssps); MYLOG_STMT_TRACE(stmt, "ssps has been executed"); } else @@ -191,7 +152,7 @@ SQLRETURN do_query(STMT *stmt, std::string query) if (stmt->bind_query_attrs(false) == SQL_ERROR) { - error = SQL_ERROR; + error = stmt->error.retcode; goto exit; } diff --git a/driver/handle.cc b/driver/handle.cc index e50d68487..6d190fa19 100644 --- a/driver/handle.cc +++ b/driver/handle.cc @@ -38,11 +38,6 @@ * * * SQLAllocHandle (ISO 92) * * SQLFreeHandle (ISO 92) * - * SQLAllocEnv (ODBC, Deprecated) * - * SQLAllocConnect (ODBC, Deprecated) * - * SQLAllocStmt (ODBC, Deprecated) * - * SQLFreeEnv (ODBC, Deprecated) * - * SQLFreeConnect (ODBC, Deprecated) * * SQLFreeStmt (ISO 92) * * * ****************************************************************************/ @@ -208,19 +203,6 @@ SQLRETURN SQL_API my_SQLAllocEnv(SQLHENV *phenv) } -/* - @type : ODBC 1.0 API - @purpose : to allocate the environment handle -*/ - -SQLRETURN SQL_API SQLAllocEnv(SQLHENV *phenv) -{ - CHECK_ENV_OUTPUT(phenv); - - return my_SQLAllocEnv(phenv); -} - - /* @type : myodbc3 internal @purpose : to free the environment handle @@ -239,17 +221,6 @@ SQLRETURN SQL_API my_SQLFreeEnv(SQLHENV henv) } -/* - @type : ODBC 1.0 API - @purpose : to free the environment handle -*/ -SQLRETURN SQL_API SQLFreeEnv(SQLHENV henv) -{ - CHECK_HANDLE(henv); - - return my_SQLFreeEnv(henv); -} - #ifndef _UNIX_ SQLRETURN my_GetLastError(ENV *henv) { @@ -320,23 +291,6 @@ SQLRETURN SQL_API my_SQLAllocConnect(SQLHENV henv, SQLHDBC *phdbc) } -/* - @type : ODBC 1.0 API - @purpose : to allocate the connection handle and to - maintain the connection list -*/ - -SQLRETURN SQL_API SQLAllocConnect(SQLHENV henv, SQLHDBC *phdbc) -{ - /* Checking only henv because phdbc will be checked later */ - CHECK_HANDLE(henv); - CHECK_DBC_OUTPUT(henv, phdbc); - - return my_SQLAllocConnect(henv, phdbc); -} - - - /* ODBC specs suggest(and that actually makes sense) to do jobs that require communication with server when connection is taken from pool, i.e. at "wakeup" time */ int reset_connection(DBC *dbc) @@ -412,19 +366,6 @@ SQLRETURN SQL_API my_SQLFreeConnect(SQLHDBC hdbc) } -/* - @type : ODBC 1.0 API - @purpose : to allocate the connection handle and to - maintain the connection list -*/ -SQLRETURN SQL_API SQLFreeConnect(SQLHDBC hdbc) -{ - CHECK_HANDLE(hdbc); - - return my_SQLFreeConnect(hdbc); -} - - /* Allocates memory for parameter binds in vector. */ void STMT::allocate_param_bind(uint elements) @@ -477,20 +418,6 @@ SQLRETURN SQL_API my_SQLAllocStmt(SQLHDBC hdbc, SQLHSTMT *phstmt) } -/* - @type : ODBC 1.0 API - @purpose : allocates the statement handle -*/ - -SQLRETURN SQL_API SQLAllocStmt(SQLHDBC hdbc,SQLHSTMT *phstmt) -{ - CHECK_HANDLE(hdbc); - CHECK_STMT_OUTPUT(hdbc, phstmt); - - return my_SQLAllocStmt(hdbc,phstmt); -} - - /* @type : ODBC 1.0 API @purpose : stops processing associated with a specific statement, diff --git a/driver/info.cc b/driver/info.cc index 7697cbf3f..b329ea3de 100644 --- a/driver/info.cc +++ b/driver/info.cc @@ -1221,15 +1221,16 @@ List of functions supported in the driver. */ SQLUSMALLINT myodbc3_functions[] = { - SQL_API_SQLALLOCCONNECT, - SQL_API_SQLALLOCENV, SQL_API_SQLALLOCHANDLE, - SQL_API_SQLALLOCSTMT, SQL_API_SQLBINDCOL, - /* SQL_API_SQLBINDPARAM */ + SQL_API_SQLBINDPARAM, SQL_API_SQLCANCEL, #ifndef USE_IODBC SQL_API_SQLCANCELHANDLE, +#else + SQL_API_SQLGETSTMTOPTION, + SQL_API_SQLSETSTMTOPTION, + SQL_API_SQLPARAMOPTIONS, #endif SQL_API_SQLCLOSECURSOR, SQL_API_SQLCOLATTRIBUTE, @@ -1240,17 +1241,13 @@ SQLUSMALLINT myodbc3_functions[] = SQL_API_SQLDESCRIBECOL, SQL_API_SQLDISCONNECT, SQL_API_SQLENDTRAN, - SQL_API_SQLERROR, SQL_API_SQLEXECDIRECT, SQL_API_SQLEXECUTE, SQL_API_SQLFETCH, SQL_API_SQLFETCHSCROLL, - SQL_API_SQLFREECONNECT, - SQL_API_SQLFREEENV, SQL_API_SQLFREEHANDLE, SQL_API_SQLFREESTMT, SQL_API_SQLGETCONNECTATTR, - SQL_API_SQLGETCONNECTOPTION, SQL_API_SQLGETCURSORNAME, SQL_API_SQLGETDATA, SQL_API_SQLGETDESCFIELD, @@ -1261,7 +1258,6 @@ SQLUSMALLINT myodbc3_functions[] = SQL_API_SQLGETFUNCTIONS, SQL_API_SQLGETINFO, SQL_API_SQLGETSTMTATTR, - SQL_API_SQLGETSTMTOPTION, SQL_API_SQLGETTYPEINFO, SQL_API_SQLNUMRESULTCOLS, SQL_API_SQLPARAMDATA, @@ -1269,23 +1265,18 @@ SQLUSMALLINT myodbc3_functions[] = SQL_API_SQLPUTDATA, SQL_API_SQLROWCOUNT, SQL_API_SQLSETCONNECTATTR, - SQL_API_SQLSETCONNECTOPTION, SQL_API_SQLSETCURSORNAME, SQL_API_SQLSETDESCFIELD, SQL_API_SQLSETDESCREC, SQL_API_SQLSETENVATTR, - SQL_API_SQLSETPARAM, SQL_API_SQLSETSTMTATTR, - SQL_API_SQLSETSTMTOPTION, SQL_API_SQLSPECIALCOLUMNS, SQL_API_SQLSTATISTICS, SQL_API_SQLTABLES, - SQL_API_SQLTRANSACT, - /* SQL_API_SQLALLOCHANDLESTD */ SQL_API_SQLBULKOPERATIONS, SQL_API_SQLBINDPARAMETER, SQL_API_SQLBROWSECONNECT, - SQL_API_SQLCOLATTRIBUTES, + SQL_API_SQLCOLATTRIBUTE, SQL_API_SQLCOLUMNPRIVILEGES , SQL_API_SQLDESCRIBEPARAM, SQL_API_SQLDRIVERCONNECT, @@ -1295,12 +1286,10 @@ SQLUSMALLINT myodbc3_functions[] = SQL_API_SQLMORERESULTS, SQL_API_SQLNATIVESQL, SQL_API_SQLNUMPARAMS, - SQL_API_SQLPARAMOPTIONS, SQL_API_SQLPRIMARYKEYS, SQL_API_SQLPROCEDURECOLUMNS, SQL_API_SQLPROCEDURES, SQL_API_SQLSETPOS, - SQL_API_SQLSETSCROLLOPTIONS, SQL_API_SQLTABLEPRIVILEGES }; @@ -1361,4 +1350,5 @@ SQLRETURN SQL_API SQLGetFunctions(SQLHDBC hdbc __attribute__((unused)), } return SQL_SUCCESS; -} \ No newline at end of file +} + diff --git a/driver/my_prepared_stmt.cc b/driver/my_prepared_stmt.cc index 09db3542c..06be66614 100644 --- a/driver/my_prepared_stmt.cc +++ b/driver/my_prepared_stmt.cc @@ -710,7 +710,9 @@ void STMT::free_fake_result(bool clear_all_results) { result->field_alloc->Clear(); } - + // Result array must be reset for fake resultset. + // Otherwise the data in the next resultset might be corrupted. + reset_result_array(); stmt_result_free(this); } @@ -1005,14 +1007,6 @@ bool STMT::query_attr_exists(const char *name) SQLRETURN STMT::bind_query_attrs(bool use_ssps) { - if (use_ssps) - { - set_error(MYERR_01000, - "Query attributes for prepared statements are not supported", - 0); - return SQL_SUCCESS_WITH_INFO; - } - uint rcount = (uint)apd->rcount(); if (rcount < param_count) { @@ -1061,6 +1055,44 @@ SQLRETURN STMT::bind_query_attrs(bool use_ssps) ++param_idx; } + if (use_ssps) + { + bool bind_failed = false; +#if MYSQL_VERSION_ID >= 80300 + + // For older servers that don't support named params + // we just don't count them and specify the number of unnamed params. + unsigned int p_number = + dbc->connection_proxy->get_server_capabilities() & CLIENT_QUERY_ATTRIBUTES + ? query_attr_names.size() : param_count; + + if (p_number) { + bind_failed = + mysql_stmt_bind_named_param(ssps, param_bind.data(), + p_number, query_attr_names.data()); + } + +#else + if (param_bind.size() && param_count) { + bind_failed = mysql_stmt_bind_param(ssps, param_bind.data()); + } +#endif + + if (bind_failed) + { + set_error("HY000", mysql_stmt_error(ssps), + mysql_stmt_errno(ssps)); + + /* For some errors - translating to more appropriate status */ + translate_error((char *)error.sqlstate.c_str(), MYERR_S1000, + error.native_error); + return SQL_ERROR; + } + + return SQL_SUCCESS; + } + + MYSQL_BIND *bind = param_bind.data(); const char** names = (const char**)query_attr_names.data(); diff --git a/driver/my_stmt.cc b/driver/my_stmt.cc index f0915aaa2..e90fc28ab 100644 --- a/driver/my_stmt.cc +++ b/driver/my_stmt.cc @@ -447,7 +447,9 @@ SQLRETURN prepare(STMT *stmt, char * query, SQLINTEGER query_length, if (reset_sql_limit) set_sql_select_limit(stmt->dbc, 0, false); - int prep_res = stmt->dbc->connection_proxy->stmt_prepare(stmt->ssps, query, query_length); + // After the parse and removal of curly brackets from the query + // the result string for prepare is inside stmt->query. + int prep_res = stmt->dbc->connection_proxy->stmt_prepare(stmt->ssps, query, (unsigned long)stmt->query.length()); if (prep_res) { diff --git a/driver/myutil.h b/driver/myutil.h index 5b4b43364..494d664f6 100755 --- a/driver/myutil.h +++ b/driver/myutil.h @@ -87,7 +87,7 @@ typedef char * DYNAMIC_ELEMENT; // Handle the removal of `def` and `def_length` // from MYSQL_FIELD struct in MySQL 8.3.0 -#if MYSQL_VERSION_ID >= 80300 +#if MYSQL_VERSION_ID == 80300 #define MYSQL_FIELD_DEF #define MYSQL_FIELD_DEF_LENGTH #else diff --git a/driver/options.cc b/driver/options.cc index 8b34c0cba..de5601721 100644 --- a/driver/options.cc +++ b/driver/options.cc @@ -996,6 +996,10 @@ SQLGetEnvAttr(SQLHENV henv, return SQL_SUCCESS; } +#ifdef USE_IODBC + +// iODBC has problems mapping SQLGetStmtOption()/SQLSetStmtOption() to +// SQLGetStmtAttr()/SQLSetStmtAttr() SQLRETURN SQL_API SQLGetStmtOption(SQLHSTMT hstmt,SQLUSMALLINT option, SQLPOINTER param) @@ -1013,3 +1017,6 @@ SQLSetStmtOption(SQLHSTMT hstmt, SQLUSMALLINT option, SQLULEN param) return MySQLSetStmtAttr(hstmt, option, (SQLPOINTER)param, SQL_NTS); } + +#endif + diff --git a/driver/parse.h b/driver/parse.h index 2f525a2f7..5adc25e48 100644 --- a/driver/parse.h +++ b/driver/parse.h @@ -173,6 +173,7 @@ struct MY_PARSED_QUERY const char *get_cursor_name(); size_t token_count(); bool is_select_statement(); + size_t length() { return query_end - query; } }; diff --git a/driver/prepare.cc b/driver/prepare.cc index 2453d7d00..40396c1a3 100644 --- a/driver/prepare.cc +++ b/driver/prepare.cc @@ -39,9 +39,7 @@ * SQLPrepare (ISO 92) * * SQLBindParameter (ODBC) * * SQLDescribeParam (ODBC) * - * SQLParamOptions (ODBC, Deprecated) * * SQLNumParams (ISO 92) * - * SQLSetScrollOptions (ODBC, Deprecated) * * * ****************************************************************************/ @@ -250,39 +248,6 @@ SQLRETURN SQL_API my_SQLBindParameter( SQLHSTMT StatementHandle, } -/** - Deprecated function, for more details see SQLBindParamater. - - @param[in] stmt Handle to statement - @param[in] ipar Parameter number - @param[in] fCType Value type - @param[in] fSqlType Parameter type - @param[in] cbColDef Column size - @param[in] ibScale Decimal digits - @param[in] rgbValue Parameter value pointer - @param[in] pcbValue String length or index pointer - - @return SQL_SUCCESS or SQL_ERROR (and diag is set) - -*/ - -SQLRETURN SQL_API SQLSetParam(SQLHSTMT hstmt, - SQLUSMALLINT ipar, - SQLSMALLINT fCType, - SQLSMALLINT fSqlType, - SQLULEN cbColDef, - SQLSMALLINT ibScale, - SQLPOINTER rgbValue, - SQLLEN * pcbValue) -{ - LOCK_STMT(hstmt); - - return my_SQLBindParameter(hstmt, ipar, SQL_PARAM_INPUT_OUTPUT, fCType, - fSqlType, cbColDef, ibScale, rgbValue, - SQL_SETPARAM_VALUE_MAX, pcbValue); -} - - /* @type : ODBC 2.0 API @purpose : binds a buffer to a parameter marker in an SQL statement. @@ -335,9 +300,14 @@ SQLRETURN SQL_API SQLDescribeParam( SQLHSTMT hstmt, } +#ifdef USE_IODBC + /* @type : ODBC 1.0 API @purpose : sets multiple values (arrays) for the set of parameter markers + + NOTE: iODBC has problems mapping SQLParamOptions() to SQLSetStmtAttr() and + therefore it has to stay. */ #ifdef USE_SQLPARAMOPTIONS_SQLULEN_PTR @@ -362,6 +332,7 @@ SQLRETURN SQL_API SQLParamOptions( SQLHSTMT hstmt, rc= MySQLSetStmtAttr(stmt, SQL_ATTR_PARAMS_PROCESSED_PTR, pirow, 0); return rc; } +#endif /* @@ -380,24 +351,3 @@ SQLRETURN SQL_API SQLNumParams(SQLHSTMT hstmt, SQLSMALLINT *pcpar) return SQL_SUCCESS; } - - -/* - @type : ODBC 1.0 API - @purpose : sets options that control the behavior of cursors. -*/ - -SQLRETURN SQL_API SQLSetScrollOptions( SQLHSTMT hstmt, - SQLUSMALLINT fConcurrency __attribute__((unused)), - SQLLEN crowKeyset __attribute__((unused)), - SQLUSMALLINT crowRowset ) -{ - STMT *stmt= (STMT *)hstmt; - - CHECK_HANDLE(hstmt); - - return stmt_SQLSetDescField(stmt, stmt->ard, 0, SQL_DESC_ARRAY_SIZE, - (SQLPOINTER)(size_t)crowRowset, - SQL_IS_USMALLINT); -} - diff --git a/driver/transact.cc b/driver/transact.cc index 33940d29b..1db99f211 100644 --- a/driver/transact.cc +++ b/driver/transact.cc @@ -157,28 +157,3 @@ SQLEndTran(SQLSMALLINT HandleType, return end_transaction(HandleType, Handle, CompletionType); } - - -/** - Commit or roll back the transactions associated with a particular - database connection, or all connections in an environment. - - @deprecated This function is deprecated, SQLEndTran() should be used instead. - - @param[in] henv Handle to database environment - @param[in] hdbc Handle to database connection - @param[in] fType How to complete the transactions, - @c SQL_COMMIT or @c SQL_ROLLBACK - - @since ODBC 1.0 -*/ -SQLRETURN SQL_API SQLTransact(SQLHENV henv, - SQLHDBC hdbc, - SQLUSMALLINT fType) -{ - if(henv == NULL && hdbc == NULL) - return SQL_INVALID_HANDLE; - - return end_transaction(hdbc ? SQL_HANDLE_DBC : SQL_HANDLE_ENV, - hdbc ? hdbc : henv, fType); -} diff --git a/driver/unicode.cc b/driver/unicode.cc index 0983cf2b1..954f9eac4 100644 --- a/driver/unicode.cc +++ b/driver/unicode.cc @@ -129,18 +129,6 @@ SQLColAttributeWImpl(SQLHSTMT hstmt, SQLUSMALLINT column, } -SQLRETURN SQL_API -SQLColAttributesW(SQLHSTMT hstmt, SQLUSMALLINT column, SQLUSMALLINT field, - SQLPOINTER char_attr, SQLSMALLINT char_attr_max, - SQLSMALLINT *char_attr_len, SQLLEN *num_attr) -{ - LOCK_STMT(hstmt); - - return SQLColAttributeWImpl(hstmt, column, field, char_attr, char_attr_max, - char_attr_len, num_attr); -} - - SQLRETURN SQL_API SQLColumnPrivilegesW(SQLHSTMT hstmt, SQLWCHAR *catalog, SQLSMALLINT catalog_len, @@ -327,36 +315,6 @@ SQLDescribeColW(SQLHSTMT hstmt, SQLUSMALLINT column, } -SQLRETURN SQL_API -SQLErrorW(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, SQLWCHAR *sqlstate, - SQLINTEGER *native_error, SQLWCHAR *message, SQLSMALLINT message_max, - SQLSMALLINT *message_len) -{ - SQLRETURN rc= SQL_INVALID_HANDLE; - - if (hstmt) - { - rc= SQLGetDiagRecWImpl(SQL_HANDLE_STMT, hstmt, NEXT_STMT_ERROR(hstmt), - sqlstate, native_error, message, message_max, - message_len); - } - else if (hdbc) - { - rc= SQLGetDiagRecWImpl(SQL_HANDLE_DBC, hdbc, NEXT_DBC_ERROR(hdbc), - sqlstate, native_error, message, message_max, - message_len); - } - else if (henv) - { - rc= SQLGetDiagRecWImpl(SQL_HANDLE_ENV, henv, NEXT_ENV_ERROR(henv), - sqlstate, native_error, message, message_max, - message_len); - } - - return rc; -} - - SQLRETURN SQL_API SQLExecDirectW(SQLHSTMT hstmt, SQLWCHAR *str, SQLINTEGER str_len) { @@ -514,17 +472,6 @@ SQLGetConnectAttrWImpl(SQLHDBC hdbc, SQLINTEGER attribute, SQLPOINTER value, } -SQLRETURN SQL_API -SQLGetConnectOptionW(SQLHDBC hdbc, SQLUSMALLINT option, SQLPOINTER param) -{ - CHECK_HANDLE(hdbc); - - return SQLGetConnectAttrWImpl(hdbc, option, param, - ((option == SQL_ATTR_CURRENT_CATALOG) ? - SQL_MAX_OPTION_STRING_LENGTH : 0), NULL); -} - - SQLRETURN SQL_API SQLGetCursorNameW(SQLHSTMT hstmt, SQLWCHAR *cursor, SQLSMALLINT cursor_max, SQLSMALLINT *cursor_len) @@ -1083,17 +1030,6 @@ SQLSetCursorNameW(SQLHSTMT hstmt, SQLWCHAR *name, SQLSMALLINT name_len) } -SQLRETURN SQL_API -SQLSetConnectOptionW(SQLHDBC hdbc, SQLUSMALLINT option, SQLULEN param) -{ - CHECK_HANDLE(hdbc); - - return SQLSetConnectAttrWImpl(hdbc, option, (SQLPOINTER)param, - ((option == SQL_ATTR_CURRENT_CATALOG) ? - SQL_NTS : 0)); -} - - SQLRETURN SQL_API SQLSetStmtAttrW(SQLHSTMT hstmt, SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER value_len) diff --git a/driver/utility.cc b/driver/utility.cc index ab2322ba6..53bec1d27 100755 --- a/driver/utility.cc +++ b/driver/utility.cc @@ -1102,7 +1102,16 @@ std::map sql_data_types_map = { SQLSMALLINT get_sql_data_type_from_str(const char *mysql_type_name) { - return sql_data_types_map.at(mysql_type_name); + try + { + return sql_data_types_map.at(mysql_type_name); + } + catch(const std::out_of_range&) + { + return SQL_UNKNOWN_TYPE; + } + // Keep compiler happy + return SQL_UNKNOWN_TYPE; } SQLSMALLINT compute_sql_data_type(STMT *stmt, SQLSMALLINT sql_type, diff --git a/extra/otel/CMakeLists.txt b/extra/otel/CMakeLists.txt index 18c8c68e5..184ac47a7 100644 --- a/extra/otel/CMakeLists.txt +++ b/extra/otel/CMakeLists.txt @@ -1,21 +1,25 @@ -# -# Copyright (c) 2022, 2023, Oracle and/or its affiliates. -# -project(otel) - -add_subdirectory(opentelemetry-cpp-1.8.3/api) - -# Export targets - -export( - TARGETS -# Note: opentelemetry_api is header-only -- see the generated exports.cmake - opentelemetry_api -# TODO: Are these really needed for our purposes? It seems these libraires -# depend on opentelemetry_sdk and we should not need to link to SDK -# opentelemetry_common -# opentelemetry_resources -# opentelemetry_trace - NAMESPACE otel_ - FILE "${PROJECT_BINARY_DIR}/exports.cmake" -) +SET(OPENTELEMETRY_CPP_TAG "opentelemetry-cpp-1.10.0" CACHE INTERNAL "") + +add_library(otel_api INTERFACE) + +# Note: For now make it phony target on platforms other than Linux + +if(NOT (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME MATCHES "SunOS")) + + message(STATUS "Adding OTel support") + + set(TELEMETRY ON CACHE INTERNAL "Whether connector is built with OTel support") + + target_include_directories(otel_api INTERFACE + "${PROJECT_SOURCE_DIR}/extra/otel/${OPENTELEMETRY_CPP_TAG}/api/include" + ) + + target_compile_definitions(otel_api INTERFACE TELEMETRY) + + if(WIN32) + # Note: warning C4996 is triggered by OTel headers (as of version 1.10.0) + target_compile_definitions(otel_api INTERFACE _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING) + endif() + +endif() + diff --git a/extra/otel/README.txt b/extra/otel/README.txt index 99c8e9c22..053d44dc6 100644 --- a/extra/otel/README.txt +++ b/extra/otel/README.txt @@ -1,69 +1,23 @@ -# Copyright (c) 2022, 2023, Oracle and/or its affiliates. +How to update the bundled version of opentelemetry-cpp +====================================================== -HOWTO import a new opentelemetry-cpp package +We use copy of opentelemetry-cpp sources that are bundled with the server +(note that server potentially patches the original sources). When server +starts to bundle new version X.Y.Z the following should be done to update +our copy: -Using release 1.6.0 as an example, adjust to the proper release number. +1. Delete the current opentelemtetry-cpp-* subfolder from this folder. -1) Read the release notes +2. Copy folder opentelemetry-cpp-X.Y.Z from the server source tree to this + folder. -https://github.com/open-telemetry/opentelemetry-cpp/releases/tag/v1.6.0 +3. Inside opentelemtry-cpp-X.Y.Z delete everything except api/ subfolder + and LICENSE file. -If opentelemetry-cpp upgraded its own dependencies, -the following packages may need to be upgraded as well: +4. Inside CMakeLists.txt in this folder update OPENTELEMETRY_CPP_TAG + variable: -- internal/extra/json -- internal/extra/opentelemetry-proto - -2) Download the .tar.gz - -https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.6.0.tar.gz - -3) Unpack the .tar.gz in a sub directory - -cd internal/extra/opentelemetry-cpp -tar xvf opentelemetry-cpp-1.6.0.tar.gz - -This should create a directory named internal/extra/opentelemetry-cpp/opentelemetry-cpp-1.6.0 - -Code for a package MUST be in a dedicated sub directory. - -4) Remove un necessary code - -cd internal/extra/opentelemetry-cpp/opentelemetry-cpp-1.6.0 - -5) Commit and push. - -It is important to have a separate commit for the import alone, -for the git history. - -At this point, the new code is imported, but not used yet. - -6) Adjust CMake - -In internal/cmake/opentelemetry-cpp.cmake, -point the tag to the new release - -SET(OPENTELEMETRY_CPP_TAG "opentelemetry-cpp-1.6.0") - -7) Do a full build and test - -In particular, make sure the code still builds in MYSQL_MAINTAINER_MODE, -and adjust warnings flags for third party code if needed. - -See internal/extra/opentelemetry-cpp/CMakeFiles.txt - -8) Commit and push. - -At this point, the new code is used, -and the old code is still in the repository. - -9) Cleanup the previous release - -cd internal/extra/opentelemetry-cpp/ -rm -rf opentelemetry-cpp- - -10) Commit and push. - -It is important to have a separate commit for the cleanup alone, -for the git history. + set(OPENTELEMETRY_CPP_TAG "opentelemetry-cpp-X.Y.Z" CACHE INTERNAL "") +3. Build and test connector on a platform on which we support OTel (Linux) + to confirm that it works as before. diff --git a/extra/otel/opentelemetry-cpp-1.8.3/LICENSE b/extra/otel/opentelemetry-cpp-1.10.0/LICENSE similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/LICENSE rename to extra/otel/opentelemetry-cpp-1.10.0/LICENSE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/README.md b/extra/otel/opentelemetry-cpp-1.10.0/README.md similarity index 97% rename from extra/otel/opentelemetry-cpp-1.8.3/README.md rename to extra/otel/opentelemetry-cpp-1.10.0/README.md index fac6bcbb4..6dd56949f 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/README.md +++ b/extra/otel/opentelemetry-cpp-1.10.0/README.md @@ -52,7 +52,7 @@ of the current project. | Windows Server 2022 (Visual Studio Enterprise 2022) | CMake | [1]: Bazel build is disabled for GCC 4.8, as gRPC library 1.38 and above - (required by OTLP expoter) don't build with this compiler. See gRPC [official + (required by OTLP exporter) don't build with this compiler. See gRPC [official support](https://grpc.io/docs/#official-support) document. CMake build doesn't build OTLP exporter with GCC 4.8. @@ -98,14 +98,13 @@ For edit access, get in touch on * [Ehsan Saei](https://github.com/esigo) * [Lalit Kumar Bhasin](https://github.com/lalitb), Microsoft +* [Marc Alff](https://github.com/marcalff), Oracle * [Tom Tan](https://github.com/ThomsonTan), Microsoft [Approvers](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver) ([@open-telemetry/cpp-approvers](https://github.com/orgs/open-telemetry/teams/cpp-approvers)): * [Josh Suereth](https://github.com/jsuereth), Google -* [Marc Alff](https://github.com/marcalff), Oracle -* [Reiley Yang](https://github.com/reyang), Microsoft * [WenTao Ou](https://github.com/owent), Tencent [Emeritus @@ -116,6 +115,7 @@ Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/ma * [Jodee Varney](https://github.com/jodeev) * [Johannes Tax](https://github.com/pyohannes) * [Max Golovanov](https://github.com/maxgolov) +* [Reiley Yang](https://github.com/reyang) * [Ryan Burn](https://github.com/rnburn) ### Thanks to all the people who have contributed diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/BUILD new file mode 100644 index 000000000..421d26a62 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/BUILD @@ -0,0 +1,34 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + +package(default_visibility = ["//visibility:public"]) + +bool_flag( + name = "with_abseil", + build_setting_default = False, +) + +cc_library( + name = "api", + hdrs = glob(["include/**/*.h"]), + defines = select({ + ":with_external_abseil": ["HAVE_ABSEIL"], + "//conditions:default": [], + }), + strip_include_prefix = "include", + tags = ["api"], + deps = select({ + ":with_external_abseil": [ + "@com_google_absl//absl/base", + "@com_google_absl//absl/types:variant", + ], + "//conditions:default": [], + }), +) + +config_setting( + name = "with_external_abseil", + flag_values = {":with_abseil": "true"}, +) diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/CMakeLists.txt similarity index 68% rename from extra/otel/opentelemetry-cpp-1.8.3/api/CMakeLists.txt rename to extra/otel/opentelemetry-cpp-1.10.0/api/CMakeLists.txt index 6b3f13705..8c6b6655a 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/CMakeLists.txt +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/CMakeLists.txt @@ -46,9 +46,14 @@ if(WITH_NO_DEPRECATED_CODE) INTERFACE OPENTELEMETRY_NO_DEPRECATED_CODE) endif() -if(WITH_ABSEIL) - - find_package(absl CONFIG REQUIRED) +if(TELEMETRY_WITH_ABSEIL) + IF(WITH_PROTOBUF STREQUAL "bundled") + INCLUDE_DIRECTORIES(BEFORE SYSTEM + "${BUNDLED_PROTO_SRCDIR}" + "${BUNDLED_ABSEIL_SRCDIR}") + ELSE() + find_package(absl CONFIG REQUIRED) + ENDIF() target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL) target_link_libraries( @@ -58,10 +63,10 @@ if(WITH_ABSEIL) endif() if(WITH_STL) - message("Building with standard library types...") + message(STATUS "Building with standard library types...") target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB) else() - message("Building with nostd types...") + message(STATUS "Building with nostd types...") endif() if(WITH_GSL) @@ -98,6 +103,31 @@ if(WITH_ASYNC_EXPORT_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT) endif() +if(WITH_REMOVE_METER_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_REMOVE_METER_PREVIEW) +endif() + +# A better place should be in sdk, not api +if(WITH_OTLP_HTTP_SSL_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_OTLP_HTTP_SSL_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_HTTP_SSL_PREVIEW) + + if(WITH_OTLP_HTTP_SSL_TLS_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_OTLP_HTTP_SSL_TLS_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_HTTP_SSL_TLS_PREVIEW) + endif() +endif() + +if(WITH_OTLP_GRPC_SSL_MTLS_PREVIEW) + target_compile_definitions(opentelemetry_api + INTERFACE ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW) +endif() + if(WITH_METRICS_EXEMPLAR_PREVIEW) target_compile_definitions(opentelemetry_api INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW) diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/baggage.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/baggage.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/baggage.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/baggage.h index 66a77ed94..66eb9d983 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/baggage.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/baggage.h @@ -26,14 +26,12 @@ class OPENTELEMETRY_EXPORT Baggage static constexpr char kMembersSeparator = ','; static constexpr char kMetadataSeparator = ';'; - Baggage() noexcept : kv_properties_(new opentelemetry::common::KeyValueProperties()) {} - Baggage(size_t size) noexcept - : kv_properties_(new opentelemetry::common::KeyValueProperties(size)) - {} + Baggage() noexcept : kv_properties_(new common::KeyValueProperties()) {} + Baggage(size_t size) noexcept : kv_properties_(new common::KeyValueProperties(size)) {} template Baggage(const T &keys_and_values) noexcept - : kv_properties_(new opentelemetry::common::KeyValueProperties(keys_and_values)) + : kv_properties_(new common::KeyValueProperties(keys_and_values)) {} OPENTELEMETRY_API_SINGLETON static nostd::shared_ptr GetDefault() @@ -293,7 +291,7 @@ class OPENTELEMETRY_EXPORT Baggage private: // Store entries in a C-style array to avoid using std::array or std::vector. - nostd::unique_ptr kv_properties_; + nostd::unique_ptr kv_properties_; }; } // namespace baggage diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/baggage_context.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/baggage_context.h new file mode 100644 index 000000000..e5b9556d3 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/baggage_context.h @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/baggage/baggage.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE + +namespace baggage +{ + +static const std::string kBaggageHeader = "baggage"; + +inline nostd::shared_ptr GetBaggage(const context::Context &context) noexcept +{ + context::ContextValue context_value = context.GetValue(kBaggageHeader); + if (nostd::holds_alternative>(context_value)) + { + return nostd::get>(context_value); + } + static nostd::shared_ptr empty_baggage{new Baggage()}; + return empty_baggage; +} + +inline context::Context SetBaggage(context::Context &context, + nostd::shared_ptr baggage) noexcept +{ + return context.SetValue(kBaggageHeader, baggage); +} + +} // namespace baggage +OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/propagation/baggage_propagator.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/propagation/baggage_propagator.h similarity index 52% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/propagation/baggage_propagator.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/propagation/baggage_propagator.h index 3de60860b..6de32882c 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/propagation/baggage_propagator.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/baggage/propagation/baggage_propagator.h @@ -14,13 +14,13 @@ namespace baggage namespace propagation { -class BaggagePropagator : public opentelemetry::context::propagation::TextMapPropagator +class BaggagePropagator : public context::propagation::TextMapPropagator { public: - void Inject(opentelemetry::context::propagation::TextMapCarrier &carrier, - const opentelemetry::context::Context &context) noexcept override + void Inject(context::propagation::TextMapCarrier &carrier, + const context::Context &context) noexcept override { - auto baggage = opentelemetry::baggage::GetBaggage(context); + auto baggage = baggage::GetBaggage(context); auto header = baggage->ToHeader(); if (header.size()) { @@ -28,15 +28,15 @@ class BaggagePropagator : public opentelemetry::context::propagation::TextMapPro } } - context::Context Extract(const opentelemetry::context::propagation::TextMapCarrier &carrier, - opentelemetry::context::Context &context) noexcept override + context::Context Extract(const context::propagation::TextMapCarrier &carrier, + context::Context &context) noexcept override { - nostd::string_view baggage_str = carrier.Get(opentelemetry::baggage::kBaggageHeader); - auto baggage = opentelemetry::baggage::Baggage::FromHeader(baggage_str); + nostd::string_view baggage_str = carrier.Get(baggage::kBaggageHeader); + auto baggage = baggage::Baggage::FromHeader(baggage_str); if (baggage->ToHeader().size()) { - return opentelemetry::baggage::SetBaggage(context, baggage); + return baggage::SetBaggage(context, baggage); } else { diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/attribute_value.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/attribute_value.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/attribute_value.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/attribute_value.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/key_value_iterable.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/key_value_iterable.h similarity index 97% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/key_value_iterable.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/key_value_iterable.h index 732d361e7..9d43e1571 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/key_value_iterable.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/key_value_iterable.h @@ -5,6 +5,7 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/key_value_iterable_view.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/key_value_iterable_view.h similarity index 98% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/key_value_iterable_view.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/key_value_iterable_view.h index daea8fce2..fb1a6ea01 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/key_value_iterable_view.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/key_value_iterable_view.h @@ -4,10 +4,10 @@ #pragma once #include -#include #include #include "opentelemetry/common/key_value_iterable.h" +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/kv_properties.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/kv_properties.h similarity index 99% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/kv_properties.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/kv_properties.h index 96442021b..00fa2571c 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/kv_properties.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/kv_properties.h @@ -6,7 +6,6 @@ #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/common/string_util.h" #include "opentelemetry/nostd/function_ref.h" -#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/version.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/macros.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/macros.h similarity index 86% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/macros.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/macros.h index 323e5cdc0..dd40c63bf 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/macros.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/macros.h @@ -10,6 +10,7 @@ # define OPENTELEMETRY_LIKELY_IF(...) \ if (__VA_ARGS__) \ [[likely]] + # endif # endif #endif @@ -176,6 +177,31 @@ point. #endif +// +// Atomic wrappers based on compiler intrinsics for memory read/write. +// The tailing number is read/write length in bits. +// +// N.B. Compiler instrinsic is used because the usage of C++ standard library is restricted in the +// OpenTelemetry C++ API. +// +#if defined(__GNUC__) + +# define OPENTELEMETRY_ATOMIC_READ_8(ptr) __atomic_load_n(ptr, __ATOMIC_SEQ_CST) +# define OPENTELEMETRY_ATOMIC_WRITE_8(ptr, value) __atomic_store_n(ptr, value, __ATOMIC_SEQ_CST) + +#elif defined(_MSC_VER) + +# include + +# define OPENTELEMETRY_ATOMIC_READ_8(ptr) \ + static_cast(_InterlockedCompareExchange8(reinterpret_cast(ptr), 0, 0)) +# define OPENTELEMETRY_ATOMIC_WRITE_8(ptr, value) \ + _InterlockedExchange8(reinterpret_cast(ptr), static_cast(value)) + +#else +# error port atomics read/write for the current platform +#endif + /* clang-format on */ // // The if/elif order matters here. If both OPENTELEMETRY_BUILD_IMPORT_DLL and diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/spin_lock_mutex.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/spin_lock_mutex.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/spin_lock_mutex.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/spin_lock_mutex.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/string_util.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/string_util.h similarity index 78% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/string_util.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/string_util.h index 5496f8579..a7070a0ac 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/string_util.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/string_util.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace common @@ -14,11 +15,11 @@ class StringUtil public: static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept { - while (str[static_cast(left)] == ' ' && left <= right) + while (left <= right && str[static_cast(left)] == ' ') { left++; } - while (str[static_cast(right)] == ' ' && left <= right) + while (left <= right && str[static_cast(right)] == ' ') { right--; } diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/timestamp.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/timestamp.h similarity index 99% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/timestamp.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/timestamp.h index da8765b9b..14aa457b5 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/common/timestamp.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/common/timestamp.h @@ -3,7 +3,6 @@ #pragma once -#include #include #include diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/config.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/config.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/config.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/config.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/context.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/context.h similarity index 99% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/context.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/context.h index 923b396c7..d0b53c3ea 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/context.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/context.h @@ -7,6 +7,7 @@ #include "opentelemetry/context/context_value.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace context diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/context_value.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/context_value.h similarity index 78% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/context_value.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/context_value.h index 013b3a460..27bd40fb0 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/context_value.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/context_value.h @@ -5,16 +5,22 @@ #include -#include "opentelemetry/baggage/baggage.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/nostd/variant.h" -#include "opentelemetry/trace/span.h" -#include "opentelemetry/trace/span_context.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace baggage +{ +class Baggage; +} // namespace baggage + +namespace trace +{ +class Span; +class SpanContext; +} // namespace trace + namespace context { using ContextValue = nostd::variant #include #include + #include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace context diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/global_propagator.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/global_propagator.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/global_propagator.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/global_propagator.h index 460764a74..a62146e10 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/global_propagator.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/global_propagator.h @@ -6,7 +6,6 @@ #include #include "opentelemetry/context/propagation/noop_propagator.h" -#include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/common/macros.h" #include "opentelemetry/common/spin_lock_mutex.h" @@ -20,6 +19,8 @@ namespace context namespace propagation { +class TextMapPropagator; + /* Stores the singleton TextMapPropagator */ class OPENTELEMETRY_EXPORT GlobalTextMapPropagator diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/noop_propagator.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/noop_propagator.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/noop_propagator.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/noop_propagator.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/text_map_propagator.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/text_map_propagator.h similarity index 97% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/text_map_propagator.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/text_map_propagator.h index bb0c6d802..21bc29361 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/propagation/text_map_propagator.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/propagation/text_map_propagator.h @@ -3,8 +3,8 @@ #pragma once -#include #include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/runtime_context.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/runtime_context.h similarity index 98% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/runtime_context.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/runtime_context.h index bec96a9af..2cd5b0ff9 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/context/runtime_context.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/context/runtime_context.h @@ -5,6 +5,10 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace context diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/detail/preprocessor.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/detail/preprocessor.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/detail/preprocessor.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/detail/preprocessor.h diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_id.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_id.h new file mode 100644 index 000000000..60d020827 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_id.h @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef ENABLE_LOGS_PREVIEW + +# include + +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/nostd/unique_ptr.h" +# include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace logs +{ + +/** + * EventId class which acts the Id of the event with an optional name. + */ +class EventId +{ +public: + EventId(int64_t id, nostd::string_view name) noexcept : id_{id} + { + name_ = nostd::unique_ptr{new char[name.length() + 1]}; + std::copy(name.begin(), name.end(), name_.get()); + name_.get()[name.length()] = 0; + } + + EventId(int64_t id) noexcept : id_{id}, name_{nullptr} {} + +public: + int64_t id_; + nostd::unique_ptr name_; +}; + +} // namespace logs +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/event_logger.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_logger.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/event_logger.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_logger.h index 654c6f6c6..c87997816 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/event_logger.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_logger.h @@ -4,15 +4,9 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW -# include -# include -# include - -# include "opentelemetry/common/macros.h" # include "opentelemetry/logs/log_record.h" # include "opentelemetry/logs/logger.h" # include "opentelemetry/logs/logger_type_traits.h" -# include "opentelemetry/logs/severity.h" # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/string_view.h" # include "opentelemetry/nostd/unique_ptr.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/event_logger_provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_logger_provider.h similarity index 76% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/event_logger_provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_logger_provider.h index 8692222c1..06170dcca 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/event_logger_provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/event_logger_provider.h @@ -4,16 +4,17 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/common/key_value_iterable.h" -# include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/logs/event_logger.h" -# include "opentelemetry/logs/logger.h" # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs { + +class EventLogger; +class Logger; + /** * Creates new EventLogger instances. */ diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/log_record.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/log_record.h similarity index 58% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/log_record.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/log_record.h index 7fb51c2d9..1014a880b 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/log_record.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/log_record.h @@ -5,17 +5,22 @@ #ifdef ENABLE_LOGS_PREVIEW # include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/key_value_iterable.h" # include "opentelemetry/common/timestamp.h" -# include "opentelemetry/logs/severity.h" -# include "opentelemetry/trace/span_id.h" -# include "opentelemetry/trace/trace_flags.h" -# include "opentelemetry/trace/trace_id.h" # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +class SpanId; +class TraceId; +class TraceFlags; +} // namespace trace + namespace logs { + +enum class Severity : uint8_t; + /** * Maintains a representation of a log in a format that can be processed by a recorder. * @@ -30,25 +35,25 @@ class LogRecord * Set the timestamp for this log. * @param timestamp the timestamp to set */ - virtual void SetTimestamp(opentelemetry::common::SystemTimestamp timestamp) noexcept = 0; + virtual void SetTimestamp(common::SystemTimestamp timestamp) noexcept = 0; /** * Set the observed timestamp for this log. * @param timestamp the timestamp to set */ - virtual void SetObservedTimestamp(opentelemetry::common::SystemTimestamp timestamp) noexcept = 0; + virtual void SetObservedTimestamp(common::SystemTimestamp timestamp) noexcept = 0; /** * Set the severity for this log. * @param severity the severity of the event */ - virtual void SetSeverity(opentelemetry::logs::Severity severity) noexcept = 0; + virtual void SetSeverity(logs::Severity severity) noexcept = 0; /** * Set body field for this log. * @param message the body to set */ - virtual void SetBody(const opentelemetry::common::AttributeValue &message) noexcept = 0; + virtual void SetBody(const common::AttributeValue &message) noexcept = 0; /** * Set an attribute of a log. @@ -56,25 +61,33 @@ class LogRecord * @param value the attribute value */ virtual void SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept = 0; + const common::AttributeValue &value) noexcept = 0; + + /** + * Set the Event Id. + * @param id The event id to set + * @param name Optional event name to set + */ + // TODO: mark this as pure virtual once all exporters have been updated + virtual void SetEventId(int64_t id, nostd::string_view name = {}) noexcept = 0; /** * Set the trace id for this log. * @param trace_id the trace id to set */ - virtual void SetTraceId(const opentelemetry::trace::TraceId &trace_id) noexcept = 0; + virtual void SetTraceId(const trace::TraceId &trace_id) noexcept = 0; /** * Set the span id for this log. * @param span_id the span id to set */ - virtual void SetSpanId(const opentelemetry::trace::SpanId &span_id) noexcept = 0; + virtual void SetSpanId(const trace::SpanId &span_id) noexcept = 0; /** * Inject trace_flags for this log. * @param trace_flags the trace flags to set */ - virtual void SetTraceFlags(const opentelemetry::trace::TraceFlags &trace_flags) noexcept = 0; + virtual void SetTraceFlags(const trace::TraceFlags &trace_flags) noexcept = 0; }; } // namespace logs OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger.h similarity index 58% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger.h index 23aea1114..d991a13d8 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger.h @@ -4,8 +4,6 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW -# include "opentelemetry/common/key_value_iterable.h" -# include "opentelemetry/logs/log_record.h" # include "opentelemetry/logs/logger_type_traits.h" # include "opentelemetry/logs/severity.h" # include "opentelemetry/nostd/string_view.h" @@ -13,8 +11,17 @@ # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + namespace logs { + +class EventId; +class LogRecord; + /** * Handles log record creation. **/ @@ -246,10 +253,225 @@ class Logger this->EmitLogRecord(Severity::kFatal, std::forward(args)...); } + // + // OpenTelemetry C++ user-facing Logs API + // + + inline bool Enabled(Severity severity, const EventId &event_id) const noexcept + { + OPENTELEMETRY_LIKELY_IF(Enabled(severity) == false) { return false; } + return EnabledImplementation(severity, event_id); + } + + inline bool Enabled(Severity severity, int64_t event_id) const noexcept + { + OPENTELEMETRY_LIKELY_IF(Enabled(severity) == false) { return false; } + return EnabledImplementation(severity, event_id); + } + + inline bool Enabled(Severity severity) const noexcept + { + return static_cast(severity) >= OPENTELEMETRY_ATOMIC_READ_8(&minimum_severity_); + } + + /** + * Log an event + * + * @severity severity of the log + * @event_id event identifier of the log + * @format an utf-8 string following https://messagetemplates.org/ + * @attributes key value pairs of the log + */ + virtual void Log(Severity severity, + const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->EmitLogRecord(severity, event_id, format, attributes); + } + + virtual void Log(Severity severity, + int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->EmitLogRecord(severity, EventId{event_id}, format, attributes); + } + + virtual void Log(Severity severity, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->EmitLogRecord(severity, format, attributes); + } + + virtual void Log(Severity severity, nostd::string_view message) noexcept + { + this->EmitLogRecord(severity, message); + } + + // Convenient wrappers based on virtual methods Log(). + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber + + inline void Trace(const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kTrace, event_id, format, attributes); + } + + inline void Trace(int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kTrace, EventId{event_id}, format, attributes); + } + + inline void Trace(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kTrace, format, attributes); + } + + inline void Trace(nostd::string_view message) noexcept { this->Log(Severity::kTrace, message); } + + inline void Debug(const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kDebug, event_id, format, attributes); + } + + inline void Debug(int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kDebug, EventId{event_id}, format, attributes); + } + + inline void Debug(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kDebug, format, attributes); + } + + inline void Debug(nostd::string_view message) noexcept { this->Log(Severity::kDebug, message); } + + inline void Info(const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kInfo, event_id, format, attributes); + } + + inline void Info(int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kInfo, EventId{event_id}, format, attributes); + } + + inline void Info(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kInfo, format, attributes); + } + + inline void Info(nostd::string_view message) noexcept { this->Log(Severity::kInfo, message); } + + inline void Warn(const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kWarn, event_id, format, attributes); + } + + inline void Warn(int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kWarn, EventId{event_id}, format, attributes); + } + + inline void Warn(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kWarn, format, attributes); + } + + inline void Warn(nostd::string_view message) noexcept { this->Log(Severity::kWarn, message); } + + inline void Error(const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kError, event_id, format, attributes); + } + + inline void Error(int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kError, EventId{event_id}, format, attributes); + } + + inline void Error(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kError, format, attributes); + } + + inline void Error(nostd::string_view message) noexcept { this->Log(Severity::kError, message); } + + inline void Fatal(const EventId &event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kFatal, event_id, format, attributes); + } + + inline void Fatal(int64_t event_id, + nostd::string_view format, + const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kFatal, EventId{event_id}, format, attributes); + } + + inline void Fatal(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept + { + this->Log(Severity::kFatal, format, attributes); + } + + inline void Fatal(nostd::string_view message) noexcept { this->Log(Severity::kFatal, message); } + + // + // End of OpenTelemetry C++ user-facing Log API. + // + +protected: + // TODO: discuss with community about naming for internal methods. + virtual bool EnabledImplementation(Severity /*severity*/, + const EventId & /*event_id*/) const noexcept + { + return false; + } + + virtual bool EnabledImplementation(Severity /*severity*/, int64_t /*event_id*/) const noexcept + { + return false; + } + + void SetMinimumSeverity(uint8_t severity_or_max) noexcept + { + OPENTELEMETRY_ATOMIC_WRITE_8(&minimum_severity_, severity_or_max); + } + private: template void IgnoreTraitResult(ValueType &&...) {} + + // + // minimum_severity_ can be updated concurrently by multiple threads/cores, so race condition on + // read/write should be handled. And std::atomic can not be used here because it is not ABI + // compatible for OpenTelemetry C++ API. + // + mutable uint8_t minimum_severity_{kMaxSeverity}; }; } // namespace logs OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger_provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger_provider.h similarity index 88% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger_provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger_provider.h index 7979ab202..e2a72bcc5 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger_provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger_provider.h @@ -7,13 +7,18 @@ # include "opentelemetry/common/key_value_iterable.h" # include "opentelemetry/common/key_value_iterable_view.h" -# include "opentelemetry/logs/logger.h" # include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/span.h" # include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/nostd/type_traits.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs { + +class Logger; + /** * Creates new Logger instances. */ @@ -35,10 +40,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider virtual nostd::shared_ptr GetLogger( nostd::string_view logger_name, - nostd::string_view library_name, + nostd::string_view library_name = "", nostd::string_view library_version = "", nostd::string_view schema_url = "", - bool include_trace_context = true, const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) = 0; nostd::shared_ptr GetLogger( @@ -46,10 +50,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, std::initializer_list> attributes) { - return GetLogger(logger_name, library_name, library_version, schema_url, include_trace_context, + return GetLogger(logger_name, library_name, library_version, schema_url, nostd::span>{ attributes.begin(), attributes.end()}); } @@ -60,10 +63,9 @@ class OPENTELEMETRY_EXPORT LoggerProvider nostd::string_view library_name, nostd::string_view library_version, nostd::string_view schema_url, - bool include_trace_context, const T &attributes) { - return GetLogger(logger_name, library_name, library_version, schema_url, include_trace_context, + return GetLogger(logger_name, library_name, library_version, schema_url, common::KeyValueIterableView(attributes)); } }; diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger_type_traits.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger_type_traits.h similarity index 94% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger_type_traits.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger_type_traits.h index 8736c03f7..b1e5e560d 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/logger_type_traits.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/logger_type_traits.h @@ -10,13 +10,11 @@ # include "opentelemetry/common/attribute_value.h" # include "opentelemetry/common/key_value_iterable.h" # include "opentelemetry/common/timestamp.h" +# include "opentelemetry/logs/event_id.h" # include "opentelemetry/logs/log_record.h" # include "opentelemetry/logs/severity.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/span.h" # include "opentelemetry/nostd/string_view.h" # include "opentelemetry/nostd/type_traits.h" -# include "opentelemetry/nostd/unique_ptr.h" # include "opentelemetry/trace/span_context.h" # include "opentelemetry/trace/span_id.h" # include "opentelemetry/trace/trace_flags.h" @@ -43,6 +41,18 @@ struct LogRecordSetterTrait } }; +template <> +struct LogRecordSetterTrait +{ + template + inline static LogRecord *Set(LogRecord *log_record, ArgumentType &&arg) noexcept + { + log_record->SetEventId(arg.id_, nostd::string_view{arg.name_.get()}); + + return log_record; + } +}; + template <> struct LogRecordSetterTrait { diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/noop.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/noop.h similarity index 76% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/noop.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/noop.h index 506100327..5303b2e77 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/noop.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/noop.h @@ -9,28 +9,21 @@ // This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be // used directly. Please refer to logger.h for documentation on these interfaces. -# include - -# include "opentelemetry/common/attribute_value.h" -# include "opentelemetry/common/key_value_iterable.h" -# include "opentelemetry/common/timestamp.h" -# include "opentelemetry/context/runtime_context.h" +# include "opentelemetry/logs/event_logger.h" # include "opentelemetry/logs/event_logger_provider.h" # include "opentelemetry/logs/logger.h" # include "opentelemetry/logs/logger_provider.h" -# include "opentelemetry/logs/severity.h" # include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/span.h" # include "opentelemetry/nostd/string_view.h" # include "opentelemetry/nostd/unique_ptr.h" -# include "opentelemetry/trace/span_id.h" -# include "opentelemetry/trace/trace_flags.h" -# include "opentelemetry/trace/trace_id.h" -# include "opentelemetry/version.h" - # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace common +{ +class KeyValueIterable; +} // namespace common + namespace logs { /** @@ -52,26 +45,22 @@ class NoopLogger final : public Logger /** * No-op implementation of a LoggerProvider. */ -class NoopLoggerProvider final : public opentelemetry::logs::LoggerProvider +class NoopLoggerProvider final : public LoggerProvider { public: - NoopLoggerProvider() - : logger_{ - nostd::shared_ptr(new opentelemetry::logs::NoopLogger)} - {} + NoopLoggerProvider() : logger_{nostd::shared_ptr(new NoopLogger())} {} nostd::shared_ptr GetLogger(nostd::string_view /* logger_name */, nostd::string_view /* library_name */, nostd::string_view /* library_version */, nostd::string_view /* schema_url */, - bool /* include_trace_context */, const common::KeyValueIterable & /* attributes */) override { return logger_; } private: - nostd::shared_ptr logger_; + nostd::shared_ptr logger_; }; class NoopEventLogger final : public EventLogger diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/provider.h similarity index 94% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/provider.h index ed6fe86ba..a33b26dba 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/provider.h @@ -8,18 +8,21 @@ # include "opentelemetry/common/macros.h" # include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/logs/event_logger_provider.h" -# include "opentelemetry/logs/logger_provider.h" # include "opentelemetry/logs/noop.h" # include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace logs { + +class EventLoggerProvider; +class LoggerProvider; + /** * Stores the singleton global LoggerProvider. */ -class Provider +class OPENTELEMETRY_EXPORT Provider { public: /** diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/severity.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/severity.h similarity index 59% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/severity.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/severity.h index 9fcf457b2..6a435f38f 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/logs/severity.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/logs/severity.h @@ -4,6 +4,7 @@ #pragma once #ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/nostd/string_view.h" # include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -13,36 +14,41 @@ namespace logs /** * Severity Levels assigned to log events, based on Log Data Model, * with the addition of kInvalid (mapped to a severity number of 0). + * + * See + * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber */ enum class Severity : uint8_t { - kInvalid, - kTrace, - kTrace2, - kTrace3, - kTrace4, - kDebug, - kDebug2, - kDebug3, - kDebug4, - kInfo, - kInfo2, - kInfo3, - kInfo4, - kWarn, - kWarn2, - kWarn3, - kWarn4, - kError, - kError2, - kError3, - kError4, - kFatal, - kFatal2, - kFatal3, - kFatal4 + kInvalid = 0, + kTrace = 1, + kTrace2 = 2, + kTrace3 = 3, + kTrace4 = 4, + kDebug = 5, + kDebug2 = 6, + kDebug3 = 7, + kDebug4 = 8, + kInfo = 9, + kInfo2 = 10, + kInfo3 = 11, + kInfo4 = 12, + kWarn = 13, + kWarn2 = 14, + kWarn3 = 15, + kWarn4 = 16, + kError = 17, + kError2 = 18, + kError3 = 19, + kError4 = 20, + kFatal = 21, + kFatal2 = 22, + kFatal3 = 23, + kFatal4 = 24 }; +const uint8_t kMaxSeverity = 255; + /** * Mapping of the severity enum above, to a severity text string (in all caps). * This severity text can be printed out by exporters. Capital letters follow the @@ -51,7 +57,7 @@ enum class Severity : uint8_t * Included to follow the specification's recommendation to print both * severity number and text in each log record. */ -const opentelemetry::nostd::string_view SeverityNumToText[25] = { +const nostd::string_view SeverityNumToText[25] = { "INVALID", "TRACE", "TRACE2", "TRACE3", "TRACE4", "DEBUG", "DEBUG2", "DEBUG3", "DEBUG4", "INFO", "INFO2", "INFO3", "INFO4", "WARN", "WARN2", "WARN3", "WARN4", "ERROR", "ERROR2", "ERROR3", "ERROR4", "FATAL", "FATAL2", "FATAL3", "FATAL4"}; diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/async_instruments.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/async_instruments.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/async_instruments.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/async_instruments.h index 6e6d5012c..f73eb2f51 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/async_instruments.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/async_instruments.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/meter.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/meter.h similarity index 97% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/meter.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/meter.h index 877453884..8784fe788 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/meter.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/meter.h @@ -3,10 +3,7 @@ #pragma once -#include "opentelemetry/metrics/async_instruments.h" -#include "opentelemetry/metrics/sync_instruments.h" #include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/version.h" @@ -14,6 +11,18 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics { + +template +class Counter; + +template +class Histogram; + +template +class UpDownCounter; + +class ObservableInstrument; + /** * Handles instrument creation and provides a facility for batch recording. * diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/meter_provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/meter_provider.h similarity index 72% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/meter_provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/meter_provider.h index 4c3306ebf..e0b0285ef 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/meter_provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/meter_provider.h @@ -3,13 +3,16 @@ #pragma once -#include "opentelemetry/metrics/meter.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics { + +class Meter; + /** * Creates new Meter instances. */ @@ -26,6 +29,11 @@ class MeterProvider virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; +#ifdef ENABLE_REMOVE_METER_PREVIEW + virtual void RemoveMeter(nostd::string_view library_name, + nostd::string_view library_version = "", + nostd::string_view schema_url = "") noexcept = 0; +#endif }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/noop.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/noop.h similarity index 90% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/noop.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/noop.h index 0d2eacde9..c5802f3dd 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/noop.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/noop.h @@ -23,12 +23,11 @@ class NoopCounter : public Counter nostd::string_view /* unit */) noexcept {} void Add(T /* value */) noexcept override {} - void Add(T /* value */, const opentelemetry::context::Context & /* context */) noexcept override - {} + void Add(T /* value */, const context::Context & /* context */) noexcept override {} void Add(T /* value */, const common::KeyValueIterable & /* attributes */) noexcept override {} void Add(T /* value */, const common::KeyValueIterable & /* attributes */, - const opentelemetry::context::Context & /* context */) noexcept override + const context::Context & /* context */) noexcept override {} }; @@ -40,12 +39,10 @@ class NoopHistogram : public Histogram nostd::string_view /* description */, nostd::string_view /* unit */) noexcept {} - void Record(T /* value */, - const opentelemetry::context::Context & /* context */) noexcept override - {} + void Record(T /* value */, const context::Context & /* context */) noexcept override {} void Record(T /* value */, const common::KeyValueIterable & /* attributes */, - const opentelemetry::context::Context & /* context */) noexcept override + const context::Context & /* context */) noexcept override {} }; @@ -59,12 +56,11 @@ class NoopUpDownCounter : public UpDownCounter {} ~NoopUpDownCounter() override = default; void Add(T /* value */) noexcept override {} - void Add(T /* value */, const opentelemetry::context::Context & /* context */) noexcept override - {} + void Add(T /* value */, const context::Context & /* context */) noexcept override {} void Add(T /* value */, const common::KeyValueIterable & /* attributes */) noexcept override {} void Add(T /* value */, const common::KeyValueIterable & /* attributes */, - const opentelemetry::context::Context & /* context */) noexcept override + const context::Context & /* context */) noexcept override {} }; @@ -207,6 +203,13 @@ class NoopMeterProvider final : public MeterProvider return meter_; } +#ifdef ENABLE_REMOVE_METER_PREVIEW + void RemoveMeter(nostd::string_view /* name */, + nostd::string_view /* version */, + nostd::string_view /* schema_url */) noexcept override + {} +#endif + private: nostd::shared_ptr meter_; }; diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/observer_result.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/observer_result.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/observer_result.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/observer_result.h index 88cae2861..56c42bc20 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/observer_result.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/observer_result.h @@ -9,6 +9,8 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" +#include "opentelemetry/nostd/variant.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/provider.h similarity index 96% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/provider.h index ea710a482..b2fa3e20e 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/provider.h @@ -7,13 +7,16 @@ #include "opentelemetry/common/macros.h" #include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/metrics/meter_provider.h" #include "opentelemetry/metrics/noop.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics { + +class MeterProvider; + /** * Stores the singleton global MeterProvider. */ diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/sync_instruments.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/sync_instruments.h similarity index 78% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/sync_instruments.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/sync_instruments.h index 8db77daae..b26e527c2 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/metrics/sync_instruments.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/metrics/sync_instruments.h @@ -9,6 +9,7 @@ #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -33,7 +34,7 @@ class Counter : public SynchronousInstrument */ virtual void Add(T value) noexcept = 0; - virtual void Add(T value, const opentelemetry::context::Context &context) noexcept = 0; + virtual void Add(T value, const context::Context &context) noexcept = 0; /** * Add adds the value to the counter's sum. The attributes should contain @@ -48,19 +49,19 @@ class Counter : public SynchronousInstrument virtual void Add(T value, const common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept = 0; + const context::Context &context) noexcept = 0; template ::value> * = nullptr> void Add(T value, const U &attributes) noexcept { - auto context = opentelemetry::context::Context{}; + auto context = context::Context{}; this->Add(value, common::KeyValueIterableView{attributes}, context); } template ::value> * = nullptr> - void Add(T value, const U &attributes, const opentelemetry::context::Context &context) noexcept + void Add(T value, const U &attributes, const context::Context &context) noexcept { this->Add(value, common::KeyValueIterableView{attributes}, context); } @@ -69,7 +70,7 @@ class Counter : public SynchronousInstrument std::initializer_list> attributes) noexcept { - auto context = opentelemetry::context::Context{}; + auto context = context::Context{}; this->Add(value, nostd::span>{ attributes.begin(), attributes.end()}, @@ -78,7 +79,7 @@ class Counter : public SynchronousInstrument void Add(T value, std::initializer_list> attributes, - const opentelemetry::context::Context &context) noexcept + const context::Context &context) noexcept { this->Add(value, nostd::span>{ @@ -96,23 +97,23 @@ class Histogram : public SynchronousInstrument /** * Records a value. * - * @param value The increment amount. May be positive, negative or zero. + * @param value The measurement value. MUST be non-negative. */ - virtual void Record(T value, const opentelemetry::context::Context &context) noexcept = 0; + virtual void Record(T value, const context::Context &context) noexcept = 0; /** * Records a value with a set of attributes. * - * @param value The increment amount. May be positive, negative or zero. + * @param value The measurement value. MUST be non-negative. * @param attributes A set of attributes to associate with the count. */ virtual void Record(T value, const common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept = 0; + const context::Context &context) noexcept = 0; template ::value> * = nullptr> - void Record(T value, const U &attributes, const opentelemetry::context::Context &context) noexcept + void Record(T value, const U &attributes, const context::Context &context) noexcept { this->Record(value, common::KeyValueIterableView{attributes}, context); } @@ -120,7 +121,7 @@ class Histogram : public SynchronousInstrument void Record( T value, std::initializer_list> attributes, - const opentelemetry::context::Context &context) noexcept + const context::Context &context) noexcept { this->Record(value, nostd::span>{ @@ -142,7 +143,7 @@ class UpDownCounter : public SynchronousInstrument */ virtual void Add(T value) noexcept = 0; - virtual void Add(T value, const opentelemetry::context::Context &context) noexcept = 0; + virtual void Add(T value, const context::Context &context) noexcept = 0; /** * Add a value with a set of attributes. @@ -154,19 +155,19 @@ class UpDownCounter : public SynchronousInstrument virtual void Add(T value, const common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept = 0; + const context::Context &context) noexcept = 0; template ::value> * = nullptr> void Add(T value, const U &attributes) noexcept { - auto context = opentelemetry::context::Context{}; + auto context = context::Context{}; this->Add(value, common::KeyValueIterableView{attributes}, context); } template ::value> * = nullptr> - void Add(T value, const U &attributes, const opentelemetry::context::Context &context) noexcept + void Add(T value, const U &attributes, const context::Context &context) noexcept { this->Add(value, common::KeyValueIterableView{attributes}, context); } @@ -175,7 +176,7 @@ class UpDownCounter : public SynchronousInstrument std::initializer_list> attributes) noexcept { - auto context = opentelemetry::context::Context{}; + auto context = context::Context{}; this->Add(value, nostd::span>{ attributes.begin(), attributes.end()}, @@ -184,7 +185,7 @@ class UpDownCounter : public SynchronousInstrument void Add(T value, std::initializer_list> attributes, - const opentelemetry::context::Context &context) noexcept + const context::Context &context) noexcept { this->Add(value, nostd::span>{ diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/all.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/all.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/all.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/all.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/decay.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/decay.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/decay.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/decay.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/dependent_type.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/dependent_type.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/dependent_type.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/dependent_type.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/functional.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/functional.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/functional.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/functional.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/invoke.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/invoke.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/invoke.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/invoke.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/trait.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/trait.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/trait.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/trait.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/type_pack_element.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/type_pack_element.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/type_pack_element.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/type_pack_element.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/valueless.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/valueless.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/valueless.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/valueless.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/variant_alternative.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/variant_alternative.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/variant_alternative.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/variant_alternative.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/variant_fwd.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/variant_fwd.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/variant_fwd.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/variant_fwd.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/variant_size.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/variant_size.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/variant_size.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/variant_size.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/void.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/void.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/detail/void.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/detail/void.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/function_ref.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/function_ref.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/function_ref.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/function_ref.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/.clang-format b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/.clang-format similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/.clang-format rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/.clang-format diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/README.md b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/README.md similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/README.md rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/README.md diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/attributes.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/attributes.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/attributes.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/attributes.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/config.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/config.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/config.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/config.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/internal/identity.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/internal/identity.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/internal/identity.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/internal/identity.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/internal/inline_variable.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/internal/invoke.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/macros.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/macros.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/macros.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/macros.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/optimization.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/optimization.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/optimization.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/optimization.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/options.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/options.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/options.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/options.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/policy_checks.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/port.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/port.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/base/port.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/base/port.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/types/bad_variant_access.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/types/internal/variant.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/types/variant.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/types/variant.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/types/variant.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/types/variant.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/utility/utility.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/utility/utility.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/internal/absl/utility/utility.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/internal/absl/utility/utility.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/shared_ptr.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/shared_ptr.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/shared_ptr.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/shared_ptr.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/span.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/span.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/span.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/span.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/string_view.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/string_view.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/string_view.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/string_view.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/type_traits.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/type_traits.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/type_traits.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/type_traits.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/unique_ptr.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/unique_ptr.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/unique_ptr.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/unique_ptr.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/utility.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/utility.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/utility.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/utility.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/variant.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/variant.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/nostd/variant.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/nostd/variant.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_library_handle.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_library_handle.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_library_handle.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_library_handle.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h similarity index 94% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h index bcc4bd0b8..1d249317a 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_load_unix.h @@ -8,6 +8,8 @@ #include +#include "opentelemetry/plugin/detail/dynamic_library_handle.h" +#include "opentelemetry/plugin/detail/loader_info.h" #include "opentelemetry/plugin/detail/utility.h" #include "opentelemetry/plugin/factory.h" #include "opentelemetry/plugin/hook.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_load_windows.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_load_windows.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_load_windows.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_load_windows.h index 7a586b6bc..3f5e05f19 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/dynamic_load_windows.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/dynamic_load_windows.h @@ -5,6 +5,8 @@ #include +#include "opentelemetry/plugin/detail/dynamic_library_handle.h" +#include "opentelemetry/plugin/detail/loader_info.h" #include "opentelemetry/plugin/detail/utility.h" #include "opentelemetry/plugin/factory.h" #include "opentelemetry/plugin/hook.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/loader_info.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/loader_info.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/loader_info.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/loader_info.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/tracer_handle.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/tracer_handle.h similarity index 88% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/tracer_handle.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/tracer_handle.h index 559d7ddf4..46b128106 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/tracer_handle.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/tracer_handle.h @@ -3,10 +3,14 @@ #pragma once -#include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +class Tracer; +} // namespace trace + namespace plugin { /** diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/utility.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/utility.h similarity index 89% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/utility.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/utility.h index 6f8dd5d46..8007f285d 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/detail/utility.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/detail/utility.h @@ -3,10 +3,12 @@ #pragma once -#include +#if __EXCEPTIONS +# include +#endif // __EXCEPTIONS + #include -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/dynamic_load.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/dynamic_load.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/dynamic_load.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/dynamic_load.h index 8318d534a..58a69ad5c 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/dynamic_load.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/dynamic_load.h @@ -3,6 +3,7 @@ #pragma once +#include #include #ifdef _WIN32 @@ -10,12 +11,14 @@ #else # include "opentelemetry/plugin/detail/dynamic_load_unix.h" #endif - #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace plugin { + +class Factory; + /** * Load an OpenTelemetry implementation as a plugin. * @param plugin the path to the plugin to load diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/factory.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/factory.h similarity index 84% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/factory.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/factory.h index 0a285d65b..6b484d8f2 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/factory.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/factory.h @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #include #include @@ -39,9 +40,8 @@ class Factory final * @param error_message on failure this will contain an error message. * @return a Tracer on success or nullptr on failure. */ - std::shared_ptr MakeTracer( - nostd::string_view tracer_config, - std::string &error_message) const noexcept + std::shared_ptr MakeTracer(nostd::string_view tracer_config, + std::string &error_message) const noexcept { nostd::unique_ptr plugin_error_message; auto tracer_handle = factory_impl_->MakeTracerHandle(tracer_config, plugin_error_message); @@ -50,8 +50,8 @@ class Factory final detail::CopyErrorMessage(plugin_error_message.get(), error_message); return nullptr; } - return std::shared_ptr{ - new (std::nothrow) Tracer{library_handle_, std::move(tracer_handle)}}; + return std::shared_ptr{new (std::nothrow) + Tracer{library_handle_, std::move(tracer_handle)}}; } private: diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/hook.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/hook.h similarity index 95% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/hook.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/hook.h index c06c0b324..c9597e06a 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/hook.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/hook.h @@ -3,8 +3,7 @@ #pragma once -#include "opentelemetry/plugin/detail/loader_info.h" -#include "opentelemetry/plugin/factory.h" +#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/version.h" #ifdef _WIN32 @@ -41,6 +40,10 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace plugin { + +struct LoaderInfo; +class FactoryImpl; + using OpenTelemetryHook = nostd::unique_ptr (*)(const LoaderInfo &loader_info, nostd::unique_ptr &error_message); diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/tracer.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/tracer.h similarity index 98% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/tracer.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/tracer.h index df8e542c0..b87f9e889 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/plugin/tracer.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/plugin/tracer.h @@ -6,7 +6,6 @@ #include #include "opentelemetry/common/key_value_iterable.h" -#include "opentelemetry/plugin/detail/dynamic_library_handle.h" #include "opentelemetry/plugin/detail/tracer_handle.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/version.h" @@ -14,6 +13,9 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace plugin { + +class DynamicLibraryHandle; + class Span final : public trace::Span { public: diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/shared_ptr.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/shared_ptr.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/shared_ptr.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/shared_ptr.h index 418d4ef71..b1b99bd36 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/shared_ptr.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/shared_ptr.h @@ -3,10 +3,10 @@ #pragma once -#include "opentelemetry/version.h" - #include +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE // Standard Type aliases in nostd namespace namespace nostd diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/span.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/span.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/span.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/span.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/string_view.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/string_view.h similarity index 75% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/string_view.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/string_view.h index 8fd159d3a..5295eb454 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/string_view.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/string_view.h @@ -3,15 +3,9 @@ #pragma once -#include "opentelemetry/version.h" - -#include "opentelemetry/std/utility.h" - -#include -#include #include -#include -#include + +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE // Standard Type aliases in nostd namespace diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/type_traits.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/type_traits.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/type_traits.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/type_traits.h index 66308a42a..f26af95b9 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/type_traits.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/type_traits.h @@ -3,10 +3,10 @@ #pragma once -#include "opentelemetry/version.h" - #include +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE // Standard Type aliases in nostd namespace namespace nostd diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/unique_ptr.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/unique_ptr.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/unique_ptr.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/unique_ptr.h index f15699b67..1d7d9b1fc 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/unique_ptr.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/unique_ptr.h @@ -3,10 +3,10 @@ #pragma once -#include "opentelemetry/version.h" - #include +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE // Standard Type aliases in nostd namespace namespace nostd diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/utility.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/utility.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/utility.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/utility.h index 01cdc1833..9a1c76540 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/utility.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/utility.h @@ -3,11 +3,11 @@ #pragma once -#include "opentelemetry/version.h" - #include #include +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE // Standard Type aliases in nostd namespace namespace nostd diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/variant.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/variant.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/std/variant.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/std/variant.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/canonical_code.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/canonical_code.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/canonical_code.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/canonical_code.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/context.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/context.h similarity index 74% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/context.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/context.h index 0a57e725c..b68fe9e95 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/context.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/context.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/default_span.h" #include "opentelemetry/version.h" @@ -12,7 +13,7 @@ namespace trace { // Get Span from explicit context -inline nostd::shared_ptr GetSpan(const opentelemetry::context::Context &context) noexcept +inline nostd::shared_ptr GetSpan(const context::Context &context) noexcept { context::ContextValue span = context.GetValue(kSpanKey); if (nostd::holds_alternative>(span)) @@ -23,8 +24,7 @@ inline nostd::shared_ptr GetSpan(const opentelemetry::context::Context &co } // Set Span into explicit context -inline context::Context SetSpan(opentelemetry::context::Context &context, - nostd::shared_ptr span) noexcept +inline context::Context SetSpan(context::Context &context, nostd::shared_ptr span) noexcept { return context.SetValue(kSpanKey, span); } diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/default_span.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/default_span.h similarity index 96% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/default_span.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/default_span.h index dd1e5475f..cccc7951a 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/default_span.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/default_span.h @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once + #include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/trace/canonical_code.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/noop.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/noop.h similarity index 83% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/noop.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/noop.h index 8a9b13b7a..2a2b7312b 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/noop.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/noop.h @@ -7,18 +7,18 @@ // This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be // used directly. Please refer to span.h and tracer.h for documentation on these interfaces. +#include + #include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/span_context.h" -#include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/trace/tracer.h" #include "opentelemetry/trace/tracer_provider.h" #include "opentelemetry/version.h" -#include - namespace trace_api = opentelemetry::trace; OPENTELEMETRY_BEGIN_NAMESPACE @@ -88,8 +88,7 @@ class OPENTELEMETRY_EXPORT NoopTracer final : public Tracer, { // Don't allocate a no-op span for every StartSpan call, but use a static // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); + static nostd::shared_ptr noop_span(new trace::NoopSpan{this->shared_from_this()}); return noop_span; } @@ -102,24 +101,22 @@ class OPENTELEMETRY_EXPORT NoopTracer final : public Tracer, /** * No-op implementation of a TracerProvider. */ -class OPENTELEMETRY_EXPORT NoopTracerProvider final : public opentelemetry::trace::TracerProvider +class OPENTELEMETRY_EXPORT NoopTracerProvider final : public trace::TracerProvider { public: NoopTracerProvider() noexcept - : tracer_{nostd::shared_ptr( - new opentelemetry::trace::NoopTracer)} + : tracer_{nostd::shared_ptr(new trace::NoopTracer)} {} - nostd::shared_ptr GetTracer( - nostd::string_view /* library_name */, - nostd::string_view /* library_version */, - nostd::string_view /* schema_url */) noexcept override + nostd::shared_ptr GetTracer(nostd::string_view /* library_name */, + nostd::string_view /* library_version */, + nostd::string_view /* schema_url */) noexcept override { return tracer_; } private: - nostd::shared_ptr tracer_; + nostd::shared_ptr tracer_; }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/b3_propagator.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/b3_propagator.h similarity index 93% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/b3_propagator.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/b3_propagator.h index d5661cb2a..e52e42b74 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/b3_propagator.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/b3_propagator.h @@ -3,13 +3,14 @@ #pragma once +#include + #include "detail/hex.h" #include "detail/string.h" #include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/trace/context.h" #include "opentelemetry/trace/default_span.h" - -#include +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -41,11 +42,11 @@ static const int kSpanIdHexStrLength = 16; // providing the object containing the headers, and a getter function for the extraction. Based on: // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md#b3-extract -class B3PropagatorExtractor : public opentelemetry::context::propagation::TextMapPropagator +class B3PropagatorExtractor : public context::propagation::TextMapPropagator { public: // Returns the context that is stored in the HTTP header carrier. - context::Context Extract(const opentelemetry::context::propagation::TextMapCarrier &carrier, + context::Context Extract(const context::propagation::TextMapCarrier &carrier, context::Context &context) noexcept override { SpanContext span_context = ExtractImpl(carrier); @@ -77,7 +78,7 @@ class B3PropagatorExtractor : public opentelemetry::context::propagation::TextMa } private: - static SpanContext ExtractImpl(const opentelemetry::context::propagation::TextMapCarrier &carrier) + static SpanContext ExtractImpl(const context::propagation::TextMapCarrier &carrier) { nostd::string_view trace_id_hex; nostd::string_view span_id_hex; @@ -128,7 +129,7 @@ class B3Propagator : public B3PropagatorExtractor { public: // Sets the context for a HTTP header carrier with self defined rules. - void Inject(opentelemetry::context::propagation::TextMapCarrier &carrier, + void Inject(context::propagation::TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = trace::GetSpan(context)->GetContext(); @@ -160,7 +161,7 @@ class B3Propagator : public B3PropagatorExtractor class B3PropagatorMultiHeader : public B3PropagatorExtractor { public: - void Inject(opentelemetry::context::propagation::TextMapCarrier &carrier, + void Inject(context::propagation::TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = GetSpan(context)->GetContext(); diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/detail/hex.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/detail/hex.h similarity index 98% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/detail/hex.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/detail/hex.h index 10a17ff51..c8bd58f8b 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/detail/hex.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/detail/hex.h @@ -3,11 +3,12 @@ #pragma once -#include "opentelemetry/nostd/string_view.h" - #include #include +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/detail/string.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/detail/string.h similarity index 97% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/detail/string.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/detail/string.h index 67e934b40..de4699952 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/detail/string.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/detail/string.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/http_trace_context.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/http_trace_context.h similarity index 89% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/http_trace_context.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/http_trace_context.h index 9440960be..bba7592ea 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/http_trace_context.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/http_trace_context.h @@ -4,12 +4,17 @@ #pragma once #include + #include "detail/hex.h" #include "detail/string.h" #include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/trace/context.h" #include "opentelemetry/trace/default_span.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -30,10 +35,10 @@ static const size_t kTraceParentSize = 55; // HttpTraceContext().Inject(carrier, context); // HttpTraceContext().Extract(carrier, context); -class HttpTraceContext : public opentelemetry::context::propagation::TextMapPropagator +class HttpTraceContext : public context::propagation::TextMapPropagator { public: - void Inject(opentelemetry::context::propagation::TextMapCarrier &carrier, + void Inject(context::propagation::TextMapCarrier &carrier, const context::Context &context) noexcept override { SpanContext span_context = trace::GetSpan(context)->GetContext(); @@ -44,7 +49,7 @@ class HttpTraceContext : public opentelemetry::context::propagation::TextMapProp InjectImpl(carrier, span_context); } - context::Context Extract(const opentelemetry::context::propagation::TextMapCarrier &carrier, + context::Context Extract(const context::propagation::TextMapCarrier &carrier, context::Context &context) noexcept override { SpanContext span_context = ExtractImpl(carrier); @@ -83,7 +88,7 @@ class HttpTraceContext : public opentelemetry::context::propagation::TextMapProp return version != kInvalidVersion; } - static void InjectImpl(opentelemetry::context::propagation::TextMapCarrier &carrier, + static void InjectImpl(context::propagation::TextMapCarrier &carrier, const SpanContext &span_context) { char trace_parent[kTraceParentSize]; @@ -152,10 +157,10 @@ class HttpTraceContext : public opentelemetry::context::propagation::TextMapProp } return SpanContext(trace_id, span_id, TraceFlagsFromHex(trace_flags_hex), true, - opentelemetry::trace::TraceState::FromHeader(trace_state)); + trace::TraceState::FromHeader(trace_state)); } - static SpanContext ExtractImpl(const opentelemetry::context::propagation::TextMapCarrier &carrier) + static SpanContext ExtractImpl(const context::propagation::TextMapCarrier &carrier) { nostd::string_view trace_parent = carrier.Get(kTraceParent); nostd::string_view trace_state = carrier.Get(kTraceState); diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/jaeger.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/jaeger.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/propagation/jaeger.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/propagation/jaeger.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/provider.h similarity index 96% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/provider.h index aff94d4d0..d5a52a02f 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/provider.h @@ -9,11 +9,14 @@ #include "opentelemetry/common/spin_lock_mutex.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/noop.h" -#include "opentelemetry/trace/tracer_provider.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { + +class TracerProvider; + /** * Stores the singleton global TracerProvider. */ diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/scope.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/scope.h similarity index 86% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/scope.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/scope.h index ecceba458..11ded4ab6 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/scope.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/scope.h @@ -4,12 +4,17 @@ #pragma once #include "opentelemetry/context/runtime_context.h" -#include "opentelemetry/trace/span.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/span_metadata.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { + +class Span; + /** * Controls how long a span is active. * diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/semantic_conventions.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/semantic_conventions.h similarity index 77% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/semantic_conventions.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/semantic_conventions.h index d0485704e..ecada99a4 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/semantic_conventions.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/semantic_conventions.h @@ -21,7 +21,7 @@ namespace SemanticConventions /** * The URL of the OpenTelemetry schema for these keys and values. */ -static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.18.0"; +static constexpr const char *kSchemaUrl = "https://opentelemetry.io/schemas/1.20.0"; /** * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of @@ -40,6 +40,33 @@ static constexpr const char *kExceptionMessage = "exception.message"; */ static constexpr const char *kExceptionStacktrace = "exception.stacktrace"; +/** + * HTTP request method. + */ +static constexpr const char *kHttpMethod = "http.method"; + +/** + * HTTP response status code. + */ +static constexpr const char *kHttpStatusCode = "http.status_code"; + +/** + * The URI scheme identifying the used protocol. + */ +static constexpr const char *kHttpScheme = "http.scheme"; + +/** + * The matched route (path template in the format used by the respective server framework). See note +below + * + *

Notes: +

  • MUST NOT be populated when this is not supported by the HTTP server framework as the +route attribute should have low-cardinality and the URI path can NOT substitute it. SHOULD include +the application +root if there is one.
+ */ +static constexpr const char *kHttpRoute = "http.route"; + /** * The name identifies the event. */ @@ -54,12 +81,23 @@ unrelated events. */ static constexpr const char *kEventDomain = "event.domain"; +/** + * A unique identifier for the Log Record. + * + *

Notes: +

  • If an id is provided, other log records with the same id will be considered duplicates +and can be removed safely. This means, that two distinguishable log records MUST have different +values. The id MAY be an Universally Unique Lexicographically +Sortable Identifier (ULID), but other identifiers (e.g. UUID) may be used as needed.
+ */ +static constexpr const char *kLogRecordUid = "log.record.uid"; + /** * The full invoked ARN as provided on the {@code Context} passed to the function ({@code Lambda-Runtime-Invoked-Function-Arn} header on the {@code /runtime/invocation/next} applicable). * *

Notes: -

  • This may be different from {@code faas.id} if an alias is involved.
+
  • This may be different from {@code cloud.resource_id} if an alias is involved.
*/ static constexpr const char *kAwsLambdaInvokedArn = "aws.lambda.invoked_arn"; @@ -143,9 +181,6 @@ static constexpr const char *kDbName = "db.name"; /** * The database statement being executed. - * - *

Notes: -

  • The value may be sanitized to exclude sensitive information.
*/ static constexpr const char *kDbStatement = "db.statement"; @@ -243,6 +278,46 @@ static constexpr const char *kDbMongodbCollection = "db.mongodb.collection"; */ static constexpr const char *kDbSqlTable = "db.sql.table"; +/** + * Unique Cosmos client instance id. + */ +static constexpr const char *kDbCosmosdbClientId = "db.cosmosdb.client_id"; + +/** + * CosmosDB Operation Type. + */ +static constexpr const char *kDbCosmosdbOperationType = "db.cosmosdb.operation_type"; + +/** + * Cosmos client connection mode. + */ +static constexpr const char *kDbCosmosdbConnectionMode = "db.cosmosdb.connection_mode"; + +/** + * Cosmos DB container name. + */ +static constexpr const char *kDbCosmosdbContainer = "db.cosmosdb.container"; + +/** + * Request payload size in bytes + */ +static constexpr const char *kDbCosmosdbRequestContentLength = "db.cosmosdb.request_content_length"; + +/** + * Cosmos DB status code. + */ +static constexpr const char *kDbCosmosdbStatusCode = "db.cosmosdb.status_code"; + +/** + * Cosmos DB sub status code. + */ +static constexpr const char *kDbCosmosdbSubStatusCode = "db.cosmosdb.sub_status_code"; + +/** + * RU consumed for that operation + */ +static constexpr const char *kDbCosmosdbRequestCharge = "db.cosmosdb.request_charge"; + /** * Name of the code, either "OK" or "ERROR". MUST NOT be set if the status code * is UNSET. @@ -255,7 +330,7 @@ static constexpr const char *kOtelStatusCode = "otel.status_code"; static constexpr const char *kOtelStatusDescription = "otel.status_description"; /** - * Type of the trigger which caused this function execution. + * Type of the trigger which caused this function invocation. * *

Notes:

  • For the server/consumer span on the incoming side, @@ -268,9 +343,9 @@ lambda, which is often HTTP).
static constexpr const char *kFaasTrigger = "faas.trigger"; /** - * The execution ID of the current function execution. + * The invocation ID of the current function invocation. */ -static constexpr const char *kFaasExecution = "faas.execution"; +static constexpr const char *kFaasInvocationId = "faas.invocation_id"; /** * The name of the source on which the triggering operation was performed. For example, in Cloud @@ -343,6 +418,30 @@ static constexpr const char *kFaasInvokedProvider = "faas.invoked_provider"; */ static constexpr const char *kFaasInvokedRegion = "faas.invoked_region"; +/** + * The unique identifier of the feature flag. + */ +static constexpr const char *kFeatureFlagKey = "feature_flag.key"; + +/** + * The name of the service provider that performs the flag evaluation. + */ +static constexpr const char *kFeatureFlagProviderName = "feature_flag.provider_name"; + +/** + * SHOULD be a semantic identifier for a value. If one is unavailable, a stringified version of the +value can be used. + * + *

Notes: +

  • A semantic identifier, commonly referred to as a variant, provides a means +for referring to a value without including the value itself. This can +provide additional context for understanding the meaning behind a value. +For example, the variant {@code red} maybe be used for the value {@code #c05543}.
  • A +stringified version of the value can be used in situations where a semantic identifier is +unavailable. String representation of the value should be determined by the implementer.
+ */ +static constexpr const char *kFeatureFlagVariant = "feature_flag.variant"; + /** * Transport protocol used. See note below. */ @@ -351,18 +450,18 @@ static constexpr const char *kNetTransport = "net.transport"; /** * Application layer protocol used. The value SHOULD be normalized to lowercase. */ -static constexpr const char *kNetAppProtocolName = "net.app.protocol.name"; +static constexpr const char *kNetProtocolName = "net.protocol.name"; /** * Version of the application layer protocol used. See note below. * *

Notes: -

  • {@code net.app.protocol.version} refers to the version of the protocol used and might be +
    • {@code net.protocol.version} refers to the version of the protocol used and might be different from the protocol client's version. If the HTTP client used has a version of {@code 0.27.2}, but sends HTTP version {@code 1.1}, this attribute should be set to {@code 1.1}.
    */ -static constexpr const char *kNetAppProtocolVersion = "net.app.protocol.version"; +static constexpr const char *kNetProtocolVersion = "net.protocol.version"; /** * Remote socket peer name. @@ -521,31 +620,6 @@ static constexpr const char *kCodeLineno = "code.lineno"; */ static constexpr const char *kCodeColumn = "code.column"; -/** - * HTTP request method. - */ -static constexpr const char *kHttpMethod = "http.method"; - -/** - * HTTP response status code. - */ -static constexpr const char *kHttpStatusCode = "http.status_code"; - -/** - * Kind of HTTP protocol used. - * - *

    Notes: -

    • If {@code net.transport} is not specified, it can be assumed to be {@code IP.TCP} except - if {@code http.flavor} is {@code QUIC}, in which case {@code IP.UDP} is assumed.
    - */ -static constexpr const char *kHttpFlavor = "http.flavor"; - -/** - * Value of the HTTP - * User-Agent header sent by the client. - */ -static constexpr const char *kHttpUserAgent = "http.user_agent"; - /** * The size of the request payload body in bytes. This is the number of bytes transferred excluding * headers and is often, but not always, present as the Notes: - - */ -static constexpr const char *kHttpRoute = "http.route"; - /** * The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For). @@ -621,6 +679,12 @@ the closest proxy.
*/ static constexpr const char *kHttpClientIp = "http.client_ip"; +/** + * The AWS request ID as returned in the response headers {@code x-amz-request-id} or {@code + * x-amz-requestid}. + */ +static constexpr const char *kAwsRequestId = "aws.request_id"; + /** * The keys in the {@code RequestItems} object field. */ @@ -739,6 +803,117 @@ static constexpr const char *kAwsDynamodbAttributeDefinitions = static constexpr const char *kAwsDynamodbGlobalSecondaryIndexUpdates = "aws.dynamodb.global_secondary_index_updates"; +/** + * The S3 bucket name the request refers to. Corresponds to the {@code --bucket} parameter of the S3 API operations. + * + *

Notes: +

  • The {@code bucket} attribute is applicable to all S3 operations that reference a bucket, +i.e. that require the bucket name as a mandatory parameter. This applies to almost all S3 operations +except {@code list-buckets}.
+ */ +static constexpr const char *kAwsS3Bucket = "aws.s3.bucket"; + +/** + * The S3 object key the request refers to. Corresponds to the {@code --key} parameter of the S3 API operations. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3Key = "aws.s3.key"; + +/** + * The source object (in the form {@code bucket}/{@code key}) for the copy operation. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3CopySource = "aws.s3.copy_source"; + +/** + * Upload ID that identifies the multipart upload. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3UploadId = "aws.s3.upload_id"; + +/** + * The delete request container that specifies the objects to be deleted. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3Delete = "aws.s3.delete"; + +/** + * The part number of the part being uploaded in a multipart-upload operation. This is a positive +integer between 1 and 10,000. + * + *

Notes: +

+ */ +static constexpr const char *kAwsS3PartNumber = "aws.s3.part_number"; + /** * The name of the operation being executed. */ @@ -791,11 +966,6 @@ the broker. */ static constexpr const char *kMessagingDestinationName = "messaging.destination.name"; -/** - * The kind of message destination - */ -static constexpr const char *kMessagingDestinationKind = "messaging.destination.kind"; - /** * Low cardinality representation of the messaging destination name * @@ -829,11 +999,6 @@ broker. */ static constexpr const char *kMessagingSourceName = "messaging.source.name"; -/** - * The kind of message source - */ -static constexpr const char *kMessagingSourceKind = "messaging.source.kind"; - /** * Low cardinality representation of the messaging source name * @@ -1054,6 +1219,62 @@ static constexpr const char *kRpcJsonrpcErrorCode = "rpc.jsonrpc.error_code"; */ static constexpr const char *kRpcJsonrpcErrorMessage = "rpc.jsonrpc.error_message"; +/** + * Whether this is a received or sent message. + */ +static constexpr const char *kMessageType = "message.type"; + +/** + * MUST be calculated as two different counters starting from {@code 1} one for sent messages and + one for received message. + * + *

Notes: +

  • This way we guarantee that the values will be consistent between different + implementations.
+ */ +static constexpr const char *kMessageId = "message.id"; + +/** + * Compressed size of the message in bytes. + */ +static constexpr const char *kMessageCompressedSize = "message.compressed_size"; + +/** + * Uncompressed size of the message in bytes. + */ +static constexpr const char *kMessageUncompressedSize = "message.uncompressed_size"; + +/** + * The error codes of the Connect + * request. Error codes are always string values. + */ +static constexpr const char *kRpcConnectRpcErrorCode = "rpc.connect_rpc.error_code"; + +/** + * SHOULD be set to true if the exception event is recorded at a point where it is known that the +exception is escaping the scope of the span. + * + *

Notes: +

  • An exception is considered to have escaped (or left) the scope of a span, +if that span is ended while the exception is still logically "in flight". +This may be actually "in flight" in some languages (e.g. if the exception +is passed to a Context manager's {@code __exit__} method in Python) but will +usually be caught at the point of recording the exception in most languages.
  • It is usually +not possible to determine at the point where an exception is thrown whether it will escape the scope +of a span. However, it is trivial to know that an exception will escape, if one checks for an active +exception just before ending the span, as done in the example +above.
  • It follows that an exception may still escape the scope of the span even if the +{@code exception.escaped} attribute was not set or set to false, since the event might have been +recorded at a time where it was not clear whether the exception will escape.
+ */ +static constexpr const char *kExceptionEscaped = "exception.escaped"; + +/** + * Value of the HTTP + * User-Agent header sent by the client. + */ +static constexpr const char *kUserAgentOriginal = "user_agent.original"; + // Enum definitions namespace EventDomainValues { @@ -1177,6 +1398,8 @@ static constexpr const char *kOpensearch = "opensearch"; static constexpr const char *kClickhouse = "clickhouse"; /** Cloud Spanner. */ static constexpr const char *kSpanner = "spanner"; +/** Trino. */ +static constexpr const char *kTrino = "trino"; } // namespace DbSystemValues namespace DbCassandraConsistencyLevelValues @@ -1205,6 +1428,48 @@ static constexpr const char *kSerial = "serial"; static constexpr const char *kLocalSerial = "local_serial"; } // namespace DbCassandraConsistencyLevelValues +namespace DbCosmosdbOperationTypeValues +{ +/** invalid. */ +static constexpr const char *kInvalid = "Invalid"; +/** create. */ +static constexpr const char *kCreate = "Create"; +/** patch. */ +static constexpr const char *kPatch = "Patch"; +/** read. */ +static constexpr const char *kRead = "Read"; +/** read_feed. */ +static constexpr const char *kReadFeed = "ReadFeed"; +/** delete. */ +static constexpr const char *kDelete = "Delete"; +/** replace. */ +static constexpr const char *kReplace = "Replace"; +/** execute. */ +static constexpr const char *kExecute = "Execute"; +/** query. */ +static constexpr const char *kQuery = "Query"; +/** head. */ +static constexpr const char *kHead = "Head"; +/** head_feed. */ +static constexpr const char *kHeadFeed = "HeadFeed"; +/** upsert. */ +static constexpr const char *kUpsert = "Upsert"; +/** batch. */ +static constexpr const char *kBatch = "Batch"; +/** query_plan. */ +static constexpr const char *kQueryPlan = "QueryPlan"; +/** execute_javascript. */ +static constexpr const char *kExecuteJavascript = "ExecuteJavaScript"; +} // namespace DbCosmosdbOperationTypeValues + +namespace DbCosmosdbConnectionModeValues +{ +/** Gateway (HTTP) connections mode. */ +static constexpr const char *kGateway = "gateway"; +/** Direct connection. */ +static constexpr const char *kDirect = "direct"; +} // namespace DbCosmosdbConnectionModeValues + namespace OtelStatusCodeValues { /** The operation has been validated by an Application developer or Operator to have completed @@ -1336,22 +1601,6 @@ static constexpr const char *kNrnsa = "nrnsa"; static constexpr const char *kLteCa = "lte_ca"; } // namespace NetHostConnectionSubtypeValues -namespace HttpFlavorValues -{ -/** HTTP/1.0. */ -static constexpr const char *kHttp10 = "1.0"; -/** HTTP/1.1. */ -static constexpr const char *kHttp11 = "1.1"; -/** HTTP/2. */ -static constexpr const char *kHttp20 = "2.0"; -/** HTTP/3. */ -static constexpr const char *kHttp30 = "3.0"; -/** SPDY protocol. */ -static constexpr const char *kSpdy = "SPDY"; -/** QUIC protocol. */ -static constexpr const char *kQuic = "QUIC"; -} // namespace HttpFlavorValues - namespace GraphqlOperationTypeValues { /** GraphQL query. */ @@ -1362,22 +1611,6 @@ static constexpr const char *kMutation = "mutation"; static constexpr const char *kSubscription = "subscription"; } // namespace GraphqlOperationTypeValues -namespace MessagingDestinationKindValues -{ -/** A message sent to a queue. */ -static constexpr const char *kQueue = "queue"; -/** A message sent to a topic. */ -static constexpr const char *kTopic = "topic"; -} // namespace MessagingDestinationKindValues - -namespace MessagingSourceKindValues -{ -/** A message received from a queue. */ -static constexpr const char *kQueue = "queue"; -/** A message received from a topic. */ -static constexpr const char *kTopic = "topic"; -} // namespace MessagingSourceKindValues - namespace MessagingOperationValues { /** publish. */ @@ -1418,6 +1651,8 @@ static constexpr const char *kJavaRmi = "java_rmi"; static constexpr const char *kDotnetWcf = "dotnet_wcf"; /** Apache Dubbo. */ static constexpr const char *kApacheDubbo = "apache_dubbo"; +/** Connect RPC. */ +static constexpr const char *kConnectRpc = "connect_rpc"; } // namespace RpcSystemValues namespace RpcGrpcStatusCodeValues @@ -1458,6 +1693,50 @@ static constexpr const int kDataLoss = 15; static constexpr const int kUnauthenticated = 16; } // namespace RpcGrpcStatusCodeValues +namespace MessageTypeValues +{ +/** sent. */ +static constexpr const char *kSent = "SENT"; +/** received. */ +static constexpr const char *kReceived = "RECEIVED"; +} // namespace MessageTypeValues + +namespace RpcConnectRpcErrorCodeValues +{ +/** cancelled. */ +static constexpr const char *kCancelled = "cancelled"; +/** unknown. */ +static constexpr const char *kUnknown = "unknown"; +/** invalid_argument. */ +static constexpr const char *kInvalidArgument = "invalid_argument"; +/** deadline_exceeded. */ +static constexpr const char *kDeadlineExceeded = "deadline_exceeded"; +/** not_found. */ +static constexpr const char *kNotFound = "not_found"; +/** already_exists. */ +static constexpr const char *kAlreadyExists = "already_exists"; +/** permission_denied. */ +static constexpr const char *kPermissionDenied = "permission_denied"; +/** resource_exhausted. */ +static constexpr const char *kResourceExhausted = "resource_exhausted"; +/** failed_precondition. */ +static constexpr const char *kFailedPrecondition = "failed_precondition"; +/** aborted. */ +static constexpr const char *kAborted = "aborted"; +/** out_of_range. */ +static constexpr const char *kOutOfRange = "out_of_range"; +/** unimplemented. */ +static constexpr const char *kUnimplemented = "unimplemented"; +/** internal. */ +static constexpr const char *kInternal = "internal"; +/** unavailable. */ +static constexpr const char *kUnavailable = "unavailable"; +/** data_loss. */ +static constexpr const char *kDataLoss = "data_loss"; +/** unauthenticated. */ +static constexpr const char *kUnauthenticated = "unauthenticated"; +} // namespace RpcConnectRpcErrorCodeValues + } // namespace SemanticConventions } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span.h similarity index 98% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span.h index 77de4050d..ffd145a30 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span.h @@ -7,11 +7,9 @@ #include "opentelemetry/common/attribute_value.h" #include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/type_traits.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/canonical_code.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_metadata.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context.h similarity index 78% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context.h index e19bb9900..944bdc022 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context.h @@ -3,11 +3,12 @@ #pragma once -#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/span_id.h" #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/trace_state.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -29,7 +30,7 @@ class SpanContext final SpanContext(bool sampled_flag, bool is_remote) noexcept : trace_id_(), span_id_(), - trace_flags_(opentelemetry::trace::TraceFlags((uint8_t)sampled_flag)), + trace_flags_(trace::TraceFlags((uint8_t)sampled_flag)), is_remote_(is_remote), trace_state_(TraceState::GetDefault()) {} @@ -52,19 +53,16 @@ class SpanContext final bool IsValid() const noexcept { return trace_id_.IsValid() && span_id_.IsValid(); } // @returns the trace_flags associated with this span_context - const opentelemetry::trace::TraceFlags &trace_flags() const noexcept { return trace_flags_; } + const trace::TraceFlags &trace_flags() const noexcept { return trace_flags_; } // @returns the trace_id associated with this span_context - const opentelemetry::trace::TraceId &trace_id() const noexcept { return trace_id_; } + const trace::TraceId &trace_id() const noexcept { return trace_id_; } // @returns the span_id associated with this span_context - const opentelemetry::trace::SpanId &span_id() const noexcept { return span_id_; } + const trace::SpanId &span_id() const noexcept { return span_id_; } // @returns the trace_state associated with this span_context - const nostd::shared_ptr trace_state() const noexcept - { - return trace_state_; - } + const nostd::shared_ptr trace_state() const noexcept { return trace_state_; } /* * @param that SpanContext for comparing. @@ -86,11 +84,11 @@ class SpanContext final bool IsSampled() const noexcept { return trace_flags_.IsSampled(); } private: - opentelemetry::trace::TraceId trace_id_; - opentelemetry::trace::SpanId span_id_; - opentelemetry::trace::TraceFlags trace_flags_; + trace::TraceId trace_id_; + trace::SpanId span_id_; + trace::TraceFlags trace_flags_; bool is_remote_; - nostd::shared_ptr trace_state_; + nostd::shared_ptr trace_state_; }; } // namespace trace OPENTELEMETRY_END_NAMESPACE diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context_kv_iterable.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context_kv_iterable.h similarity index 80% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context_kv_iterable.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context_kv_iterable.h index 0f1ec307f..8f3010ce9 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context_kv_iterable.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context_kv_iterable.h @@ -26,8 +26,8 @@ class SpanContextKeyValueIterable * @return true if every SpanContext/key-value pair was iterated over */ virtual bool ForEachKeyValue( - nostd::function_ref - callback) const noexcept = 0; + nostd::function_ref callback) + const noexcept = 0; /** * @return the number of key-value pairs */ @@ -40,9 +40,8 @@ class SpanContextKeyValueIterable class NullSpanContext : public SpanContextKeyValueIterable { public: - bool ForEachKeyValue( - nostd::function_ref - /* callback */) const noexcept override + bool ForEachKeyValue(nostd::function_ref + /* callback */) const noexcept override { return true; } diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context_kv_iterable_view.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context_kv_iterable_view.h similarity index 84% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context_kv_iterable_view.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context_kv_iterable_view.h index 252b4cf17..6a21aaf54 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_context_kv_iterable_view.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_context_kv_iterable_view.h @@ -8,7 +8,11 @@ #include #include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/utility.h" +#include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_context_kv_iterable.h" #include "opentelemetry/version.h" @@ -57,9 +61,8 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable public: explicit SpanContextKeyValueIterableView(const T &links) noexcept : container_{&links} {} - bool ForEachKeyValue( - nostd::function_ref - callback) const noexcept override + bool ForEachKeyValue(nostd::function_ref + callback) const noexcept override { auto iter = std::begin(*container_); auto last = std::end(*container_); @@ -78,11 +81,10 @@ class SpanContextKeyValueIterableView final : public SpanContextKeyValueIterable private: const T *container_; - bool do_callback( - SpanContext span_context, - const common::KeyValueIterable &attributes, - nostd::function_ref - callback) const noexcept + bool do_callback(SpanContext span_context, + const common::KeyValueIterable &attributes, + nostd::function_ref + callback) const noexcept { if (!callback(span_context, attributes)) { diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_id.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_id.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_id.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_id.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_metadata.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_metadata.h similarity index 96% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_metadata.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_metadata.h index f27239c73..5e615ea53 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_metadata.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_metadata.h @@ -4,6 +4,7 @@ #pragma once #include "opentelemetry/common/timestamp.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_startoptions.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_startoptions.h similarity index 86% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_startoptions.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_startoptions.h index 9265574a5..2180394d7 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/span_startoptions.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/span_startoptions.h @@ -3,9 +3,12 @@ #pragma once +#include "opentelemetry/common/timestamp.h" #include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/trace/span_context.h" #include "opentelemetry/trace/span_metadata.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace @@ -33,7 +36,7 @@ struct StartSpanOptions // // This defaults to an invalid span context. In this case, the Span is // automatically parented to the currently active span. - nostd::variant parent = SpanContext::GetInvalid(); + nostd::variant parent = SpanContext::GetInvalid(); // TODO: // SpanContext remote_parent; diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_flags.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_flags.h similarity index 98% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_flags.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_flags.h index 3cfbb022f..1f7bf4f9b 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_flags.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_flags.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include "opentelemetry/nostd/span.h" #include "opentelemetry/version.h" diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_id.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_id.h similarity index 100% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_id.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_id.h diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_state.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_state.h similarity index 96% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_state.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_state.h index 28fd126fe..f424b0199 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/trace_state.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/trace_state.h @@ -4,14 +4,15 @@ #pragma once #include -#include #include #include "opentelemetry/common/kv_properties.h" +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/version.h" #if defined(OPENTELEMETRY_HAVE_WORKING_REGEX) # include @@ -73,7 +74,7 @@ class OPENTELEMETRY_EXPORT TraceState if (!IsValidKey(key) || !IsValidValue(value)) { // invalid header. return empty TraceState - ts->kv_properties_.reset(new opentelemetry::common::KeyValueProperties()); + ts->kv_properties_.reset(new common::KeyValueProperties()); break; } @@ -229,8 +230,8 @@ class OPENTELEMETRY_EXPORT TraceState } private: - TraceState() : kv_properties_(new opentelemetry::common::KeyValueProperties()) {} - TraceState(size_t size) : kv_properties_(new opentelemetry::common::KeyValueProperties(size)) {} + TraceState() : kv_properties_(new common::KeyValueProperties()) {} + TraceState(size_t size) : kv_properties_(new common::KeyValueProperties(size)) {} static nostd::string_view TrimString(nostd::string_view str, size_t left, size_t right) { @@ -311,7 +312,7 @@ class OPENTELEMETRY_EXPORT TraceState private: // Store entries in a C-style array to avoid using std::array or std::vector. - nostd::unique_ptr kv_properties_; + nostd::unique_ptr kv_properties_; }; } // namespace trace diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/tracer.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/tracer.h similarity index 99% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/tracer.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/tracer.h index b60336a48..82b4d0ea0 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/tracer.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/tracer.h @@ -3,10 +3,11 @@ #pragma once +#include + #include "opentelemetry/context/context.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/trace/default_span.h" #include "opentelemetry/trace/scope.h" #include "opentelemetry/trace/span.h" @@ -14,8 +15,6 @@ #include "opentelemetry/trace/span_startoptions.h" #include "opentelemetry/version.h" -#include - OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/tracer_provider.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/tracer_provider.h similarity index 94% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/tracer_provider.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/tracer_provider.h index 9d3125db4..bc8ff8da8 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/trace/tracer_provider.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/trace/tracer_provider.h @@ -5,11 +5,14 @@ #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace trace { + +class Tracer; + /** * Creates new Tracer instances. */ diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/version.h b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/version.h similarity index 85% rename from extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/version.h rename to extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/version.h index 92d9b41b1..f3c2978cf 100644 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/version.h +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/include/opentelemetry/version.h @@ -7,10 +7,10 @@ #include "opentelemetry/detail/preprocessor.h" #define OPENTELEMETRY_ABI_VERSION_NO 1 -#define OPENTELEMETRY_VERSION "1.8.3" +#define OPENTELEMETRY_VERSION "1.10.0" #define OPENTELEMETRY_VERSION_MAJOR 1 -#define OPENTELEMETRY_VERSION_MINOR 8 -#define OPENTELEMETRY_VERSION_PATCH 3 +#define OPENTELEMETRY_VERSION_MINOR 10 +#define OPENTELEMETRY_VERSION_PATCH 0 #define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/CMakeLists.txt new file mode 100644 index 000000000..2d051cc72 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(core) +add_subdirectory(context) +add_subdirectory(plugin) +add_subdirectory(nostd) +add_subdirectory(trace) +add_subdirectory(metrics) +if(WITH_LOGS_PREVIEW) + add_subdirectory(logs) +endif() +add_subdirectory(common) +add_subdirectory(baggage) +add_subdirectory(singleton) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/BUILD new file mode 100644 index 000000000..a3783a63c --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/BUILD @@ -0,0 +1,30 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "baggage_test", + srcs = [ + "baggage_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +otel_cc_benchmark( + name = "baggage_benchmark", + srcs = ["baggage_benchmark.cc"], + tags = [ + "api", + "benchmark", + "test", + ], + deps = ["//api"], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/CMakeLists.txt new file mode 100644 index 000000000..0b0fee52a --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include(GoogleTest) + +foreach(testname baggage_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX baggage. + TEST_LIST ${testname}) +endforeach() + +if(WITH_BENCHMARK) + add_executable(baggage_benchmark baggage_benchmark.cc) + target_link_libraries(baggage_benchmark benchmark::benchmark + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +endif() +add_subdirectory(propagation) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/baggage_benchmark.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/baggage_benchmark.cc new file mode 100644 index 000000000..0f2efa993 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/baggage_benchmark.cc @@ -0,0 +1,119 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/baggage/baggage.h" +#include "opentelemetry/nostd/string_view.h" + +#include +#include + +using namespace opentelemetry::baggage; +namespace nostd = opentelemetry::nostd; + +namespace +{ + +const size_t kNumEntries = 10; + +std::string header_with_custom_entries(size_t num_entries) +{ + std::string header; + for (size_t i = 0; i < num_entries; i++) + { + std::string key = "ADecentlyLargekey" + std::to_string(i); + std::string value = "ADecentlyLargeValue" + std::to_string(i); + header += key + "=" + value; + if (i != num_entries - 1) + { + header += ","; + } + } + return header; +} + +void BM_CreateBaggageFromTenEntries(benchmark::State &state) +{ + std::string header = header_with_custom_entries(kNumEntries); + while (state.KeepRunning()) + { + auto baggage = Baggage::FromHeader(header); + } +} +BENCHMARK(BM_CreateBaggageFromTenEntries); + +void BM_ExtractBaggageHavingTenEntries(benchmark::State &state) +{ + auto baggage = Baggage::FromHeader(header_with_custom_entries(kNumEntries)); + while (state.KeepRunning()) + { + baggage->GetAllEntries( + [](nostd::string_view /* key */, nostd::string_view /* value */) { return true; }); + } +} +BENCHMARK(BM_ExtractBaggageHavingTenEntries); + +void BM_CreateBaggageFrom180Entries(benchmark::State &state) +{ + std::string header = header_with_custom_entries(Baggage::kMaxKeyValuePairs); + while (state.KeepRunning()) + { + auto baggage = Baggage::FromHeader(header); + } +} +BENCHMARK(BM_CreateBaggageFrom180Entries); + +void BM_ExtractBaggageWith180Entries(benchmark::State &state) +{ + auto baggage = Baggage::FromHeader(header_with_custom_entries(Baggage::kMaxKeyValuePairs)); + while (state.KeepRunning()) + { + baggage->GetAllEntries( + [](nostd::string_view /* key */, nostd::string_view /* value */) { return true; }); + } +} +BENCHMARK(BM_ExtractBaggageWith180Entries); + +void BM_SetValueBaggageWithTenEntries(benchmark::State &state) +{ + auto baggage = Baggage::FromHeader( + header_with_custom_entries(kNumEntries - 1)); // 9 entries, and add one new + while (state.KeepRunning()) + { + auto new_baggage = baggage->Set("new_key", "new_value"); + } +} +BENCHMARK(BM_SetValueBaggageWithTenEntries); + +void BM_SetValueBaggageWith180Entries(benchmark::State &state) +{ + auto baggage = Baggage::FromHeader(header_with_custom_entries( + Baggage::kMaxKeyValuePairs - 1)); // keep 179 entries, and add one new + while (state.KeepRunning()) + { + auto new_baggage = baggage->Set("new_key", "new_value"); + } +} +BENCHMARK(BM_SetValueBaggageWith180Entries); + +void BM_BaggageToHeaderTenEntries(benchmark::State &state) +{ + auto baggage = Baggage::FromHeader(header_with_custom_entries(kNumEntries)); + while (state.KeepRunning()) + { + auto new_baggage = baggage->ToHeader(); + } +} +BENCHMARK(BM_BaggageToHeaderTenEntries); + +void BM_BaggageToHeader180Entries(benchmark::State &state) +{ + auto baggage = Baggage::FromHeader(header_with_custom_entries(Baggage::kMaxKeyValuePairs)); + while (state.KeepRunning()) + { + auto new_baggage = baggage->ToHeader(); + } +} +BENCHMARK(BM_BaggageToHeader180Entries); +} // namespace + +BENCHMARK_MAIN(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/baggage_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/baggage_test.cc new file mode 100644 index 000000000..9c14fc892 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/baggage_test.cc @@ -0,0 +1,218 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/string_view.h" + +#include +#include +#include + +#include "opentelemetry/baggage/baggage.h" + +using namespace opentelemetry; +using namespace opentelemetry::baggage; + +std::string header_with_custom_entries(size_t num_entries) +{ + std::string header; + for (size_t i = 0; i < num_entries; i++) + { + std::string key = "key" + std::to_string(i); + std::string value = "value" + std::to_string(i); + header += key + "=" + value; + if (i != num_entries - 1) + { + header += ","; + } + } + return header; +} + +std::string header_with_custom_size(size_t key_value_size, size_t num_entries) +{ + std::string header = ""; + for (size_t i = 0; i < num_entries; i++) + { + std::string str = std::to_string(i + 1); + str += "="; + assert(key_value_size > str.size()); + for (size_t j = str.size(); j < key_value_size; j++) + { + str += "a"; + } + + header += str + ','; + } + + header.pop_back(); + return header; +} + +TEST(BaggageTest, ValidateExtractHeader) +{ + auto invalid_key_value_size_header = header_with_custom_size(Baggage::kMaxKeyValueSize + 5, 1); + + struct + { + const char *input; + std::vector keys; + std::vector values; + } testcases[] = { + {"k1=v1", {"k1"}, {"v1"}}, + {"k1=V1,K2=v2;metadata,k3=v3", + {"k1", "K2", "k3"}, + {"V1", "v2;metadata", "v3"}}, // metadata is part of value + {",k1 =v1,k2=v2 ; metadata,", + {"k1", "k2"}, + {"v1", "v2; metadata"}}, // key and value are trimmed + {"1a-2f%40foo=bar%251,a%2A%2Ffoo-_%2Fbar=bar+4", + {"1a-2f@foo", "a*/foo-_/bar"}, + {"bar%1", "bar 4"}}, // decoding is done properly + {"k1=v1,invalidmember,k2=v2", {"k1", "k2"}, {"v1", "v2"}}, // invalid member is skipped + {",", {}, {}}, + {",=,", {}, {}}, + {"", {}, {}}, + {"k1=%5zv", {}, {}}, // invalid hex : invalid second digit + {"k1=%5", {}, {}}, // invalid hex : missing two digits + {"k%z2=v1", {}, {}}, // invalid hex : invalid first digit + {"k%00=v1", {}, {}}, // key not valid + {"k=v%7f", {}, {}}, // value not valid + {invalid_key_value_size_header.data(), {}, {}}}; + for (auto &testcase : testcases) + { + auto baggage = Baggage::FromHeader(testcase.input); + size_t index = 0; + baggage->GetAllEntries([&testcase, &index](nostd::string_view key, nostd::string_view value) { + EXPECT_EQ(key, testcase.keys[index]); + EXPECT_EQ(value, testcase.values[index]); + index++; + return true; + }); + } + + // For header with maximum threshold pairs, no pair is dropped + auto max_pairs_header = header_with_custom_entries(Baggage::kMaxKeyValuePairs); + EXPECT_EQ(Baggage::FromHeader(max_pairs_header.data())->ToHeader(), max_pairs_header.data()); + + // Entries beyond threshold are dropped + auto baggage = Baggage::FromHeader(header_with_custom_entries(Baggage::kMaxKeyValuePairs + 1)); + auto header = baggage->ToHeader(); + common::KeyValueStringTokenizer kv_str_tokenizer(header); + int expected_tokens = Baggage::kMaxKeyValuePairs; + EXPECT_EQ(kv_str_tokenizer.NumTokens(), expected_tokens); + + // For header with total size more than threshold, baggage is empty + int num_pairs_with_max_size = Baggage::kMaxSize / Baggage::kMaxKeyValueSize; + auto invalid_total_size_header = + header_with_custom_size(Baggage::kMaxKeyValueSize, num_pairs_with_max_size + 1); + EXPECT_EQ(Baggage::FromHeader(invalid_total_size_header.data())->ToHeader(), ""); +} + +TEST(BaggageTest, ValidateInjectHeader) +{ + struct + { + std::vector keys; + std::vector values; + const char *header; + } testcases[] = {{{"k1"}, {"v1"}, "k1=v1"}, + {{"k3", "k2", "k1"}, {"", "v2", "v1"}, "k1=v1,k2=v2,k3="}, // empty value + {{"1a-2f@foo", "a*/foo-_/bar"}, + {"bar%1", "bar 4"}, + "a%2A%2Ffoo-_%2Fbar=bar+4,1a-2f%40foo=bar%251"}, // encoding is done properly + {{"foo 1"}, + {"bar 1; metadata ; ;;"}, + "foo+1=bar+1; metadata ; ;;"}}; // metadata is added without encoding + + for (auto &testcase : testcases) + { + nostd::shared_ptr baggage(new Baggage{}); + for (size_t i = 0; i < testcase.keys.size(); i++) + { + baggage = baggage->Set(testcase.keys[i], testcase.values[i]); + } + EXPECT_EQ(baggage->ToHeader(), testcase.header); + } +} + +TEST(BaggageTest, BaggageGet) +{ + auto header = header_with_custom_entries(Baggage::kMaxKeyValuePairs); + auto baggage = Baggage::FromHeader(header); + + std::string value; + EXPECT_TRUE(baggage->GetValue("key0", value)); + EXPECT_EQ(value, "value0"); + EXPECT_TRUE(baggage->GetValue("key16", value)); + EXPECT_EQ(value, "value16"); + + EXPECT_TRUE(baggage->GetValue("key31", value)); + EXPECT_EQ(value, "value31"); + + EXPECT_FALSE(baggage->GetValue("key181", value)); +} + +TEST(BaggageTest, BaggageSet) +{ + std::string header = "k1=v1,k2=v2"; + auto baggage = Baggage::FromHeader(header); + + std::string value; + baggage = baggage->Set("k3", "v3"); + EXPECT_TRUE(baggage->GetValue("k3", value)); + EXPECT_EQ(value, "v3"); + + baggage = baggage->Set("k3", "v3_1"); // key should be updated with the latest value + EXPECT_TRUE(baggage->GetValue("k3", value)); + EXPECT_EQ(value, "v3_1"); + + header = header_with_custom_entries(Baggage::kMaxKeyValuePairs); + baggage = Baggage::FromHeader(header); + baggage = baggage->Set("key0", "0"); // updating on max list should work + EXPECT_TRUE(baggage->GetValue("key0", value)); + EXPECT_EQ(value, "0"); + + header = "k1=v1,k2=v2"; + baggage = Baggage::FromHeader(header); + baggage = baggage->Set("", "n_v1"); // adding invalid key, should return copy of same baggage + EXPECT_EQ(baggage->ToHeader(), header); + + header = "k1=v1,k2=v2"; + baggage = Baggage::FromHeader(header); + baggage = baggage->Set("k1", "\x1A"); // adding invalid value, should return copy of same baggage + EXPECT_EQ(baggage->ToHeader(), header); +} + +TEST(BaggageTest, BaggageRemove) +{ + auto header = header_with_custom_entries(Baggage::kMaxKeyValuePairs); + auto baggage = Baggage::FromHeader(header); + std::string value; + + // existing key is removed + EXPECT_TRUE(baggage->GetValue("key0", value)); + auto new_baggage = baggage->Delete("key0"); + EXPECT_FALSE(new_baggage->GetValue("key0", value)); + + // trying Delete on non existent key + EXPECT_FALSE(baggage->GetValue("key181", value)); + auto new_baggage_2 = baggage->Delete("key181"); + EXPECT_FALSE(new_baggage_2->GetValue("key181", value)); +} + +TEST(BaggageTest, BaggageGetAll) +{ + std::string baggage_header = "k1=v1,k2=v2,k3=v3"; + auto baggage = Baggage::FromHeader(baggage_header); + const int kNumPairs = 3; + nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; + nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; + size_t index = 0; + baggage->GetAllEntries( + [&keys, &values, &index](nostd::string_view key, nostd::string_view value) { + EXPECT_EQ(key, keys[index]); + EXPECT_EQ(value, values[index]); + index++; + return true; + }); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/BUILD new file mode 100644 index 000000000..2b820ed3c --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/BUILD @@ -0,0 +1,19 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "baggage_propagator_test", + srcs = [ + "baggage_propagator_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/CMakeLists.txt new file mode 100644 index 000000000..b4142ead8 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +foreach(testname baggage_propagator_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX baggage. + TEST_LIST ${testname}) +endforeach() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/baggage_propagator_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/baggage_propagator_test.cc new file mode 100644 index 000000000..94fe8b005 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/baggage/propagation/baggage_propagator_test.cc @@ -0,0 +1,113 @@ + +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/baggage/propagation/baggage_propagator.h" +#include +#include +#include +#include "opentelemetry/baggage/baggage_context.h" + +using namespace opentelemetry; +using namespace opentelemetry::baggage::propagation; + +class BaggageCarrierTest : public context::propagation::TextMapCarrier +{ +public: + BaggageCarrierTest() = default; + virtual nostd::string_view Get(nostd::string_view key) const noexcept override + { + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); + } + + std::map headers_; +}; + +static BaggagePropagator format; + +TEST(BaggagePropagatorTest, ExtractNoBaggageHeader) +{ + BaggageCarrierTest carrier; + carrier.headers_ = {}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + auto ctx2_baggage = baggage::GetBaggage(ctx2); + EXPECT_EQ(ctx2_baggage->ToHeader(), ""); +} + +TEST(BaggagePropagatorTest, ExtractAndInjectBaggage) +{ + // create header string for baggage larger than allowed size (kMaxKeyValueSize) + std::string very_large_baggage_header = + std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'k') + "=" + + std::string(baggage::Baggage::kMaxKeyValueSize / 2 + 1, 'v'); + + std::map baggages = { + {"key1=val1,key2=val2", "key1=val1,key2=val2"}, // valid header + {"key1 = val1, key2 =val2 ", "key1=val1,key2=val2"}, // valid header with spaces + {"key1=val1,key2=val2;prop=1", "key1=val1,key2=val2;prop=1"}, // valid header with properties + {"key%2C1=val1,key2=val2%2Cval3", + "key%2C1=val1,key2=val2%2Cval3"}, // valid header with url escape + {"key1=val1,key2=val2,a,val3", "key1=val1,key2=val2"}, // valid header with invalid value + {"key1=,key2=val2", "key1=,key2=val2"}, // valid header with empty value + {"invalid_header", ""}, // invalid header + {very_large_baggage_header, ""}}; // baggage header larger than allowed size. + + for (auto baggage : baggages) + { + BaggageCarrierTest carrier1; + carrier1.headers_[baggage::kBaggageHeader.data()] = baggage.first; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier1, ctx1); + + BaggageCarrierTest carrier2; + format.Inject(carrier2, ctx2); + EXPECT_EQ(carrier2.headers_[baggage::kBaggageHeader.data()], baggage.second); + + std::vector fields; + format.Fields([&fields](nostd::string_view field) { + fields.push_back(field.data()); + return true; + }); + EXPECT_EQ(fields.size(), 1); + EXPECT_EQ(fields[0], baggage::kBaggageHeader.data()); + } +} + +TEST(BaggagePropagatorTest, InjectEmptyHeader) +{ + // Test Missing baggage from context + BaggageCarrierTest carrier; + context::Context ctx = context::Context{}; + format.Inject(carrier, ctx); + EXPECT_EQ(carrier.headers_.find(baggage::kBaggageHeader), carrier.headers_.end()); + + { + // Test empty baggage in context + BaggageCarrierTest carrier1; + carrier1.headers_[baggage::kBaggageHeader.data()] = ""; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier1, ctx1); + format.Inject(carrier, ctx2); + EXPECT_EQ(carrier.headers_.find(baggage::kBaggageHeader), carrier.headers_.end()); + } + { + // Invalid baggage in context + BaggageCarrierTest carrier1; + carrier1.headers_[baggage::kBaggageHeader.data()] = "InvalidBaggageData"; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier1, ctx1); + + format.Inject(carrier, ctx2); + EXPECT_EQ(carrier.headers_.find(baggage::kBaggageHeader), carrier.headers_.end()); + } +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/BUILD new file mode 100644 index 000000000..5ea2d5d57 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/BUILD @@ -0,0 +1,45 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +otel_cc_benchmark( + name = "spinlock_benchmark", + srcs = ["spinlock_benchmark.cc"], + tags = [ + "api", + "benchmark", + "test", + ], + deps = ["//api"], +) + +cc_test( + name = "kv_properties_test", + srcs = [ + "kv_properties_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "string_util_test", + srcs = [ + "string_util_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/CMakeLists.txt new file mode 100644 index 000000000..8d77dcdfa --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include(GoogleTest) + +foreach(testname kv_properties_test string_util_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX common. + TEST_LIST ${testname}) +endforeach() + +if(WITH_BENCHMARK) + add_executable(spinlock_benchmark spinlock_benchmark.cc) + target_link_libraries(spinlock_benchmark benchmark::benchmark + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +endif() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/kv_properties_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/kv_properties_test.cc new file mode 100644 index 000000000..e5d9a2439 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/kv_properties_test.cc @@ -0,0 +1,235 @@ + +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include +#include +#include + +// ------------------------- Entry class tests --------------------------------- + +using namespace opentelemetry; +using opentelemetry::common::KeyValueProperties; +// Test constructor that takes a key-value pair +TEST(EntryTest, KeyValueConstruction) +{ + opentelemetry::nostd::string_view key = "test_key"; + opentelemetry::nostd::string_view val = "test_value"; + KeyValueProperties::Entry e(key, val); + + EXPECT_EQ(key.size(), e.GetKey().size()); + EXPECT_EQ(key, e.GetKey()); + + EXPECT_EQ(val.size(), e.GetValue().size()); + EXPECT_EQ(val, e.GetValue()); +} + +// Test copy constructor +TEST(EntryTest, Copy) +{ + KeyValueProperties::Entry e("test_key", "test_value"); + KeyValueProperties::Entry copy(e); + EXPECT_EQ(copy.GetKey(), e.GetKey()); + EXPECT_EQ(copy.GetValue(), e.GetValue()); +} + +// Test assignment operator +TEST(EntryTest, Assignment) +{ + KeyValueProperties::Entry e("test_key", "test_value"); + KeyValueProperties::Entry empty; + empty = e; + EXPECT_EQ(empty.GetKey(), e.GetKey()); + EXPECT_EQ(empty.GetValue(), e.GetValue()); +} + +TEST(EntryTest, SetValue) +{ + KeyValueProperties::Entry e("test_key", "test_value"); + opentelemetry::nostd::string_view new_val = "new_value"; + e.SetValue(new_val); + + EXPECT_EQ(new_val.size(), e.GetValue().size()); + EXPECT_EQ(new_val, e.GetValue()); +} + +// ------------------------- KeyValueStringTokenizer tests --------------------------------- + +using opentelemetry::common::KeyValueStringTokenizer; +using opentelemetry::common::KeyValueStringTokenizerOptions; + +TEST(KVStringTokenizer, SinglePair) +{ + bool valid_kv; + nostd::string_view key, value; + opentelemetry::nostd::string_view str = "k1=v1"; + KeyValueStringTokenizerOptions opts; + KeyValueStringTokenizer tk(str, opts); + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_TRUE(valid_kv); + EXPECT_EQ(key, "k1"); + EXPECT_EQ(value, "v1"); + EXPECT_FALSE(tk.next(valid_kv, key, value)); +} + +TEST(KVStringTokenizer, AcceptEmptyEntries) +{ + bool valid_kv; + nostd::string_view key, value; + opentelemetry::nostd::string_view str = ":k1=v1::k2=v2: "; + KeyValueStringTokenizerOptions opts; + opts.member_separator = ':'; + opts.ignore_empty_members = false; + + KeyValueStringTokenizer tk(str, opts); + EXPECT_TRUE(tk.next(valid_kv, key, value)); // empty pair + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_TRUE(valid_kv); + EXPECT_EQ(key, "k1"); + EXPECT_EQ(value, "v1"); + EXPECT_TRUE(tk.next(valid_kv, key, value)); // empty pair + EXPECT_EQ(key, ""); + EXPECT_EQ(value, ""); + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_TRUE(tk.next(valid_kv, key, value)); // empty pair + EXPECT_FALSE(tk.next(valid_kv, key, value)); +} + +TEST(KVStringTokenizer, ValidPairsWithEmptyEntries) +{ + opentelemetry::nostd::string_view str = "k1:v1===k2:v2=="; + bool valid_kv; + nostd::string_view key, value; + KeyValueStringTokenizerOptions opts; + opts.member_separator = '='; + opts.key_value_separator = ':'; + + KeyValueStringTokenizer tk(str, opts); + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_TRUE(valid_kv); + EXPECT_EQ(key, "k1"); + EXPECT_EQ(value, "v1"); + + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_TRUE(valid_kv); + EXPECT_EQ(key, "k2"); + EXPECT_EQ(value, "v2"); + + EXPECT_FALSE(tk.next(valid_kv, key, value)); +} + +TEST(KVStringTokenizer, InvalidPairs) +{ + opentelemetry::nostd::string_view str = "k1=v1,invalid ,, k2=v2 ,invalid"; + KeyValueStringTokenizer tk(str); + bool valid_kv; + nostd::string_view key, value; + EXPECT_TRUE(tk.next(valid_kv, key, value)); + + EXPECT_TRUE(valid_kv); + EXPECT_EQ(key, "k1"); + EXPECT_EQ(value, "v1"); + + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_FALSE(valid_kv); + + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_TRUE(valid_kv); + EXPECT_EQ(key, "k2"); + EXPECT_EQ(value, "v2"); + + EXPECT_TRUE(tk.next(valid_kv, key, value)); + EXPECT_FALSE(valid_kv); + + EXPECT_FALSE(tk.next(valid_kv, key, value)); +} + +TEST(KVStringTokenizer, NumTokens) +{ + struct + { + const char *input; + size_t expected; + } testcases[] = {{"k1=v1", 1}, + {" ", 1}, + {"k1=v1,k2=v2,k3=v3", 3}, + {"k1=v1,", 1}, + {"k1=v1,k2=v2,invalidmember", 3}, + {"", 0}}; + for (auto &testcase : testcases) + { + KeyValueStringTokenizer tk(testcase.input); + EXPECT_EQ(tk.NumTokens(), testcase.expected); + } +} + +//------------------------- KeyValueProperties tests --------------------------------- + +TEST(KeyValueProperties, PopulateKVIterableContainer) +{ + std::vector> kv_pairs = {{"k1", "v1"}, {"k2", "v2"}}; + + auto kv_properties = KeyValueProperties(kv_pairs); + EXPECT_EQ(kv_properties.Size(), 2); + + std::string value; + bool present = kv_properties.GetValue("k1", value); + EXPECT_TRUE(present); + EXPECT_EQ(value, "v1"); + + present = kv_properties.GetValue("k2", value); + EXPECT_TRUE(present); + EXPECT_EQ(value, "v2"); +} + +TEST(KeyValueProperties, AddEntry) +{ + auto kv_properties = KeyValueProperties(1); + kv_properties.AddEntry("k1", "v1"); + std::string value; + bool present = kv_properties.GetValue("k1", value); + EXPECT_TRUE(present); + EXPECT_EQ(value, "v1"); + + kv_properties.AddEntry("k2", "v2"); // entry will not be added as max size reached. + EXPECT_EQ(kv_properties.Size(), 1); + present = kv_properties.GetValue("k2", value); + EXPECT_FALSE(present); +} + +TEST(KeyValueProperties, GetValue) +{ + auto kv_properties = KeyValueProperties(1); + kv_properties.AddEntry("k1", "v1"); + std::string value; + bool present = kv_properties.GetValue("k1", value); + EXPECT_TRUE(present); + EXPECT_EQ(value, "v1"); + + present = kv_properties.GetValue("k3", value); + EXPECT_FALSE(present); +} + +TEST(KeyValueProperties, GetAllEntries) +{ + std::vector> kv_pairs = { + {"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; + const size_t kNumPairs = 3; + opentelemetry::nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; + opentelemetry::nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; + auto kv_properties = KeyValueProperties(kv_pairs); + + size_t index = 0; + kv_properties.GetAllEntries( + [&keys, &values, &index](nostd::string_view key, nostd::string_view value) { + EXPECT_EQ(key, keys[index]); + EXPECT_EQ(value, values[index]); + index++; + return true; + }); + + EXPECT_EQ(index, kNumPairs); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/spinlock_benchmark.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/spinlock_benchmark.cc new file mode 100644 index 000000000..53ea633d1 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/spinlock_benchmark.cc @@ -0,0 +1,157 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/common/spin_lock_mutex.h" + +#include +#include + +namespace +{ +using opentelemetry::common::SpinLockMutex; + +constexpr int TightLoopLocks = 10000; + +// Runs a thrash-test where we spin up N threads, each of which will +// attempt to lock-mutate-unlock a total of `TightLoopLocks` times. +// +// lock: A lambda denoting how to lock. Accepts a reference to `SpinLockType`. +// unlock: A lambda denoting how to unlock. Accepts a reference to `SpinLockType`. +template +inline void SpinThrash(benchmark::State &s, SpinLockType &spinlock, LockF lock, UnlockF unlock) +{ + auto num_threads = s.range(0); + // Value we will increment, fighting over a spinlock. + // The contention is meant to be brief, as close to our expected + // use cases of "updating pointers" or "pushing an event onto a buffer". + std::int64_t value = 0; + + std::vector threads; + threads.reserve(num_threads); + + // Timing loop + for (auto _ : s) + { + for (auto i = 0; i < num_threads; i++) + { + threads.emplace_back([&] { + // Increment value once each time the lock is acquired. Spin a few times + // to ensure maximum thread contention. + for (int i = 0; i < TightLoopLocks; i++) + { + lock(spinlock); + value++; + unlock(spinlock); + } + }); + } + // Join threads + for (auto &thread : threads) + thread.join(); + threads.clear(); + } +} + +// Benchmark of full spin-lock implementation. +static void BM_SpinLockThrashing(benchmark::State &s) +{ + SpinLockMutex spinlock; + SpinThrash( + s, spinlock, [](SpinLockMutex &m) { m.lock(); }, [](SpinLockMutex &m) { m.unlock(); }); +} + +// Naive `while(try_lock()) {}` implementation of lock. +static void BM_NaiveSpinLockThrashing(benchmark::State &s) +{ + SpinLockMutex spinlock; + SpinThrash( + s, spinlock, + [](SpinLockMutex &m) { + while (!m.try_lock()) + { + // Left this comment to keep the same format on old and new versions of clang-format + } + }, + [](SpinLockMutex &m) { m.unlock(); }); +} + +// Simple `while(try_lock()) { yield-processor }` +static void BM_ProcYieldSpinLockThrashing(benchmark::State &s) +{ + SpinLockMutex spinlock; + SpinThrash( + s, spinlock, + [](SpinLockMutex &m) { + while (!m.try_lock()) + { +#if defined(_MSC_VER) + YieldProcessor(); +#elif defined(__i386__) || defined(__x86_64__) +# if defined(__clang__) || defined(__INTEL_COMPILER) + _mm_pause(); +# else + __builtin_ia32_pause(); +# endif +#elif defined(__arm__) + __asm__ volatile("yield" ::: "memory"); +#endif + } + }, + [](SpinLockMutex &m) { m.unlock(); }); +} + +// SpinLock thrashing with thread::yield(). +static void BM_ThreadYieldSpinLockThrashing(benchmark::State &s) +{ +#if defined(__cpp_lib_atomic_value_initialization) && \ + __cpp_lib_atomic_value_initialization >= 201911L + std::atomic_flag mutex{}; +#else + std::atomic_flag mutex = ATOMIC_FLAG_INIT; +#endif + SpinThrash( + s, mutex, + [](std::atomic_flag &l) { + uint32_t try_count = 0; + while (l.test_and_set(std::memory_order_acq_rel)) + { + ++try_count; + if (try_count % 32) + { + std::this_thread::yield(); + } + } + std::this_thread::yield(); + }, + [](std::atomic_flag &l) { l.clear(std::memory_order_release); }); +} + +// Run the benchmarks at 2x thread/core and measure the amount of time to thrash around. +BENCHMARK(BM_SpinLockThrashing) + ->RangeMultiplier(2) + ->Range(1, std::thread::hardware_concurrency()) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Unit(benchmark::kMillisecond); +BENCHMARK(BM_ProcYieldSpinLockThrashing) + ->RangeMultiplier(2) + ->Range(1, std::thread::hardware_concurrency()) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Unit(benchmark::kMillisecond); +BENCHMARK(BM_NaiveSpinLockThrashing) + ->RangeMultiplier(2) + ->Range(1, std::thread::hardware_concurrency()) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Unit(benchmark::kMillisecond); +BENCHMARK(BM_ThreadYieldSpinLockThrashing) + ->RangeMultiplier(2) + ->Range(1, std::thread::hardware_concurrency()) + ->MeasureProcessCPUTime() + ->UseRealTime() + ->Unit(benchmark::kMillisecond); + +} // namespace + +BENCHMARK_MAIN(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/string_util_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/string_util_test.cc new file mode 100644 index 000000000..da2e63511 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/common/string_util_test.cc @@ -0,0 +1,47 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include +#include +#include + +// ------------------------- StringUtil class tests --------------------------------- + +using opentelemetry::common::StringUtil; + +TEST(StringUtilTest, TrimStringWithIndex) +{ + struct + { + const char *input; + const char *expected; + } testcases[] = {{"k1=v1", "k1=v1"}, {"k1=v1,k2=v2, k3=v3", "k1=v1,k2=v2, k3=v3"}, + {" k1=v1", "k1=v1"}, {"k1=v1 ", "k1=v1"}, + {" k1=v1 ", "k1=v1"}, {" ", ""}}; + for (auto &testcase : testcases) + { + EXPECT_EQ(StringUtil::Trim(testcase.input, 0, strlen(testcase.input) - 1), testcase.expected); + } +} + +TEST(StringUtilTest, TrimString) +{ + struct + { + const char *input; + const char *expected; + } testcases[] = {{"k1=v1", "k1=v1"}, + {"k1=v1,k2=v2, k3=v3", "k1=v1,k2=v2, k3=v3"}, + {" k1=v1", "k1=v1"}, + {"k1=v1 ", "k1=v1"}, + {" k1=v1 ", "k1=v1"}, + {" ", ""}, + {"", ""}}; + for (auto &testcase : testcases) + { + EXPECT_EQ(StringUtil::Trim(testcase.input), testcase.expected); + } +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/BUILD new file mode 100644 index 000000000..64b2cb750 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/BUILD @@ -0,0 +1,34 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "context_test", + srcs = [ + "context_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "runtime_context_test", + srcs = [ + "runtime_context_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/CMakeLists.txt new file mode 100644 index 000000000..25ce51bc2 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(propagation) + +include(GoogleTest) + +foreach(testname context_test runtime_context_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX context. + TEST_LIST ${testname}) +endforeach() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/context_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/context_test.cc new file mode 100644 index 000000000..975e11f8c --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/context_test.cc @@ -0,0 +1,147 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/context/context.h" + +#include + +#include + +using namespace opentelemetry; + +// Tests that the context constructor accepts an std::map. +TEST(ContextTest, ContextIterableAcceptsMap) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + context::Context test_context = context::Context(map_test); +} + +// Tests that the GetValue method returns the expected value. +TEST(ContextTest, ContextGetValueReturnsExpectedValue) +{ + std::map map_test = {{"test_key", (int64_t)123}, + {"foo_key", (int64_t)456}}; + const context::Context test_context = context::Context(map_test); + EXPECT_EQ(nostd::get(test_context.GetValue("test_key")), 123); + EXPECT_EQ(nostd::get(test_context.GetValue("foo_key")), 456); +} + +// Tests that the SetValues method accepts an std::map. +TEST(ContextTest, ContextSetValuesAcceptsMap) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_test_write = {{"foo_key", (int64_t)456}}; + + context::Context test_context = context::Context(map_test); + context::Context foo_context = test_context.SetValues(map_test_write); + + EXPECT_EQ(nostd::get(foo_context.GetValue("test_key")), 123); + EXPECT_EQ(nostd::get(foo_context.GetValue("foo_key")), 456); +} + +// Tests that the SetValues method accepts a nostd::string_view and +// context::ContextValue. +TEST(ContextTest, ContextSetValuesAcceptsStringViewContextValue) +{ + nostd::string_view string_view_test = "string_view"; + context::ContextValue context_value_test = (int64_t)123; + + context::Context test_context = context::Context(string_view_test, context_value_test); + context::Context foo_context = test_context.SetValue(string_view_test, context_value_test); + + EXPECT_EQ(nostd::get(foo_context.GetValue(string_view_test)), 123); +} + +// Tests that the original context does not change when a value is +// written to it. +TEST(ContextTest, ContextImmutability) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + + context::Context context_test = context::Context(map_test); + context::Context context_foo = context_test.SetValue("foo_key", (int64_t)456); + + EXPECT_FALSE(nostd::holds_alternative(context_test.GetValue("foo_key"))); +} + +// Tests that writing the same to a context overwrites the original value. +TEST(ContextTest, ContextKeyOverwrite) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + + context::Context context_test = context::Context(map_test); + context::Context context_foo = context_test.SetValue("test_key", (int64_t)456); + + EXPECT_EQ(nostd::get(context_foo.GetValue("test_key")), 456); +} + +// Tests that the new Context Objects inherits the keys and values +// of the original context object. +TEST(ContextTest, ContextInheritance) +{ + using M = std::map; + + M m1 = {{"test_key", (int64_t)123}, {"foo_key", (int64_t)321}}; + M m2 = {{"other_key", (int64_t)789}, {"another_key", (int64_t)987}}; + + context::Context test_context = context::Context(m1); + context::Context foo_context = test_context.SetValues(m2); + + EXPECT_EQ(nostd::get(foo_context.GetValue("test_key")), 123); + EXPECT_EQ(nostd::get(foo_context.GetValue("foo_key")), 321); + EXPECT_EQ(nostd::get(foo_context.GetValue("other_key")), 789); + EXPECT_EQ(nostd::get(foo_context.GetValue("another_key")), 987); + + EXPECT_TRUE(nostd::holds_alternative(test_context.GetValue("other_key"))); + EXPECT_TRUE(nostd::holds_alternative(test_context.GetValue("another_key"))); +} + +// Tests that copying a context copies the key value pairs as expected. +TEST(ContextTest, ContextCopyOperator) +{ + std::map test_map = { + {"test_key", (int64_t)123}, {"foo_key", (int64_t)456}, {"other_key", (int64_t)789}}; + + context::Context test_context = context::Context(test_map); + context::Context copied_context = test_context; + + EXPECT_EQ(nostd::get(copied_context.GetValue("test_key")), 123); + EXPECT_EQ(nostd::get(copied_context.GetValue("foo_key")), 456); + EXPECT_EQ(nostd::get(copied_context.GetValue("other_key")), 789); +} + +// Tests that the Context accepts an empty map. +TEST(ContextTest, ContextEmptyMap) +{ + std::map map_test = {}; + context::Context test_context = context::Context(map_test); +} + +// Tests that if a key exists within a context has key will return true +// false if not. +TEST(ContextTest, ContextHasKey) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + const context::Context context_test = context::Context(map_test); + EXPECT_TRUE(context_test.HasKey("test_key")); + EXPECT_FALSE(context_test.HasKey("foo_key")); +} + +// Tests that a copied context returns true when compared +TEST(ContextTest, ContextCopyCompare) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + context::Context context_test = context::Context(map_test); + context::Context copied_test = context_test; + EXPECT_TRUE(context_test == copied_test); +} + +// Tests that two differently constructed contexts return false when compared +TEST(ContextTest, ContextDiffCompare) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + std::map map_foo = {{"foo_key", (int64_t)123}}; + context::Context context_test = context::Context(map_test); + context::Context foo_test = context::Context(map_foo); + EXPECT_FALSE(context_test == foo_test); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/BUILD new file mode 100644 index 000000000..d62d67649 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/BUILD @@ -0,0 +1,19 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "composite_propagator_test", + srcs = [ + "composite_propagator_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/CMakeLists.txt new file mode 100644 index 000000000..844aa123f --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +foreach(testname composite_propagator_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX trace. + TEST_LIST ${testname}) +endforeach() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/composite_propagator_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/composite_propagator_test.cc new file mode 100644 index 000000000..918f8cedd --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/propagation/composite_propagator_test.cc @@ -0,0 +1,124 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context.h" + +#include "opentelemetry/context/propagation/composite_propagator.h" +#include "opentelemetry/context/propagation/text_map_propagator.h" +#include "opentelemetry/trace/default_span.h" +#include "opentelemetry/trace/propagation/b3_propagator.h" +#include "opentelemetry/trace/propagation/http_trace_context.h" + +#include +#include +#include + +#include + +using namespace opentelemetry; + +template +static std::string Hex(const T &id_item) +{ + char buf[T::kSize * 2]; + id_item.ToLowerBase16(buf); + return std::string(buf, sizeof(buf)); +} + +class TextMapCarrierTest : public context::propagation::TextMapCarrier +{ +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override + { + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); + } + + std::map headers_; +}; + +class CompositePropagatorTest : public ::testing::Test +{ + +public: + CompositePropagatorTest() + { + std::vector> propogator_list = {}; + std::unique_ptr w3c_propogator( + new trace::propagation::HttpTraceContext()); + std::unique_ptr b3_propogator( + new trace::propagation::B3Propagator()); + propogator_list.push_back(std::move(w3c_propogator)); + propogator_list.push_back(std::move(b3_propogator)); + + composite_propagator_ = + new context::propagation::CompositePropagator(std::move(propogator_list)); + } + + ~CompositePropagatorTest() { delete composite_propagator_; } + +protected: + context::propagation::CompositePropagator *composite_propagator_; +}; + +TEST_F(CompositePropagatorTest, Extract) +{ + TextMapCarrierTest carrier; + carrier.headers_ = { + {"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; + context::Context ctx1 = context::Context{}; + + context::Context ctx2 = composite_propagator_->Extract(carrier, ctx1); + + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); + + auto span = nostd::get>(ctx2_span); + + // confirm last propagator in composite propagator list (B3 here) wins for same key + // ("active_span" here). + EXPECT_EQ(Hex(span->GetContext().trace_id()), "80f198ee56343ba864fe8b2a57d3eff7"); + EXPECT_EQ(Hex(span->GetContext().span_id()), "e457b5a2e4d86bd1"); + EXPECT_EQ(span->GetContext().IsSampled(), true); + EXPECT_EQ(span->GetContext().IsRemote(), true); +} + +TEST_F(CompositePropagatorTest, Inject) +{ + TextMapCarrierTest carrier; + constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; + constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, + trace::TraceFlags{true}, false}; + nostd::shared_ptr sp{new trace::DefaultSpan{span_context}}; + + // Set `sp` as the currently active span, which must be used by `Inject`. + trace::Scope scoped_span{sp}; + + composite_propagator_->Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["traceparent"], + "00-0102030405060708090a0b0c0d0e0f10-0102030405060708-01"); + EXPECT_EQ(carrier.headers_["b3"], "0102030405060708090a0b0c0d0e0f10-0102030405060708-1"); + + std::vector fields; + composite_propagator_->Fields([&fields](nostd::string_view field) { + fields.push_back(field.data()); + return true; + }); + EXPECT_EQ(fields.size(), 3); + EXPECT_EQ(fields[0], trace::propagation::kTraceParent); + EXPECT_EQ(fields[1], trace::propagation::kTraceState); + EXPECT_EQ(fields[2], trace::propagation::kB3CombinedHeader); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/runtime_context_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/runtime_context_test.cc new file mode 100644 index 000000000..e85fc6350 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/context/runtime_context_test.cc @@ -0,0 +1,135 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/context/context.h" + +#include + +using namespace opentelemetry; + +// Tests that GetCurrent returns the current context +TEST(RuntimeContextTest, GetCurrent) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + context::Context test_context = context::Context(map_test); + auto old_context = context::RuntimeContext::Attach(test_context); + EXPECT_EQ(context::RuntimeContext::GetCurrent(), test_context); +} + +// Tests that detach resets the context to the previous context +TEST(RuntimeContextTest, Detach) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + context::Context test_context = context::Context(map_test); + context::Context foo_context = context::Context(map_test); + + auto test_context_token = context::RuntimeContext::Attach(test_context); + auto foo_context_token = context::RuntimeContext::Attach(foo_context); + + foo_context_token.reset(); + EXPECT_EQ(context::RuntimeContext::GetCurrent(), test_context); + test_context_token.reset(); +} + +// Tests that detach returns false when the wrong context is provided +TEST(RuntimeContextTest, DetachWrongContext) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + context::Context test_context = context::Context(map_test); + auto test_context_token = context::RuntimeContext::Attach(test_context); + EXPECT_TRUE(context::RuntimeContext::Detach(*test_context_token)); + EXPECT_FALSE(context::RuntimeContext::Detach(*test_context_token)); +} + +// Tests that the ThreadLocalContext can handle three attached contexts +TEST(RuntimeContextTest, ThreeAttachDetach) +{ + std::map map_test = {{"test_key", (int64_t)123}}; + context::Context test_context = context::Context(map_test); + context::Context foo_context = context::Context(map_test); + context::Context other_context = context::Context(map_test); + auto test_context_token = context::RuntimeContext::Attach(test_context); + auto foo_context_token = context::RuntimeContext::Attach(foo_context); + auto other_context_token = context::RuntimeContext::Attach(other_context); + + EXPECT_TRUE(context::RuntimeContext::Detach(*other_context_token)); + EXPECT_TRUE(context::RuntimeContext::Detach(*foo_context_token)); + EXPECT_TRUE(context::RuntimeContext::Detach(*test_context_token)); +} + +// Tests that SetValue returns a context with the passed in data and the +// RuntimeContext data when a context is not passed into the +// RuntimeContext::SetValue method. +TEST(RuntimeContextTest, SetValueRuntimeContext) +{ + context::Context foo_context = context::Context("foo_key", (int64_t)596); + auto old_context_token = context::RuntimeContext::Attach(foo_context); + context::Context test_context = context::RuntimeContext::SetValue("test_key", (int64_t)123); + EXPECT_EQ(nostd::get(test_context.GetValue("test_key")), 123); + EXPECT_EQ(nostd::get(test_context.GetValue("foo_key")), 596); +} + +// Tests that SetValue returns a context with the passed in data and the +// passed in context data when a context* is passed into the +// RuntimeContext::SetValue method. +TEST(RuntimeContextTest, SetValueOtherContext) +{ + context::Context foo_context = context::Context("foo_key", (int64_t)596); + context::Context test_context = + context::RuntimeContext::SetValue("test_key", (int64_t)123, &foo_context); + EXPECT_EQ(nostd::get(test_context.GetValue("test_key")), 123); + EXPECT_EQ(nostd::get(test_context.GetValue("foo_key")), 596); +} + +// Tests that SetValue returns the ContextValue associated with the +// passed in string and the current Runtime Context +TEST(RuntimeContextTest, GetValueRuntimeContext) +{ + context::Context foo_context = context::Context("foo_key", (int64_t)596); + auto old_context_token = context::RuntimeContext::Attach(foo_context); + EXPECT_EQ(nostd::get(context::RuntimeContext::GetValue("foo_key")), 596); +} + +// Tests that SetValue returns the ContextValue associated with the +// passed in string and the passed in context +TEST(RuntimeContextTest, GetValueOtherContext) +{ + context::Context foo_context = context::Context("foo_key", (int64_t)596); + EXPECT_EQ(nostd::get(context::RuntimeContext::GetValue("foo_key", &foo_context)), 596); +} + +// Test that any possible order of context detaching doesn't mess up the stack. +TEST(RuntimeContextTest, DetachOutOfOrder) +{ + std::vector indices; + indices.push_back(0); + indices.push_back(1); + indices.push_back(2); + indices.push_back(3); + + std::vector contexts; + for (auto i : indices) + { + contexts.push_back(context::Context("index", (int64_t)i)); + } + + do + { + std::vector> tokens; + + for (auto &c : contexts) + { + tokens.push_back(context::RuntimeContext::Attach(c)); + } + + for (size_t i : indices) + { + auto token = std::move(tokens.at(i)); + context::RuntimeContext::Detach(*token); + } + + EXPECT_EQ(context::RuntimeContext::GetCurrent(), context::Context()); + + } while (std::next_permutation(indices.begin(), indices.end())); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/BUILD new file mode 100644 index 000000000..38c65e6d3 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/BUILD @@ -0,0 +1,32 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cc_test( + name = "timestamp_test", + srcs = [ + "timestamp_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "version_test", + srcs = [ + "version_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/CMakeLists.txt new file mode 100644 index 000000000..7123f9a70 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include(GoogleTest) + +add_executable(timestamp_test timestamp_test.cc) +target_link_libraries(timestamp_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +gtest_add_tests( + TARGET timestamp_test + TEST_PREFIX trace. + TEST_LIST timestamp_test) + +add_executable(version_test version_test.cc) +target_link_libraries(version_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +gtest_add_tests( + TARGET version_test + TEST_PREFIX version. + TEST_LIST version_test) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/timestamp_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/timestamp_test.cc new file mode 100644 index 000000000..8efc0215b --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/timestamp_test.cc @@ -0,0 +1,67 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/common/timestamp.h" + +#include + +using opentelemetry::common::SteadyTimestamp; +using opentelemetry::common::SystemTimestamp; + +template +static bool AreNearlyEqual(const Timestamp &t1, const Timestamp &t2) noexcept +{ + return std::abs(std::chrono::duration_cast(t2 - t1).count()) < 2; +} + +TEST(SystemTimestampTest, Construction) +{ + auto now_system = std::chrono::system_clock::now(); + + SystemTimestamp t1; + EXPECT_EQ(t1.time_since_epoch(), std::chrono::nanoseconds{0}); + + SystemTimestamp t2{now_system}; + EXPECT_TRUE(AreNearlyEqual(now_system, static_cast(t2))); + EXPECT_EQ(std::chrono::duration_cast(now_system.time_since_epoch()), + t2.time_since_epoch()); +} + +TEST(SystemTimestampTest, Comparison) +{ + SystemTimestamp t1; + SystemTimestamp t2; + SystemTimestamp t3{std::chrono::nanoseconds{2}}; + + EXPECT_EQ(t1, t1); + EXPECT_EQ(t1, t2); + EXPECT_EQ(t2, t1); + EXPECT_NE(t1, t3); + EXPECT_NE(t3, t1); +} + +TEST(SteadyTimestampTest, Construction) +{ + auto now_steady = std::chrono::steady_clock::now(); + + SteadyTimestamp t1; + EXPECT_EQ(t1.time_since_epoch(), std::chrono::nanoseconds{0}); + + SteadyTimestamp t2{now_steady}; + EXPECT_TRUE(AreNearlyEqual(now_steady, static_cast(t2))); + EXPECT_EQ(std::chrono::duration_cast(now_steady.time_since_epoch()), + t2.time_since_epoch()); +} + +TEST(SteadyTimestampTest, Comparison) +{ + SteadyTimestamp t1; + SteadyTimestamp t2; + SteadyTimestamp t3{std::chrono::nanoseconds{2}}; + + EXPECT_EQ(t1, t1); + EXPECT_EQ(t1, t2); + EXPECT_EQ(t2, t1); + EXPECT_NE(t1, t3); + EXPECT_NE(t3, t1); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/version_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/version_test.cc new file mode 100644 index 000000000..2e360ffda --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/core/version_test.cc @@ -0,0 +1,16 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/version.h" + +#include + +TEST(VersionTest, Consistency) +{ + char expected[10]; + snprintf(expected, sizeof(expected), "%d.%d.%d", OPENTELEMETRY_VERSION_MAJOR, + OPENTELEMETRY_VERSION_MINOR, OPENTELEMETRY_VERSION_PATCH); + + std::string actual = OPENTELEMETRY_VERSION; + EXPECT_EQ(actual, expected); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/BUILD new file mode 100644 index 000000000..521620a20 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/BUILD @@ -0,0 +1,36 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "provider_test", + srcs = [ + "provider_test.cc", + ], + tags = [ + "api", + "logs", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "logger_test", + srcs = [ + "logger_test.cc", + ], + tags = [ + "api", + "logs", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/CMakeLists.txt new file mode 100644 index 000000000..3d1278274 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +foreach(testname provider_test logger_test) + add_executable(logs_api_${testname} "${testname}.cc") + target_link_libraries(logs_api_${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET logs_api_${testname} + TEST_PREFIX logs. + TEST_LIST logs_api_${testname}) +endforeach() + +if(WITH_BENCHMARK) + add_executable(logger_benchmark logger_benchmark.cc) + target_link_libraries(logger_benchmark benchmark::benchmark + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +endif() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/logger_benchmark.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/logger_benchmark.cc new file mode 100644 index 000000000..fa5ad2b0c --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/logger_benchmark.cc @@ -0,0 +1,260 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/logs/logger.h" +# include "opentelemetry/logs/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" + +# include +# include +# include +# include +# include +# include + +# include + +using opentelemetry::logs::EventId; +using opentelemetry::logs::Logger; +using opentelemetry::logs::LoggerProvider; +using opentelemetry::logs::Provider; +using opentelemetry::logs::Severity; +using opentelemetry::nostd::shared_ptr; +using opentelemetry::nostd::span; +using opentelemetry::nostd::string_view; + +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; +namespace trace = opentelemetry::trace; +namespace log_api = opentelemetry::logs; + +namespace +{ + +constexpr int64_t kMaxIterations = 1000000000; + +class Barrier +{ +public: + explicit Barrier(std::size_t iCount) : mThreshold(iCount), mCount(iCount), mGeneration(0) {} + + void Wait() + { + std::unique_lock lLock{mMutex}; + auto lGen = mGeneration; + if (!--mCount) + { + mGeneration++; + mCount = mThreshold; + mCond.notify_all(); + } + else + { + mCond.wait(lLock, [this, lGen] { return lGen != mGeneration; }); + } + } + +private: + std::mutex mMutex; + std::condition_variable mCond; + std::size_t mThreshold; + std::size_t mCount; + std::size_t mGeneration; +}; + +static void ThreadRoutine(Barrier &barrier, + benchmark::State &state, + int thread_id, + std::function func) +{ + barrier.Wait(); + + if (thread_id == 0) + { + state.ResumeTiming(); + } + + barrier.Wait(); + + func(); + + if (thread_id == 0) + { + state.PauseTiming(); + } + + barrier.Wait(); +} + +void MultiThreadRunner(benchmark::State &state, std::function func) +{ + int num_threads = std::thread::hardware_concurrency(); + + Barrier barrier(num_threads); + + std::vector threads; + + for (int i = 0; i < num_threads; i++) + { + threads.emplace_back(ThreadRoutine, std::ref(barrier), std::ref(state), i, func); + } + + for (auto &thread : threads) + { + thread.join(); + } +} + +static void BM_UnstructuredLog(benchmark::State &state) +{ + auto lp = Provider::GetLoggerProvider(); + auto logger = lp->GetLogger("UnstructuredLog"); + + for (auto _ : state) + { + state.PauseTiming(); + + MultiThreadRunner(state, [&logger]() { + for (int64_t i = 0; i < kMaxIterations; i++) + { + logger->Trace("This is a simple unstructured log message"); + } + }); + + state.ResumeTiming(); + } +} +BENCHMARK(BM_UnstructuredLog); + +static void BM_StructuredLogWithTwoAttributes(benchmark::State &state) +{ + auto lp = Provider::GetLoggerProvider(); + auto logger = lp->GetLogger("StructuredLog"); + + for (auto _ : state) + { + state.PauseTiming(); + + MultiThreadRunner(state, [&logger]() { + for (int64_t i = 0; i < kMaxIterations; i++) + { + logger->Trace( + "This is a simple structured log message from {process_id}:{thread_id}", + opentelemetry::common::MakeAttributes({{"process_id", 12347}, {"thread_id", 12348}})); + } + }); + + state.ResumeTiming(); + } +} +BENCHMARK(BM_StructuredLogWithTwoAttributes); + +static void BM_StructuredLogWithEventIdAndTwoAttributes(benchmark::State &state) +{ + auto lp = Provider::GetLoggerProvider(); + auto logger = lp->GetLogger("StructuredLogWithEventId"); + + for (auto _ : state) + { + state.PauseTiming(); + + MultiThreadRunner(state, [&logger]() { + for (int64_t i = 0; i < kMaxIterations; i++) + { + logger->Trace( + 0x12345678, "This is a simple structured log message from {process_id}:{thread_id}", + opentelemetry::common::MakeAttributes({{"process_id", 12347}, {"thread_id", 12348}})); + } + }); + + state.ResumeTiming(); + } +} +BENCHMARK(BM_StructuredLogWithEventIdAndTwoAttributes); + +static void BM_StructuredLogWithEventIdStructAndTwoAttributes(benchmark::State &state) +{ + auto lp = Provider::GetLoggerProvider(); + auto logger = lp->GetLogger("StructuredLogWithEventId"); + + const EventId function_name_event_id{0x12345678, "Company.Component.SubComponent.FunctionName"}; + + for (auto _ : state) + { + state.PauseTiming(); + + MultiThreadRunner(state, [&logger, &function_name_event_id]() { + for (int64_t i = 0; i < kMaxIterations; i++) + { + logger->Trace( + function_name_event_id, + "Simulate function enter trace message from {process_id}:{thread_id}", + opentelemetry::common::MakeAttributes({{"process_id", 12347}, {"thread_id", 12348}})); + } + }); + + state.ResumeTiming(); + } +} +BENCHMARK(BM_StructuredLogWithEventIdStructAndTwoAttributes); + +static void BM_EnabledOnSeverityReturnFalse(benchmark::State &state) +{ + auto lp = Provider::GetLoggerProvider(); + auto logger = lp->GetLogger("UnstructuredLogWithEnabledReturnFalse"); + + for (auto _ : state) + { + state.PauseTiming(); + + MultiThreadRunner(state, [&logger]() { + for (int64_t i = 0; i < kMaxIterations; i++) + { + if (logger->Enabled(Severity::kTrace)) + { + logger->Trace("This log line would not be called"); + } + } + }); + + state.ResumeTiming(); + } +} +BENCHMARK(BM_EnabledOnSeverityReturnFalse); + +static void BM_EnabledOnSeverityAndEventIdReturnFalse(benchmark::State &state) +{ + auto lp = Provider::GetLoggerProvider(); + auto logger = lp->GetLogger("UnstructuredLogWithEnabledReturnFalse"); + + for (auto _ : state) + { + state.PauseTiming(); + + MultiThreadRunner(state, [&logger]() { + for (int64_t i = 0; i < kMaxIterations; i++) + { + if (logger->Enabled(Severity::kTrace, 0x12345678)) + { + logger->Trace("This log line would not be called"); + } + } + }); + + state.ResumeTiming(); + } +} +BENCHMARK(BM_EnabledOnSeverityAndEventIdReturnFalse); + +} // namespace + +int main(int argc, char **argv) +{ + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); +} + +#endif diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/logger_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/logger_test.cc new file mode 100644 index 000000000..789ffd125 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/logger_test.cc @@ -0,0 +1,224 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include +# include +# include + +# include "opentelemetry/common/timestamp.h" +# include "opentelemetry/logs/logger.h" +# include "opentelemetry/logs/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" + +using opentelemetry::logs::EventId; +using opentelemetry::logs::Logger; +using opentelemetry::logs::LoggerProvider; +using opentelemetry::logs::Provider; +using opentelemetry::logs::Severity; +using opentelemetry::nostd::shared_ptr; +using opentelemetry::nostd::span; +using opentelemetry::nostd::string_view; +namespace common = opentelemetry::common; +namespace nostd = opentelemetry::nostd; +namespace trace = opentelemetry::trace; + +// Check that the default logger is a noop logger instance +TEST(Logger, GetLoggerDefault) +{ + auto lp = Provider::GetLoggerProvider(); + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + auto logger = lp->GetLogger("TestLogger", "opentelelemtry_library", "", schema_url); + auto name = logger->GetName(); + EXPECT_NE(nullptr, logger); + EXPECT_EQ(name, "noop logger"); +} + +// Test the two additional overloads for GetLogger() +TEST(Logger, GetNoopLoggerNameWithArgs) +{ + auto lp = Provider::GetLoggerProvider(); + + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + lp->GetLogger("NoopLoggerWithArgs", "opentelelemtry_library", "", schema_url); + + lp->GetLogger("NoopLoggerWithOptions", "opentelelemtry_library", "", schema_url); +} + +// Test the EmitLogRecord() overloads +TEST(Logger, LogMethodOverloads) +{ + auto lp = Provider::GetLoggerProvider(); + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + auto logger = lp->GetLogger("TestLogger", "opentelelemtry_library", "", schema_url); + + EventId trace_event_id{0x1, "TraceEventId"}; + EventId debug_event_id{0x2, "DebugEventId"}; + EventId info_event_id{0x3, "InfoEventId"}; + EventId warn_event_id{0x4, "WarnEventId"}; + EventId error_event_id{0x5, "ErrorEventId"}; + EventId fatal_event_id{0x6, "FatalEventId"}; + + // Create a map to test the logs with + std::map m = {{"key1", "value1"}}; + + // EmitLogRecord overloads + logger->EmitLogRecord(Severity::kTrace, "Test log message"); + logger->EmitLogRecord(Severity::kInfo, "Test log message"); + logger->EmitLogRecord(Severity::kDebug, m); + logger->EmitLogRecord(Severity::kWarn, "Logging a map", m); + logger->EmitLogRecord(Severity::kError, + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->EmitLogRecord(Severity::kFatal, "Logging an initializer list", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->EmitLogRecord(Severity::kDebug, opentelemetry::common::MakeAttributes(m)); + logger->EmitLogRecord(Severity::kDebug, + common::KeyValueIterableView>(m)); + std::pair array[] = {{"key1", "value1"}}; + logger->EmitLogRecord(Severity::kDebug, opentelemetry::common::MakeAttributes(array)); + std::vector> vec = {{"key1", "value1"}}; + logger->EmitLogRecord(Severity::kDebug, opentelemetry::common::MakeAttributes(vec)); + + // Severity methods + logger->Trace("Test log message"); + logger->Trace("Test log message", m); + logger->Trace("Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Trace(m); + logger->Trace(opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Trace(trace_event_id, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Trace(trace_event_id.id_, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + + logger->Debug("Test log message"); + logger->Debug("Test log message", m); + logger->Debug("Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Debug(m); + logger->Debug(opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Debug(debug_event_id, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Debug(debug_event_id.id_, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + + logger->Info("Test log message"); + logger->Info("Test log message", m); + logger->Info("Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Info(m); + logger->Info(opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Info(info_event_id, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Info(info_event_id.id_, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + + logger->Warn("Test log message"); + logger->Warn("Test log message", m); + logger->Warn("Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Warn(m); + logger->Warn(opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Warn(warn_event_id, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Warn(warn_event_id.id_, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + + logger->Error("Test log message"); + logger->Error("Test log message", m); + logger->Error("Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Error(m); + logger->Error(opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Error(error_event_id, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Error(error_event_id.id_, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + + logger->Fatal("Test log message"); + logger->Fatal("Test log message", m); + logger->Fatal("Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Fatal(m); + logger->Fatal(opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Fatal(fatal_event_id, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + logger->Fatal(fatal_event_id.id_, "Test log message", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); +} + +TEST(Logger, EventLogMethodOverloads) +{ + auto lp = Provider::GetLoggerProvider(); + const std::string schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + auto logger = lp->GetLogger("TestLogger", "opentelelemtry_library", "", schema_url); + + auto elp = Provider::GetEventLoggerProvider(); + auto event_logger = elp->CreateEventLogger(logger, "otel-cpp.test"); + + std::map m = {{"key1", "value1"}}; + + event_logger->EmitEvent("event name", Severity::kTrace, "Test log message"); + event_logger->EmitEvent("event name", Severity::kInfo, "Test log message"); + event_logger->EmitEvent("event name", Severity::kDebug, m); + event_logger->EmitEvent("event name", Severity::kWarn, "Logging a map", m); + event_logger->EmitEvent( + "event name", Severity::kError, + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + event_logger->EmitEvent( + "event name", Severity::kFatal, "Logging an initializer list", + opentelemetry::common::MakeAttributes({{"key1", "value 1"}, {"key2", 2}})); + event_logger->EmitEvent("event name", Severity::kDebug, opentelemetry::common::MakeAttributes(m)); + event_logger->EmitEvent("event name", Severity::kDebug, + common::KeyValueIterableView>(m)); + std::pair array[] = {{"key1", "value1"}}; + event_logger->EmitEvent("event name", Severity::kDebug, + opentelemetry::common::MakeAttributes(array)); + std::vector> vec = {{"key1", "value1"}}; + event_logger->EmitEvent("event name", Severity::kDebug, + opentelemetry::common::MakeAttributes(vec)); +} + +// Define a basic Logger class +class TestLogger : public Logger +{ + const nostd::string_view GetName() noexcept override { return "test logger"; } + + nostd::unique_ptr CreateLogRecord() noexcept override + { + return nullptr; + } + + using Logger::EmitLogRecord; + + void EmitLogRecord(nostd::unique_ptr &&) noexcept override {} +}; + +// Define a basic LoggerProvider class that returns an instance of the logger class defined above +class TestProvider : public LoggerProvider +{ + nostd::shared_ptr GetLogger(nostd::string_view /* logger_name */, + nostd::string_view /* library_name */, + nostd::string_view /* library_version */, + nostd::string_view /* schema_url */, + const common::KeyValueIterable & /* attributes */) override + { + return nostd::shared_ptr(new TestLogger()); + } +}; + +TEST(Logger, PushLoggerImplementation) +{ + // Push the new loggerprovider class into the global singleton + auto test_provider = shared_ptr(new TestProvider()); + Provider::SetLoggerProvider(test_provider); + + auto lp = Provider::GetLoggerProvider(); + + // Check that the implementation was pushed by calling TestLogger's GetName() + nostd::string_view schema_url{"https://opentelemetry.io/schemas/1.11.0"}; + auto logger = lp->GetLogger("TestLogger", "opentelelemtry_library", "", schema_url); + ASSERT_EQ("test logger", logger->GetName()); +} +#endif diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/provider_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/provider_test.cc new file mode 100644 index 000000000..27af9b0c4 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/logs/provider_test.cc @@ -0,0 +1,112 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifdef ENABLE_LOGS_PREVIEW + +# include +# include + +# include "opentelemetry/logs/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" + +using opentelemetry::logs::EventLogger; +using opentelemetry::logs::EventLoggerProvider; +using opentelemetry::logs::Logger; +using opentelemetry::logs::LoggerProvider; +using opentelemetry::logs::Provider; +using opentelemetry::nostd::shared_ptr; +namespace nostd = opentelemetry::nostd; + +class TestProvider : public LoggerProvider +{ + nostd::shared_ptr GetLogger( + nostd::string_view /* logger_name */, + nostd::string_view /* library_name */, + nostd::string_view /* library_version */, + nostd::string_view /* schema_url */, + const opentelemetry::common::KeyValueIterable & /* attributes */) override + { + return shared_ptr(nullptr); + } +}; + +TEST(Provider, GetLoggerProviderDefault) +{ + auto tf = Provider::GetLoggerProvider(); + EXPECT_NE(nullptr, tf); +} + +TEST(Provider, SetLoggerProvider) +{ + auto tf = shared_ptr(new TestProvider()); + Provider::SetLoggerProvider(tf); + ASSERT_EQ(tf, Provider::GetLoggerProvider()); +} + +TEST(Provider, MultipleLoggerProviders) +{ + auto tf = shared_ptr(new TestProvider()); + Provider::SetLoggerProvider(tf); + auto tf2 = shared_ptr(new TestProvider()); + Provider::SetLoggerProvider(tf2); + + ASSERT_NE(Provider::GetLoggerProvider(), tf); +} + +TEST(Provider, GetLogger) +{ + auto tf = shared_ptr(new TestProvider()); + // tests GetLogger(name, version, schema) + const std::string schema_url{"https://opentelemetry.io/schemas/1.2.0"}; + auto logger = tf->GetLogger("logger1", "opentelelemtry_library", "", schema_url); + EXPECT_EQ(nullptr, logger); + + // tests GetLogger(name, arguments) + + auto logger2 = tf->GetLogger("logger2", "opentelelemtry_library", "", schema_url); + EXPECT_EQ(nullptr, logger2); +} + +class TestEventLoggerProvider : public EventLoggerProvider +{ +public: + nostd::shared_ptr CreateEventLogger( + nostd::shared_ptr /*delegate_logger*/, + nostd::string_view /*event_domain*/) noexcept override + { + return nostd::shared_ptr(nullptr); + } +}; + +TEST(Provider, GetEventLoggerProviderDefault) +{ + auto tf = Provider::GetEventLoggerProvider(); + EXPECT_NE(nullptr, tf); +} + +TEST(Provider, SetEventLoggerProvider) +{ + auto tf = nostd::shared_ptr(new TestEventLoggerProvider()); + Provider::SetEventLoggerProvider(tf); + ASSERT_EQ(tf, Provider::GetEventLoggerProvider()); +} + +TEST(Provider, MultipleEventLoggerProviders) +{ + auto tf = nostd::shared_ptr(new TestEventLoggerProvider()); + Provider::SetEventLoggerProvider(tf); + auto tf2 = nostd::shared_ptr(new TestEventLoggerProvider()); + Provider::SetEventLoggerProvider(tf2); + + ASSERT_NE(Provider::GetEventLoggerProvider(), tf); +} + +TEST(Provider, CreateEventLogger) +{ + auto tf = nostd::shared_ptr(new TestEventLoggerProvider()); + auto logger = tf->CreateEventLogger(nostd::shared_ptr(nullptr), "domain"); + + EXPECT_EQ(nullptr, logger); +} + +#endif diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/BUILD new file mode 100644 index 000000000..86e20033b --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/BUILD @@ -0,0 +1,34 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "noop_sync_instrument_test", + srcs = [ + "noop_sync_instrument_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "meter_provider_test", + srcs = [ + "meter_provider_test.cc", + ], + tags = [ + "metrics", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/CMakeLists.txt new file mode 100644 index 000000000..c63af9a7a --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +foreach(testname meter_provider_test noop_sync_instrument_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX metrics_new. + TEST_LIST ${testname}) +endforeach() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/meter_provider_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/meter_provider_test.cc new file mode 100644 index 000000000..878c5e9a3 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/meter_provider_test.cc @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include "opentelemetry/metrics/noop.h" +#include "opentelemetry/metrics/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" + +using opentelemetry::metrics::Meter; +using opentelemetry::metrics::MeterProvider; +using opentelemetry::metrics::NoopMeterProvider; +using opentelemetry::metrics::Provider; + +TEST(Provider, GetMeterProviderDefault) +{ + auto tf = Provider::GetMeterProvider(); + EXPECT_NE(nullptr, tf); +} + +TEST(Provider, SetMeterProvider) +{ + auto tf = opentelemetry::nostd::shared_ptr(new NoopMeterProvider()); + Provider::SetMeterProvider(tf); + ASSERT_EQ(tf, Provider::GetMeterProvider()); +} + +TEST(Provider, MultipleMeterProviders) +{ + auto tf = opentelemetry::nostd::shared_ptr(new NoopMeterProvider()); + Provider::SetMeterProvider(tf); + auto tf2 = opentelemetry::nostd::shared_ptr(new NoopMeterProvider()); + Provider::SetMeterProvider(tf2); + + ASSERT_NE(Provider::GetMeterProvider(), tf); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/noop_sync_instrument_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/noop_sync_instrument_test.cc new file mode 100644 index 000000000..6411e0e82 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/metrics/noop_sync_instrument_test.cc @@ -0,0 +1,46 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include "opentelemetry/metrics/noop.h" + +TEST(Counter, Add) +{ + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopCounter("test", "none", "unitless")}; + + std::map labels = {{"k1", "v1"}}; + counter->Add(10, labels); + counter->Add(10, labels, opentelemetry::context::Context{}); + counter->Add(2); + counter->Add(2, opentelemetry::context::Context{}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); +} + +TEST(histogram, Record) +{ + std::shared_ptr> histogram{ + new opentelemetry::metrics::NoopHistogram("test", "none", "unitless")}; + + std::map labels = {{"k1", "v1"}}; + histogram->Record(10, labels, opentelemetry::context::Context{}); + histogram->Record(2, opentelemetry::context::Context{}); + + histogram->Record(10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); +} + +TEST(UpDownCountr, Record) +{ + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopUpDownCounter("test", "none", "unitless")}; + + std::map labels = {{"k1", "v1"}}; + counter->Add(10, labels); + counter->Add(10, labels, opentelemetry::context::Context{}); + counter->Add(2); + counter->Add(2, opentelemetry::context::Context{}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/BUILD new file mode 100644 index 000000000..4f2b1d31f --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/BUILD @@ -0,0 +1,107 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cc_test( + name = "function_ref_test", + srcs = [ + "function_ref_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "string_view_test", + srcs = [ + "string_view_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "variant_test", + srcs = [ + "variant_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "unique_ptr_test", + srcs = [ + "unique_ptr_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "utility_test", + srcs = [ + "utility_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "span_test", + srcs = [ + "span_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "shared_ptr_test", + srcs = [ + "shared_ptr_test.cc", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/CMakeLists.txt new file mode 100644 index 000000000..ee774261e --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include(GoogleTest) + +foreach( + testname + function_ref_test + string_view_test + unique_ptr_test + utility_test + span_test + shared_ptr_test + variant_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX nostd. + TEST_LIST ${testname}) +endforeach() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/function_ref_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/function_ref_test.cc new file mode 100644 index 000000000..1153360d2 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/function_ref_test.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/function_ref.h" + +#include +using namespace opentelemetry::nostd; + +int Call(function_ref f) +{ + return f(); +} + +int Return3() +{ + return 3; +} + +TEST(FunctionRefTest, Call) +{ + int x = 9; + + auto f = [&] { return x; }; + EXPECT_EQ(Call(f), 9); + + EXPECT_EQ(Call(Return3), 3); +} + +TEST(FunctionRefTest, BoolConversion) +{ + auto f = [] { return 0; }; + function_ref fref1{nullptr}; + function_ref fref2{f}; + EXPECT_TRUE(!static_cast(fref1)); + EXPECT_TRUE(static_cast(fref2)); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/shared_ptr_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/shared_ptr_test.cc new file mode 100644 index 000000000..6f3d43a77 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/shared_ptr_test.cc @@ -0,0 +1,189 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" + +#include + +#include + +using opentelemetry::nostd::shared_ptr; + +class A +{ +public: + explicit A(bool &destructed) noexcept : destructed_{destructed} { destructed_ = false; } + + ~A() { destructed_ = true; } + +private: + bool &destructed_; +}; + +class B +{ +public: + int f() const { return 123; } +}; + +class C +{ +public: + virtual ~C() {} +}; + +class D : public C +{ +public: + virtual ~D() {} +}; + +TEST(SharedPtrTest, DefaultConstruction) +{ + shared_ptr ptr1; + EXPECT_EQ(ptr1.get(), nullptr); + + shared_ptr ptr2{nullptr}; + EXPECT_EQ(ptr2.get(), nullptr); +} + +TEST(SharedPtrTest, ExplicitConstruction) +{ + auto c = new C(); + shared_ptr ptr1{c}; + EXPECT_EQ(ptr1.get(), c); + + auto d = new D(); + shared_ptr ptr2{d}; + EXPECT_EQ(ptr2.get(), d); +} + +TEST(SharedPtrTest, MoveConstruction) +{ + auto value = new int{123}; + shared_ptr ptr1{value}; + shared_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); +} + +TEST(SharedPtrTest, MoveConstructionFromDifferentType) +{ + auto value = new int{123}; + shared_ptr ptr1{value}; + shared_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); +} + +TEST(SharedPtrTest, MoveConstructionFromStdSharedPtr) +{ + auto value = new int{123}; + std::shared_ptr ptr1{value}; + shared_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); +} + +TEST(SharedPtrTest, Destruction) +{ + bool was_destructed; + shared_ptr{new A{was_destructed}}; + EXPECT_TRUE(was_destructed); +} + +TEST(SharedPtrTest, Assignment) +{ + auto value = new int{123}; + shared_ptr ptr1; + + ptr1 = shared_ptr(value); + EXPECT_EQ(ptr1.get(), value); + + ptr1 = nullptr; + EXPECT_EQ(ptr1.get(), nullptr); + + auto value2 = new int{234}; + const shared_ptr ptr2 = shared_ptr(value2); + ptr1 = ptr2; + EXPECT_EQ(ptr1.get(), value2); + + auto value3 = new int{345}; + std::shared_ptr ptr3(value3); + ptr1 = ptr3; + EXPECT_EQ(ptr1.get(), value3); +} + +TEST(SharedPtrTest, BoolConversionOpertor) +{ + auto value = new int{123}; + shared_ptr ptr1{value}; + + EXPECT_TRUE(ptr1); + EXPECT_FALSE(shared_ptr{}); +} + +TEST(SharedPtrTest, PointerOperators) +{ + auto value = new int{123}; + shared_ptr ptr1{value}; + + EXPECT_EQ(&*ptr1, value); + EXPECT_EQ( + shared_ptr { new B }->f(), 123); +} + +TEST(SharedPtrTest, Swap) +{ + auto value1 = new int{123}; + shared_ptr ptr1{value1}; + + auto value2 = new int{456}; + shared_ptr ptr2{value2}; + ptr1.swap(ptr2); + + EXPECT_EQ(ptr1.get(), value2); + EXPECT_EQ(ptr2.get(), value1); +} + +TEST(SharedPtrTest, Comparison) +{ + shared_ptr ptr1{new int{123}}; + shared_ptr ptr2{new int{456}}; + shared_ptr ptr3{}; + + EXPECT_EQ(ptr1, ptr1); + EXPECT_NE(ptr1, ptr2); + + EXPECT_NE(ptr1, nullptr); + EXPECT_NE(nullptr, ptr1); + + EXPECT_EQ(ptr3, nullptr); + EXPECT_EQ(nullptr, ptr3); +} + +static void SharedPtrTest_Sort(size_t size = 10) +{ + std::vector> nums; + + for (int i = static_cast(size); i > 0; i--) + { + nums.push_back(shared_ptr(new int(i))); + } + + auto nums2 = nums; + + std::sort(nums.begin(), nums.end(), + [](shared_ptr a, shared_ptr b) { return *a < *b; }); + + EXPECT_NE(nums, nums2); + + std::reverse(nums2.begin(), nums2.end()); + + EXPECT_EQ(nums, nums2); +} + +TEST(SharedPtrTest, Sort) +{ + SharedPtrTest_Sort(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/span_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/span_test.cc new file mode 100644 index 000000000..98e825142 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/span_test.cc @@ -0,0 +1,191 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/span.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using opentelemetry::nostd::span; + +TEST(SpanTest, DefaultConstruction) +{ + span s1; + EXPECT_EQ(s1.data(), nullptr); + EXPECT_EQ(s1.size(), 0); + EXPECT_TRUE(s1.empty()); + + span s2; + EXPECT_EQ(s2.data(), nullptr); + EXPECT_EQ(s2.size(), 0); + EXPECT_TRUE(s2.empty()); + + EXPECT_FALSE((std::is_default_constructible>::value)); +} + +TEST(SpanTest, Assignment) +{ + std::array array1 = {1, 2, 3}; + std::array array2 = {1, 2, 3}; + span s1{array1.data(), array1.size()}; + span s2{array1.data(), array1.size()}; + + span s3; + s3 = s1; + EXPECT_EQ(s3.data(), array1.data()); + EXPECT_EQ(s3.size(), array1.size()); + + span s4{array2}; + s4 = s2; + EXPECT_EQ(s4.data(), array1.data()); + EXPECT_EQ(s4.size(), array1.size()); +} + +TEST(SpanTest, PointerCountConstruction) +{ + std::array array = {1, 2, 3}; + + span s1{array.data(), array.size()}; + EXPECT_EQ(s1.data(), array.data()); + EXPECT_EQ(s1.size(), array.size()); + + span s2{array.data(), array.size()}; + EXPECT_EQ(s2.data(), array.data()); + EXPECT_EQ(s2.size(), array.size()); + +#ifndef HAVE_CPP_STDLIB + /* This test is not supposed to fail with STL. Why is this invalid construct? */ + EXPECT_DEATH((span{array.data(), array.size()}), ".*"); +#endif +} + +TEST(SpanTest, RangeConstruction) +{ + int array[] = {1, 2, 3}; + + span s1{std::begin(array), std::end(array)}; + EXPECT_EQ(s1.data(), array); + EXPECT_EQ(s1.size(), 3); + + span s2{std::begin(array), std::end(array)}; + EXPECT_EQ(s2.data(), array); + EXPECT_EQ(s2.size(), 3); + +#ifndef HAVE_CPP_STDLIB + /* This test is not supposed to fail with STL. Why is this invalid construct? */ + EXPECT_DEATH((span{std::begin(array), std::end(array)}), ".*"); +#endif +} + +TEST(SpanTest, ArrayConstruction) +{ + int array1[] = {1, 2, 3}; + std::array array2 = {1, 2, 3}; + + span s1{array1}; + EXPECT_EQ(s1.data(), array1); + EXPECT_EQ(s1.size(), 3); + + span s2{array2}; + EXPECT_EQ(s2.data(), array2.data()); + EXPECT_EQ(s2.size(), array2.size()); + + span s3{array1}; + EXPECT_EQ(s3.data(), array1); + EXPECT_EQ(s3.size(), 3); + + span s4{array2}; + EXPECT_EQ(s4.data(), array2.data()); + EXPECT_EQ(s4.size(), array2.size()); + + EXPECT_FALSE((std::is_constructible, int(&)[3]>::value)); +} + +TEST(SpanTest, ContainerConstruction) +{ + std::vector v = {1, 2, 3}; + + span s1{v}; + EXPECT_EQ(s1.data(), v.data()); + EXPECT_EQ(s1.size(), v.size()); + + span s2{v.data(), 3}; + + EXPECT_EQ(s2.data(), v.data()); + EXPECT_EQ(s2.size(), v.size()); + +#ifndef HAVE_CPP_STDLIB + /* This test is not supposed to fail with STL. Why is this invalid construct? */ + EXPECT_DEATH((span{v.data(), 3}), ".*"); +#endif + + EXPECT_FALSE((std::is_constructible, std::vector>::value)); + EXPECT_FALSE((std::is_constructible, std::list>::value)); +} + +TEST(SpanTest, OtherSpanConstruction) +{ + std::array array = {1, 2, 3}; + span s1{array.data(), array.size()}; + span s2{array.data(), array.size()}; + + span s3{s1}; + EXPECT_EQ(s3.data(), array.data()); + EXPECT_EQ(s3.size(), array.size()); + + span s4{s2}; + EXPECT_EQ(s4.data(), array.data()); + EXPECT_EQ(s4.size(), array.size()); + + span s5{s1}; + EXPECT_EQ(s5.data(), array.data()); + EXPECT_EQ(s5.size(), array.size()); + + EXPECT_FALSE((std::is_constructible, span>::value)); + EXPECT_FALSE((std::is_constructible, span>::value)); + + span s6{s2}; + EXPECT_EQ(s6.data(), array.data()); + EXPECT_EQ(s6.size(), array.size()); + + span s7{s2}; + EXPECT_EQ(s7.data(), array.data()); + EXPECT_EQ(s7.size(), array.size()); + + EXPECT_FALSE((std::is_constructible, span>::value)); + EXPECT_FALSE((std::is_constructible, span>::value)); +} + +TEST(SpanTest, BracketOperator) +{ + std::array array = {1, 2}; + + span s1{array.data(), array.size()}; + EXPECT_EQ(s1[0], 1); + EXPECT_EQ(s1[1], 2); + + span s2{array.data(), array.size()}; + EXPECT_EQ(s2[0], 1); + EXPECT_EQ(s2[1], 2); +} + +TEST(SpanTest, Iteration) +{ + std::array array = {1, 2, 3}; + + span s1{array.data(), array.size()}; + EXPECT_EQ(std::distance(s1.begin(), s1.end()), (ptrdiff_t)array.size()); + EXPECT_TRUE(std::equal(s1.begin(), s1.end(), array.begin())); + + span s2{array.data(), array.size()}; + EXPECT_EQ(std::distance(s2.begin(), s2.end()), (ptrdiff_t)array.size()); + EXPECT_TRUE(std::equal(s2.begin(), s2.end(), array.begin())); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/string_view_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/string_view_test.cc new file mode 100644 index 000000000..fc580debc --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/string_view_test.cc @@ -0,0 +1,125 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/string_view.h" + +#include +#include +#include + +using opentelemetry::nostd::string_view; + +TEST(StringViewTest, DefaultConstruction) +{ + string_view ref; + EXPECT_EQ(ref.data(), nullptr); + EXPECT_EQ(ref.length(), 0); +} + +TEST(StringViewTest, CStringInitialization) +{ + const char *val = "hello world"; + + string_view ref(val); + + EXPECT_EQ(ref.data(), val); + EXPECT_EQ(ref.length(), std::strlen(val)); +} + +TEST(StringViewTest, StdStringInitialization) +{ + const std::string val = "hello world"; + + string_view ref(val); + + EXPECT_EQ(ref.data(), val.data()); + EXPECT_EQ(ref.length(), val.size()); +} + +TEST(StringViewTest, Copy) +{ + const std::string val = "hello world"; + + string_view ref(val); + string_view cpy(ref); + + EXPECT_EQ(cpy.data(), val); + EXPECT_EQ(cpy.length(), val.length()); + EXPECT_EQ(cpy, val); +} + +TEST(StringViewTest, Accessor) +{ + string_view s = "abc123"; + EXPECT_EQ(s.data(), &s[0]); + EXPECT_EQ(s.data() + 1, &s[1]); +} + +TEST(StringViewTest, ExplicitStdStringConversion) +{ + std::string s = static_cast(string_view{"abc"}); + EXPECT_EQ(s, "abc"); +} + +TEST(StringViewTest, SubstrPortion) +{ + string_view s = "abc123"; + EXPECT_EQ("123", s.substr(3)); + EXPECT_EQ("12", s.substr(3, 2)); +} + +TEST(StringViewTest, SubstrOutOfRange) +{ + string_view s = "abc123"; +#if __EXCEPTIONS || defined(HAVE_CPP_STDLIB) + EXPECT_THROW(s.substr(10), std::out_of_range); +#else + EXPECT_DEATH({ s.substr(10); }, ""); +#endif +} + +TEST(StringViewTest, FindSingleCharacter) +{ + string_view s = "abc"; + + // starting from 0-th position (default) + EXPECT_EQ(s.find('a'), 0); + EXPECT_EQ(s.find('b'), 1); + EXPECT_EQ(s.find('c'), 2); + EXPECT_EQ(s.find('d'), -1); // FIXME: string_view:npos - problem with linker + + // starting from given index + EXPECT_EQ(s.find('a', 1), -1); + EXPECT_EQ(s.find('b', 1), 1); + + // out of index + EXPECT_EQ(s.find('a', 10), -1); +} + +TEST(StringViewTest, Compare) +{ + string_view s1 = "aaa"; + string_view s2 = "bbb"; + string_view s3 = "aaa"; + + // Equals + EXPECT_EQ(s1, s3); + EXPECT_EQ(s1, s1); + + // Less then + EXPECT_LT(s1, s2); + + // Greater then + EXPECT_GT(s2, s1); +} + +TEST(StringViewTest, MapKeyOrdering) +{ + std::map m = {{"bbb", 2}, {"aaa", 1}, {"ccc", 3}}; + size_t i = 1; + for (const auto &kv : m) + { + EXPECT_EQ(kv.second, i); + i++; + } +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/unique_ptr_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/unique_ptr_test.cc new file mode 100644 index 000000000..aa49d387b --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/unique_ptr_test.cc @@ -0,0 +1,169 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/unique_ptr.h" + +#include + +using opentelemetry::nostd::unique_ptr; + +class A +{ +public: + explicit A(bool &destructed) noexcept : destructed_{destructed} { destructed_ = false; } + + ~A() { destructed_ = true; } + +private: + bool &destructed_; +}; + +class B +{ +public: + int f() const { return 123; } +}; + +TEST(UniquePtrTest, DefaultConstruction) +{ + unique_ptr ptr1; + EXPECT_EQ(ptr1.get(), nullptr); + + unique_ptr ptr2{nullptr}; + EXPECT_EQ(ptr2.get(), nullptr); +} + +TEST(UniquePtrTest, ExplicitConstruction) +{ + auto value = new int{123}; + unique_ptr ptr1{value}; + EXPECT_EQ(ptr1.get(), value); + + auto array = new int[5]; + unique_ptr ptr2{array}; + EXPECT_EQ(ptr2.get(), array); +} + +TEST(UniquePtrTest, MoveConstruction) +{ + auto value = new int{123}; + unique_ptr ptr1{value}; + unique_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); +} + +TEST(UniquePtrTest, MoveConstructionFromDifferentType) +{ + auto value = new int{123}; + unique_ptr ptr1{value}; + unique_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); +} + +TEST(UniquePtrTest, MoveConstructionFromStdUniquePtr) +{ + auto value = new int{123}; + std::unique_ptr ptr1{value}; + unique_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); +} + +TEST(UniquePtrTest, Destruction) +{ + bool was_destructed; + unique_ptr{new A{was_destructed}}; + EXPECT_TRUE(was_destructed); +} + +TEST(UniquePtrTest, StdUniquePtrConversionOperator) +{ + auto value = new int{123}; + unique_ptr ptr1{value}; + std::unique_ptr ptr2{std::move(ptr1)}; + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); + + value = new int{456}; + ptr1 = unique_ptr{value}; + ptr2 = std::move(ptr1); + EXPECT_EQ(ptr1.get(), nullptr); + EXPECT_EQ(ptr2.get(), value); + + ptr2 = nullptr; + EXPECT_EQ(ptr2.get(), nullptr); + + EXPECT_TRUE((std::is_assignable, unique_ptr &&>::value)); + EXPECT_FALSE((std::is_assignable, unique_ptr &>::value)); +} + +TEST(UniquePtrTest, BoolConversionOpertor) +{ + auto value = new int{123}; + unique_ptr ptr1{value}; + + EXPECT_TRUE(ptr1); + EXPECT_FALSE(unique_ptr{}); +} + +TEST(UniquePtrTest, PointerOperators) +{ + auto value = new int{123}; + unique_ptr ptr1{value}; + + EXPECT_EQ(&*ptr1, value); + EXPECT_EQ( + unique_ptr { new B }->f(), 123); +} + +TEST(UniquePtrTest, Reset) +{ + bool was_destructed1; + unique_ptr ptr{new A{was_destructed1}}; + bool was_destructed2 = true; + ptr.reset(new A{was_destructed2}); + EXPECT_TRUE(was_destructed1); + EXPECT_FALSE(was_destructed2); + ptr.reset(); + EXPECT_TRUE(was_destructed2); +} + +TEST(UniquePtrTest, Release) +{ + auto value = new int{123}; + unique_ptr ptr{value}; + EXPECT_EQ(ptr.release(), value); + EXPECT_EQ(ptr.get(), nullptr); + delete value; +} + +TEST(UniquePtrTest, Swap) +{ + auto value1 = new int{123}; + unique_ptr ptr1{value1}; + + auto value2 = new int{456}; + unique_ptr ptr2{value2}; + ptr1.swap(ptr2); + + EXPECT_EQ(ptr1.get(), value2); + EXPECT_EQ(ptr2.get(), value1); +} + +TEST(UniquePtrTest, Comparison) +{ + unique_ptr ptr1{new int{123}}; + unique_ptr ptr2{new int{456}}; + unique_ptr ptr3{}; + + EXPECT_EQ(ptr1, ptr1); + EXPECT_NE(ptr1, ptr2); + + EXPECT_NE(ptr1, nullptr); + EXPECT_NE(nullptr, ptr1); + + EXPECT_EQ(ptr3, nullptr); + EXPECT_EQ(nullptr, ptr3); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/utility_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/utility_test.cc new file mode 100644 index 000000000..821b2a70a --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/utility_test.cc @@ -0,0 +1,56 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/utility.h" + +#include +#include +#include + +#include + +namespace nostd = opentelemetry::nostd; + +template +auto IsDataCallable(const T &t) -> decltype(nostd::data(t), std::true_type{}); + +std::false_type IsDataCallable(...); + +template +auto IsSizeCallable(const T &t) -> decltype(nostd::size(t), std::true_type{}); + +std::false_type IsSizeCallable(...); + +TEST(UtilityTest, Data) +{ + std::vector v = {1, 2, 3}; + int array[3] = {1, 2, 3}; + std::initializer_list list{1, 2, 3}; + int x = 0; + std::ignore = x; + + EXPECT_EQ(nostd::data(v), v.data()); + EXPECT_EQ(nostd::data(array), array); + EXPECT_EQ(nostd::data(list), list.begin()); + EXPECT_FALSE(decltype(IsDataCallable(x)){}); +} + +TEST(UtilityTest, Size) +{ + std::vector v = {1, 2, 3}; + int array[3] = {1, 2, 3}; + int x = 0; + std::ignore = x; + + EXPECT_EQ(nostd::size(v), v.size()); + EXPECT_EQ(nostd::size(array), 3); + + EXPECT_FALSE(decltype(IsSizeCallable(x)){}); +} + +TEST(UtilityTest, MakeIndexSequence) +{ + EXPECT_TRUE((std::is_same, nostd::index_sequence<>>::value)); + EXPECT_TRUE((std::is_same, nostd::index_sequence<0>>::value)); + EXPECT_TRUE((std::is_same, nostd::index_sequence<0, 1>>::value)); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/variant_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/variant_test.cc new file mode 100644 index 000000000..cea5c4ee7 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/nostd/variant_test.cc @@ -0,0 +1,119 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/variant.h" + +#include +#include + +#include + +namespace nostd = opentelemetry::nostd; + +class DestroyCounter +{ +public: + explicit DestroyCounter(int *count) : count_{count} {} + ~DestroyCounter() { ++*count_; } + +private: + int *count_; +}; + +TEST(VariantSizeTest, GetVariantSize) +{ + EXPECT_EQ(nostd::variant_size>::value, 0); + EXPECT_EQ(nostd::variant_size>::value, 1); + EXPECT_EQ((nostd::variant_size>::value), 2); +} + +#if 0 // Disable this test for now. It does not compile with Visual Studio 2015. +TEST(VariantAlternativeTest, GetVariantSize) +{ + EXPECT_TRUE((std::is_same>, int>::value)); + EXPECT_TRUE( + (std::is_same>, double>::value)); + EXPECT_TRUE((std::is_same>, + const double>::value)); +} +#endif + +TEST(VariantTest, Get) +{ + nostd::variant v, w; + v = 12; + EXPECT_EQ(nostd::get(v), 12); + EXPECT_EQ(nostd::get<0>(v), 12); + w = v; + EXPECT_EQ(nostd::get(w), 12); + EXPECT_EQ(*nostd::get_if(&v), 12); + EXPECT_EQ(nostd::get_if(&v), nullptr); +#if __EXCEPTIONS + EXPECT_THROW(nostd::get(w), nostd::bad_variant_access); +#else + EXPECT_DEATH({ nostd::get(w); }, ""); +#endif +} + +TEST(VariantTest, Comparison) +{ + nostd::variant v, w; + EXPECT_TRUE(v == w); + EXPECT_FALSE(v != w); + v = 3.0f; + EXPECT_TRUE(v != w); + EXPECT_FALSE(v == w); + v = 2; + w = 3; + EXPECT_TRUE(v != w); + EXPECT_FALSE(v == w); + EXPECT_TRUE(v < w); + EXPECT_FALSE(v > w); +} + +TEST(VariantTest, Visit) +{ + nostd::variant v; + struct + { + int operator()(int) { return 0; } + int operator()(float) { return 1; } + } a; + EXPECT_EQ(nostd::visit(a, v), 0); + v = 2.0f; + EXPECT_EQ(nostd::visit(a, v), 1); +} + +TEST(VariantTest, Destructor) +{ + nostd::variant v; + int destroy_count = 0; + v = DestroyCounter{&destroy_count}; + destroy_count = 0; + v = 1; + EXPECT_EQ(destroy_count, 1); + { + nostd::variant w; + w = DestroyCounter{&destroy_count}; + destroy_count = 0; + } + EXPECT_EQ(destroy_count, 1); +} + +TEST(VariantTest, Conversion) +{ + nostd::variant x("abc"); + x = "def"; + EXPECT_EQ(nostd::get(x), "def"); + + nostd::variant y("abc"); + EXPECT_TRUE(nostd::holds_alternative(y)); + y = std::string{"xyz"}; + EXPECT_TRUE(nostd::holds_alternative(y)); +} + +TEST(VariantTest, Construction) +{ + nostd::variant v{"abc"}; + EXPECT_EQ(v.index(), 1); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/BUILD new file mode 100644 index 000000000..f20143ff7 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/BUILD @@ -0,0 +1,20 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +cc_test( + name = "dynamic_load_test", + srcs = [ + "dynamic_load_test.cc", + ], + linkopts = [ + "-ldl", + ], + tags = [ + "api", + "test", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/CMakeLists.txt new file mode 100644 index 000000000..8930928f1 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include(GoogleTest) + +add_executable(dynamic_load_test dynamic_load_test.cc) +target_link_libraries(dynamic_load_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +target_link_libraries(dynamic_load_test ${CMAKE_DL_LIBS}) +gtest_add_tests( + TARGET dynamic_load_test + TEST_PREFIX plugin. + TEST_LIST dynamic_load_test) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/dynamic_load_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/dynamic_load_test.cc new file mode 100644 index 000000000..8e8b14800 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/plugin/dynamic_load_test.cc @@ -0,0 +1,15 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/plugin/dynamic_load.h" +#include "opentelemetry/plugin/factory.h" + +#include + +TEST(LoadFactoryTest, FailureTest) +{ + std::string error_message; + auto factory = opentelemetry::plugin::LoadFactory("no-such-plugin", error_message); + EXPECT_EQ(factory, nullptr); + EXPECT_FALSE(error_message.empty()); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/BUILD new file mode 100644 index 000000000..cdd1ed7cf --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/BUILD @@ -0,0 +1,189 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +DEFAULT_WIN_COPTS = [ +] + +# gcc and clang, assumed to be used on this platform +DEFAULT_NOWIN_COPTS = [ + "-fvisibility=default", +] + +HIDDEN_WIN_COPTS = [ +] + +# gcc and clang, assumed to be used on this platform +HIDDEN_NOWIN_COPTS = [ + "-fvisibility=hidden", +] + +cc_library( + name = "component_a", + srcs = [ + "component_a.cc", + ], + hdrs = [ + "component_a.h", + ], + linkstatic = True, + deps = [ + "//api", + ], +) + +cc_library( + name = "component_b", + srcs = [ + "component_b.cc", + ], + hdrs = [ + "component_b.h", + ], + linkstatic = True, + deps = [ + "//api", + ], +) + +cc_library( + name = "component_c", + srcs = [ + "component_c.cc", + ], + hdrs = [ + "component_c.h", + ], + copts = select({ + "//bazel:windows": DEFAULT_WIN_COPTS, + "//conditions:default": DEFAULT_NOWIN_COPTS, + }), + linkstatic = False, + deps = [ + "//api", + ], +) + +cc_library( + name = "component_d", + srcs = [ + "component_d.cc", + ], + hdrs = [ + "component_d.h", + ], + copts = select({ + "//bazel:windows": HIDDEN_WIN_COPTS, + "//conditions:default": HIDDEN_NOWIN_COPTS, + }), + linkstatic = False, + deps = [ + "//api", + ], +) + +cc_library( + name = "component_e", + srcs = [ + "component_e.cc", + ], + hdrs = [ + "component_e.h", + ], + copts = select({ + "//bazel:windows": DEFAULT_WIN_COPTS, + "//conditions:default": DEFAULT_NOWIN_COPTS, + }), + linkstatic = False, + deps = [ + "//api", + ], +) + +cc_library( + name = "component_f", + srcs = [ + "component_f.cc", + ], + hdrs = [ + "component_f.h", + ], + copts = select({ + "//bazel:windows": HIDDEN_WIN_COPTS, + "//conditions:default": HIDDEN_NOWIN_COPTS, + }), + linkstatic = False, + deps = [ + "//api", + ], +) + +# no cc_shared_library in bazel 4.2 +cc_binary( + name = "component_g", + srcs = [ + "component_g.cc", + ], + copts = select({ + "//bazel:windows": DEFAULT_WIN_COPTS, + "//conditions:default": DEFAULT_NOWIN_COPTS, + }), + linkshared = True, + deps = [ + "//api", + ], +) + +# no cc_shared_library in bazel 4.2 +cc_binary( + name = "component_h", + srcs = [ + "component_h.cc", + ], + copts = select({ + "//bazel:windows": HIDDEN_WIN_COPTS, + "//conditions:default": HIDDEN_NOWIN_COPTS, + }), + linkshared = True, + deps = [ + "//api", + ], +) + +# +# To build this test alone: +# - bazel build //api/test/singleton:singleton_test +# - bazel build //api/test/singleton:component_g +# - bazel build //api/test/singleton:component_h +# +# Note that singleton_test does not depend on +# component_g and component_h, on purpose. +# +# To run this test: +# bazel test //api/test/singleton:singleton_test +# + +cc_test( + name = "singleton_test", + srcs = [ + "singleton_test.cc", + ], + defines = ["BAZEL_BUILD"], + linkopts = [ + "-ldl", + ], + linkstatic = False, + tags = [ + "api", + "test", + ], + deps = [ + "component_a", + "component_b", + "component_c", + "component_d", + "component_e", + "component_f", + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/CMakeLists.txt new file mode 100644 index 000000000..450308cd8 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/CMakeLists.txt @@ -0,0 +1,61 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +include(GoogleTest) + +# Header only singletons are not available in windows yet. + +if(NOT WIN32) + + add_library(component_a STATIC component_a.cc) + target_link_libraries(component_a opentelemetry_api) + + add_library(component_b STATIC component_b.cc) + target_link_libraries(component_b opentelemetry_api) + + add_library(component_c SHARED component_c.cc) + set_target_properties(component_c PROPERTIES CXX_VISIBILITY_PRESET default) + target_link_libraries(component_c opentelemetry_api) + + add_library(component_d SHARED component_d.cc) + set_target_properties(component_d PROPERTIES CXX_VISIBILITY_PRESET hidden) + target_link_libraries(component_d opentelemetry_api) + + add_library(component_e SHARED component_e.cc) + set_target_properties(component_e PROPERTIES CXX_VISIBILITY_PRESET default) + target_link_libraries(component_e opentelemetry_api) + + add_library(component_f SHARED component_f.cc) + set_target_properties(component_f PROPERTIES CXX_VISIBILITY_PRESET hidden) + target_link_libraries(component_f opentelemetry_api) + + add_library(component_g SHARED component_g.cc) + set_target_properties(component_g PROPERTIES CXX_VISIBILITY_PRESET default) + target_link_libraries(component_g opentelemetry_api) + + add_library(component_h SHARED component_h.cc) + set_target_properties(component_h PROPERTIES CXX_VISIBILITY_PRESET hidden) + target_link_libraries(component_h opentelemetry_api) + + add_executable(singleton_test singleton_test.cc) + + # Not linking with component_g and component_h on purpose + target_link_libraries( + singleton_test + component_a + component_b + component_c + component_d + component_e + component_f + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} + opentelemetry_api) + + gtest_add_tests( + TARGET singleton_test + TEST_PREFIX singleton. + TEST_LIST singleton_test) + +endif() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_a.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_a.cc new file mode 100644 index 000000000..bdf03cb69 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_a.cc @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#include "component_a.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("A", "10.1"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("A::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("A::f2")); + + f1(); + f1(); +} + +void do_something_in_a() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("A::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_a.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_a.h new file mode 100644 index 000000000..2e06edf9c --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_a.h @@ -0,0 +1,4 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +void do_something_in_a(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_b.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_b.cc new file mode 100644 index 000000000..966d9c461 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_b.cc @@ -0,0 +1,37 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#include "component_b.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("B", "20.2"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("B::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("B::f2")); + + f1(); + f1(); +} + +void do_something_in_b() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("B::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_b.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_b.h new file mode 100644 index 000000000..2e526e21d --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_b.h @@ -0,0 +1,4 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +void do_something_in_b(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_c.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_c.cc new file mode 100644 index 000000000..cd87ceb72 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_c.cc @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#define BUILD_COMPONENT_C + +#include "component_c.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("C", "30.3"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("C::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("C::f2")); + + f1(); + f1(); +} + +void do_something_in_c() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("C::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_c.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_c.h new file mode 100644 index 000000000..11b8c9622 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_c.h @@ -0,0 +1,15 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#if defined(_MSC_VER) +// component_c is a DLL + +# ifdef BUILD_COMPONENT_C +__declspec(dllexport) +# else +__declspec(dllimport) +# endif + +#endif + + void do_something_in_c(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_d.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_d.cc new file mode 100644 index 000000000..313fd1d23 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_d.cc @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#define BUILD_COMPONENT_D + +#include "component_d.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("D", "40.4"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("D::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("D::f2")); + + f1(); + f1(); +} + +void do_something_in_d() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("D::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_d.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_d.h new file mode 100644 index 000000000..1090014c2 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_d.h @@ -0,0 +1,21 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Make the entry point visible, loaded dynamically + +#if defined(_MSC_VER) +// component_d is a DLL + +# ifdef BUILD_COMPONENT_D +__declspec(dllexport) +# else +__declspec(dllimport) +# endif + +#else +// component_d is a shared library (*.so) +// component_d is compiled with visibility("hidden"), +__attribute__((visibility("default"))) +#endif + + void do_something_in_d(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_e.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_e.cc new file mode 100644 index 000000000..9c88d2773 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_e.cc @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#define BUILD_COMPONENT_E + +#include "component_e.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("E", "50.5"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("E::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("E::f2")); + + f1(); + f1(); +} + +void do_something_in_e() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("E::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_e.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_e.h new file mode 100644 index 000000000..223a1f3a8 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_e.h @@ -0,0 +1,15 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#if defined(_MSC_VER) +// component_e is a DLL + +# ifdef BUILD_COMPONENT_E +__declspec(dllexport) +# else +__declspec(dllimport) +# endif + +#endif + + void do_something_in_e(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_f.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_f.cc new file mode 100644 index 000000000..33b0af2fb --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_f.cc @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#define BUILD_COMPONENT_F + +#include "component_f.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("F", "60.6"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("F::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("F::f2")); + + f1(); + f1(); +} + +void do_something_in_f() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("F::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_f.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_f.h new file mode 100644 index 000000000..80334de5a --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_f.h @@ -0,0 +1,21 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Make the entry point visible, loaded dynamically + +#if defined(_MSC_VER) +// component_f is a DLL + +# ifdef BUILD_COMPONENT_F +__declspec(dllexport) +# else +__declspec(dllimport) +# endif + +#else +// component_f is a shared library (*.so) +// component_f is compiled with visibility("hidden"), +__attribute__((visibility("default"))) +#endif + + void do_something_in_f(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_g.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_g.cc new file mode 100644 index 000000000..49732d9b1 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_g.cc @@ -0,0 +1,42 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("G", "70.7"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::f2")); + + f1(); + f1(); +} + +extern "C" + +#if defined(_MSC_VER) + // component_g is a DLL + __declspec(dllexport) +#endif + + void do_something_in_g() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_h.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_h.cc new file mode 100644 index 000000000..b486536fc --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/component_h.cc @@ -0,0 +1,48 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("H", "80.8"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::f2")); + + f1(); + f1(); +} + +extern "C" + +#if defined(_MSC_VER) + // component_h is a DLL + + __declspec(dllexport) + +#else +// component_h is a shared library (*.so) +// component_h is compiled with visibility("hidden"), +__attribute__((visibility("default"))) +#endif + + void do_something_in_h() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::library")); + + f2(); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/singleton_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/singleton_test.cc new file mode 100644 index 000000000..44a445e5b --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/singleton/singleton_test.cc @@ -0,0 +1,392 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include + +/* + TODO: + Once singleton are supported for windows, + expand this test to use ::LoadLibrary, ::GetProcAddress, ::FreeLibrary +*/ +#ifndef _WIN32 +# include +#endif + +#include + +#include "component_a.h" +#include "component_b.h" +#include "component_c.h" +#include "component_d.h" +#include "component_e.h" +#include "component_f.h" + +#include "opentelemetry/trace/default_span.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/span.h" +#include "opentelemetry/trace/span_context_kv_iterable.h" +#include "opentelemetry/trace/span_startoptions.h" +#include "opentelemetry/trace/tracer_provider.h" + +using namespace opentelemetry; + +void do_something() +{ + do_something_in_a(); + do_something_in_b(); + do_something_in_c(); + do_something_in_d(); + do_something_in_e(); + do_something_in_f(); + + /* + See https://github.com/bazelbuild/bazel/issues/4218 + + There is no way to set LD_LIBRARY_PATH in bazel, + for dlopen() to find the library. + + Verified manually that dlopen("/full/path/to/libcomponent_g.so") works, + and that the test passes in this case. + */ + +#ifndef BAZEL_BUILD + /* Call do_something_in_g() */ + + void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); + EXPECT_NE(component_g, nullptr); + + auto *func_g = (void (*)())dlsym(component_g, "do_something_in_g"); + EXPECT_NE(func_g, nullptr); + + (*func_g)(); + + dlclose(component_g); + + /* Call do_something_in_h() */ + + void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); + EXPECT_NE(component_h, nullptr); + + auto *func_h = (void (*)())dlsym(component_h, "do_something_in_h"); + EXPECT_NE(func_h, nullptr); + + (*func_h)(); + + dlclose(component_h); +#endif +} + +int span_a_lib_count = 0; +int span_a_f1_count = 0; +int span_a_f2_count = 0; +int span_b_lib_count = 0; +int span_b_f1_count = 0; +int span_b_f2_count = 0; +int span_c_lib_count = 0; +int span_c_f1_count = 0; +int span_c_f2_count = 0; +int span_d_lib_count = 0; +int span_d_f1_count = 0; +int span_d_f2_count = 0; +int span_e_lib_count = 0; +int span_e_f1_count = 0; +int span_e_f2_count = 0; +int span_f_lib_count = 0; +int span_f_f1_count = 0; +int span_f_f2_count = 0; +int span_g_lib_count = 0; +int span_g_f1_count = 0; +int span_g_f2_count = 0; +int span_h_lib_count = 0; +int span_h_f1_count = 0; +int span_h_f2_count = 0; +int unknown_span_count = 0; + +void reset_counts() +{ + span_a_lib_count = 0; + span_a_f1_count = 0; + span_a_f2_count = 0; + span_b_lib_count = 0; + span_b_f1_count = 0; + span_b_f2_count = 0; + span_c_lib_count = 0; + span_c_f1_count = 0; + span_c_f2_count = 0; + span_d_lib_count = 0; + span_d_f1_count = 0; + span_d_f2_count = 0; + span_e_lib_count = 0; + span_e_f1_count = 0; + span_e_f2_count = 0; + span_f_lib_count = 0; + span_f_f1_count = 0; + span_f_f2_count = 0; + span_g_lib_count = 0; + span_g_f1_count = 0; + span_g_f2_count = 0; + span_h_lib_count = 0; + span_h_f1_count = 0; + span_h_f2_count = 0; + unknown_span_count = 0; +} + +class MyTracer : public trace::Tracer +{ +public: + nostd::shared_ptr StartSpan( + nostd::string_view name, + const common::KeyValueIterable & /* attributes */, + const trace::SpanContextKeyValueIterable & /* links */, + const trace::StartSpanOptions & /* options */) noexcept override + { + nostd::shared_ptr result(new trace::DefaultSpan(trace::SpanContext::GetInvalid())); + + /* + Unit test code, no need to be fancy. + */ + + if (name == "A::library") + { + span_a_lib_count++; + } + else if (name == "A::f1") + { + span_a_f1_count++; + } + else if (name == "A::f2") + { + span_a_f2_count++; + } + else if (name == "B::library") + { + span_b_lib_count++; + } + else if (name == "B::f1") + { + span_b_f1_count++; + } + else if (name == "B::f2") + { + span_b_f2_count++; + } + else if (name == "C::library") + { + span_c_lib_count++; + } + else if (name == "C::f1") + { + span_c_f1_count++; + } + else if (name == "C::f2") + { + span_c_f2_count++; + } + else if (name == "D::library") + { + span_d_lib_count++; + } + else if (name == "D::f1") + { + span_d_f1_count++; + } + else if (name == "D::f2") + { + span_d_f2_count++; + } + else if (name == "E::library") + { + span_e_lib_count++; + } + else if (name == "E::f1") + { + span_e_f1_count++; + } + else if (name == "E::f2") + { + span_e_f2_count++; + } + else if (name == "F::library") + { + span_f_lib_count++; + } + else if (name == "F::f1") + { + span_f_f1_count++; + } + else if (name == "F::f2") + { + span_f_f2_count++; + } + else if (name == "G::library") + { + span_g_lib_count++; + } + else if (name == "G::f1") + { + span_g_f1_count++; + } + else if (name == "G::f2") + { + span_g_f2_count++; + } + else if (name == "H::library") + { + span_h_lib_count++; + } + else if (name == "H::f1") + { + span_h_f1_count++; + } + else if (name == "H::f2") + { + span_h_f2_count++; + } + else + { + unknown_span_count++; + } + + return result; + } + + void ForceFlushWithMicroseconds(uint64_t /* timeout */) noexcept override {} + + void CloseWithMicroseconds(uint64_t /* timeout */) noexcept override {} +}; + +class MyTracerProvider : public trace::TracerProvider +{ +public: + static std::shared_ptr Create() + { + std::shared_ptr result(new MyTracerProvider()); + return result; + } + + nostd::shared_ptr GetTracer(nostd::string_view /* library_name */, + nostd::string_view /* library_version */, + nostd::string_view /* schema_url */) noexcept override + { + nostd::shared_ptr result(new MyTracer()); + return result; + } +}; + +void setup_otel() +{ + std::shared_ptr provider = MyTracerProvider::Create(); + + // The whole point of this test is to make sure + // that the API singleton behind SetTracerProvider() + // works for all components, static and dynamic. + + // Set the global tracer provider + trace_api::Provider::SetTracerProvider(provider); +} + +void cleanup_otel() +{ + std::shared_ptr provider( + new opentelemetry::trace::NoopTracerProvider()); + + // Set the global tracer provider + trace_api::Provider::SetTracerProvider(provider); +} + +TEST(SingletonTest, Uniqueness) +{ + do_something(); + + EXPECT_EQ(span_a_lib_count, 0); + EXPECT_EQ(span_a_f1_count, 0); + EXPECT_EQ(span_a_f2_count, 0); + EXPECT_EQ(span_b_lib_count, 0); + EXPECT_EQ(span_b_f1_count, 0); + EXPECT_EQ(span_b_f2_count, 0); + EXPECT_EQ(span_c_lib_count, 0); + EXPECT_EQ(span_c_f1_count, 0); + EXPECT_EQ(span_c_f2_count, 0); + EXPECT_EQ(span_d_lib_count, 0); + EXPECT_EQ(span_d_f1_count, 0); + EXPECT_EQ(span_d_f2_count, 0); + EXPECT_EQ(span_e_lib_count, 0); + EXPECT_EQ(span_e_f1_count, 0); + EXPECT_EQ(span_e_f2_count, 0); + EXPECT_EQ(span_f_lib_count, 0); + EXPECT_EQ(span_f_f1_count, 0); + EXPECT_EQ(span_f_f2_count, 0); + EXPECT_EQ(span_g_lib_count, 0); + EXPECT_EQ(span_g_f1_count, 0); + EXPECT_EQ(span_g_f2_count, 0); + EXPECT_EQ(span_h_lib_count, 0); + EXPECT_EQ(span_h_f1_count, 0); + EXPECT_EQ(span_h_f2_count, 0); + EXPECT_EQ(unknown_span_count, 0); + + reset_counts(); + setup_otel(); + + do_something(); + + EXPECT_EQ(span_a_lib_count, 1); + EXPECT_EQ(span_a_f1_count, 2); + EXPECT_EQ(span_a_f2_count, 1); + EXPECT_EQ(span_b_lib_count, 1); + EXPECT_EQ(span_b_f1_count, 2); + EXPECT_EQ(span_b_f2_count, 1); + EXPECT_EQ(span_c_lib_count, 1); + EXPECT_EQ(span_c_f1_count, 2); + EXPECT_EQ(span_c_f2_count, 1); + EXPECT_EQ(span_d_lib_count, 1); + EXPECT_EQ(span_d_f1_count, 2); + EXPECT_EQ(span_d_f2_count, 1); + EXPECT_EQ(span_e_lib_count, 1); + EXPECT_EQ(span_e_f1_count, 2); + EXPECT_EQ(span_e_f2_count, 1); + EXPECT_EQ(span_f_lib_count, 1); + EXPECT_EQ(span_f_f1_count, 2); + EXPECT_EQ(span_f_f2_count, 1); + +#ifndef BAZEL_BUILD + EXPECT_EQ(span_g_lib_count, 1); + EXPECT_EQ(span_g_f1_count, 2); + EXPECT_EQ(span_g_f2_count, 1); + EXPECT_EQ(span_h_lib_count, 1); + EXPECT_EQ(span_h_f1_count, 2); + EXPECT_EQ(span_h_f2_count, 1); +#endif + + EXPECT_EQ(unknown_span_count, 0); + + reset_counts(); + cleanup_otel(); + + do_something(); + + EXPECT_EQ(span_a_lib_count, 0); + EXPECT_EQ(span_a_f1_count, 0); + EXPECT_EQ(span_a_f2_count, 0); + EXPECT_EQ(span_b_lib_count, 0); + EXPECT_EQ(span_b_f1_count, 0); + EXPECT_EQ(span_b_f2_count, 0); + EXPECT_EQ(span_c_lib_count, 0); + EXPECT_EQ(span_c_f1_count, 0); + EXPECT_EQ(span_c_f2_count, 0); + EXPECT_EQ(span_d_lib_count, 0); + EXPECT_EQ(span_d_f1_count, 0); + EXPECT_EQ(span_d_f2_count, 0); + EXPECT_EQ(span_e_lib_count, 0); + EXPECT_EQ(span_e_f1_count, 0); + EXPECT_EQ(span_e_f2_count, 0); + EXPECT_EQ(span_f_lib_count, 0); + EXPECT_EQ(span_f_f1_count, 0); + EXPECT_EQ(span_f_f2_count, 0); + EXPECT_EQ(span_g_lib_count, 0); + EXPECT_EQ(span_g_f1_count, 0); + EXPECT_EQ(span_g_f2_count, 0); + EXPECT_EQ(span_h_lib_count, 0); + EXPECT_EQ(span_h_f1_count, 0); + EXPECT_EQ(span_h_f2_count, 0); + EXPECT_EQ(unknown_span_count, 0); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/BUILD new file mode 100644 index 000000000..d23308459 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/BUILD @@ -0,0 +1,204 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "default_span_test", + srcs = [ + "default_span_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "noop_test", + srcs = [ + "noop_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "key_value_iterable_view_test", + srcs = [ + "key_value_iterable_view_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +otel_cc_benchmark( + name = "span_id_benchmark", + srcs = ["span_id_benchmark.cc"], + tags = [ + "api", + "benchmark", + "test", + "trace", + ], + deps = ["//api"], +) + +otel_cc_benchmark( + name = "span_benchmark", + srcs = ["span_benchmark.cc"], + tags = [ + "api", + "benchmark", + "test", + "trace", + ], + deps = ["//api"], +) + +cc_test( + name = "provider_test", + srcs = [ + "provider_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "span_id_test", + srcs = [ + "span_id_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "trace_flags_test", + srcs = [ + "trace_flags_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "trace_id_test", + srcs = [ + "trace_id_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "span_context_test", + srcs = [ + "span_context_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "trace_state_test", + srcs = [ + "trace_state_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "scope_test", + srcs = [ + "scope_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "tracer_test", + srcs = [ + "tracer_test.cc", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/CMakeLists.txt new file mode 100644 index 000000000..34b49db84 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(propagation) + +foreach( + testname + key_value_iterable_view_test + provider_test + span_id_test + trace_id_test + trace_flags_test + span_context_test + scope_test + noop_test + trace_state_test + tracer_test) + add_executable(api_${testname} "${testname}.cc") + target_link_libraries(api_${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET api_${testname} + TEST_PREFIX trace. + TEST_LIST api_${testname}) +endforeach() + +if(WITH_BENCHMARK) + add_executable(span_id_benchmark span_id_benchmark.cc) + target_link_libraries(span_id_benchmark benchmark::benchmark + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + add_executable(span_benchmark span_benchmark.cc) + target_link_libraries(span_benchmark benchmark::benchmark + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) +endif() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/default_span_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/default_span_test.cc new file mode 100644 index 000000000..377a0a858 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/default_span_test.cc @@ -0,0 +1,24 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/default_span.h" +#include "opentelemetry/trace/span_context.h" + +#include +#include + +#include + +namespace +{ + +using opentelemetry::trace::DefaultSpan; +using opentelemetry::trace::SpanContext; + +TEST(DefaultSpanTest, GetContext) +{ + SpanContext span_context = SpanContext(false, false); + DefaultSpan sp = DefaultSpan(span_context); + EXPECT_EQ(span_context, sp.GetContext()); +} +} // namespace diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/key_value_iterable_view_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/key_value_iterable_view_test.cc new file mode 100644 index 000000000..e0f43c4af --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/key_value_iterable_view_test.cc @@ -0,0 +1,69 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/common/key_value_iterable_view.h" + +#include +#include +#include "opentelemetry/nostd/type_traits.h" + +using namespace opentelemetry; + +static int TakeKeyValues(const common::KeyValueIterable &iterable) +{ + std::map result; + int count = 0; + iterable.ForEachKeyValue( + [&](nostd::string_view /* key */, common::AttributeValue /* value */) noexcept { + ++count; + return true; + }); + return count; +} + +template ::value> * = nullptr> +static int TakeKeyValues(const T &iterable) +{ + return TakeKeyValues(common::KeyValueIterableView{iterable}); +} + +TEST(KeyValueIterableViewTest, is_key_value_iterable) +{ + using M1 = std::map; + EXPECT_TRUE(bool{common::detail::is_key_value_iterable::value}); + + using M2 = std::map; + EXPECT_TRUE(bool{common::detail::is_key_value_iterable::value}); + + using M3 = std::map; + EXPECT_TRUE(bool{common::detail::is_key_value_iterable::value}); + + struct A + {}; + using M4 = std::map; + EXPECT_FALSE(bool{common::detail::is_key_value_iterable::value}); +} + +TEST(KeyValueIterableViewTest, ForEachKeyValue) +{ + std::map m1 = {{"abc", "123"}, {"xyz", "456"}}; + EXPECT_EQ(TakeKeyValues(m1), 2); + + std::vector> v1 = {{"abc", 123}, {"xyz", 456}}; + EXPECT_EQ(TakeKeyValues(v1), 2); +} + +TEST(KeyValueIterableViewTest, ForEachKeyValueWithExit) +{ + using M = std::map; + M m1 = {{"abc", "123"}, {"xyz", "456"}}; + common::KeyValueIterableView iterable{m1}; + int count = 0; + auto exit = iterable.ForEachKeyValue( + [&count](nostd::string_view /*key*/, common::AttributeValue /*value*/) noexcept { + ++count; + return false; + }); + EXPECT_EQ(count, 1); + EXPECT_FALSE(exit); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/noop_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/noop_test.cc new file mode 100644 index 000000000..130496faf --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/noop_test.cc @@ -0,0 +1,81 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/noop.h" +#include "opentelemetry/common/timestamp.h" + +#include +#include +#include + +#include + +namespace trace_api = opentelemetry::trace; +namespace nonstd = opentelemetry::nostd; +namespace common = opentelemetry::common; + +TEST(NoopTest, UseNoopTracers) +{ + std::shared_ptr tracer{new trace_api::NoopTracer{}}; + auto s1 = tracer->StartSpan("abc"); + + std::map attributes1; + s1->AddEvent("abc", attributes1); + + std::vector> attributes2; + s1->AddEvent("abc", attributes2); + + s1->AddEvent("abc", {{"a", 1}, {"b", "2"}, {"c", 3.0}}); + + std::vector>> attributes3; + s1->AddEvent("abc", attributes3); + + s1->SetAttribute("abc", 4); + + s1->AddEvent("abc"); // add Empty + + EXPECT_EQ(s1->IsRecording(), false); + + s1->SetStatus(trace_api::StatusCode::kUnset, "span unset"); + + s1->UpdateName("test_name"); + + common::SystemTimestamp t1; + s1->AddEvent("test_time_stamp", t1); + + s1->GetContext(); +} + +TEST(NoopTest, StartSpan) +{ + std::shared_ptr tracer{new trace_api::NoopTracer{}}; + + std::map attrs = {{"a", "3"}}; + std::vector>> links = { + {trace_api::SpanContext(false, false), attrs}}; + auto s1 = tracer->StartSpan("abc", attrs, links); + + auto s2 = + tracer->StartSpan("efg", {{"a", 3}}, {{trace_api::SpanContext(false, false), {{"b", 4}}}}); +} + +TEST(NoopTest, CreateSpanValidSpanContext) +{ + // Create valid spancontext for NoopSpan + + constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; + constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + auto trace_id = trace_api::TraceId{buf_trace}; + auto span_id = trace_api::SpanId{buf_span}; + auto span_context = nonstd::unique_ptr( + new trace_api::SpanContext{trace_id, span_id, trace_api::TraceFlags{true}, false}); + std::shared_ptr tracer{new trace_api::NoopTracer{}}; + auto s1 = + nonstd::shared_ptr(new trace_api::NoopSpan(tracer, std::move(span_context))); + auto stored_span_context = s1->GetContext(); + EXPECT_EQ(stored_span_context.span_id(), span_id); + EXPECT_EQ(stored_span_context.trace_id(), trace_id); + + s1->AddEvent("even1"); // noop + s1->End(); // noop +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/BUILD b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/BUILD new file mode 100644 index 000000000..8e9718e80 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/BUILD @@ -0,0 +1,55 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") + +cc_test( + name = "http_text_format_test", + srcs = [ + "http_text_format_test.cc", + "util.h", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "b3_propagation_test", + srcs = [ + "b3_propagation_test.cc", + "util.h", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "jaeger_propagation_test", + srcs = [ + "jaeger_propagation_test.cc", + "util.h", + ], + tags = [ + "api", + "test", + "trace", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/CMakeLists.txt b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/CMakeLists.txt new file mode 100644 index 000000000..e52957342 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +foreach(testname http_text_format_test b3_propagation_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX trace. + TEST_LIST ${testname}) +endforeach() + +if(NOT WITH_NO_DEPRECATED_CODE) + foreach(testname jaeger_propagation_test) + + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX trace. + TEST_LIST ${testname}) + endforeach() +endif() diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/b3_propagation_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/b3_propagation_test.cc new file mode 100644 index 000000000..2538b5be2 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/b3_propagation_test.cc @@ -0,0 +1,189 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/trace/propagation/b3_propagator.h" +#include "opentelemetry/trace/scope.h" +#include "util.h" + +#include + +#include + +using namespace opentelemetry; + +class TextMapCarrierTest : public context::propagation::TextMapCarrier +{ +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override + { + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); + } + + std::map headers_; +}; + +using MapB3Context = trace::propagation::B3Propagator; + +static MapB3Context format = MapB3Context(); + +using MapB3ContextMultiHeader = trace::propagation::B3PropagatorMultiHeader; + +static MapB3ContextMultiHeader formatMultiHeader = MapB3ContextMultiHeader(); + +TEST(B3PropagationTest, TraceFlagsBufferGeneration) +{ + EXPECT_EQ(MapB3Context::TraceFlagsFromHex("0"), trace::TraceFlags()); + EXPECT_EQ(MapB3Context::TraceFlagsFromHex("1"), trace::TraceFlags(trace::TraceFlags::kIsSampled)); +} + +TEST(B3PropagationTest, PropagateInvalidContext) +{ + // Do not propagate invalid trace context. + TextMapCarrierTest carrier; + context::Context ctx{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + format.Inject(carrier, ctx); + EXPECT_TRUE(carrier.headers_.count("b3") == 0); +} + +TEST(B3PropagationTest, ExtractInvalidContext) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "00000000000000000000000000000000-0000000000000000-0"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + auto span = nostd::get>(ctx2_span); + EXPECT_EQ(span->GetContext().IsRemote(), false); +} + +TEST(B3PropagationTest, DoNotExtractWithInvalidHex) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "0000000zzz0000000000000000000000-0000000zzz000000-1"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + auto span = nostd::get>(ctx2_span); + EXPECT_EQ(span->GetContext().IsRemote(), false); +} + +TEST(B3PropagationTest, SetRemoteSpan) +{ + TextMapCarrierTest carrier; + carrier.headers_ = { + {"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); + + auto span = nostd::get>(ctx2_span); + + EXPECT_EQ(Hex(span->GetContext().trace_id()), "80f198ee56343ba864fe8b2a57d3eff7"); + EXPECT_EQ(Hex(span->GetContext().span_id()), "e457b5a2e4d86bd1"); + EXPECT_EQ(span->GetContext().IsSampled(), true); + EXPECT_EQ(span->GetContext().IsRemote(), true); +} + +TEST(B3PropagationTest, SetRemoteSpan_TraceIdShort) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "80f198ee56343ba8-e457b5a2e4d86bd1-1-05e3ac9a4f6e3b90"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); + + auto span = nostd::get>(ctx2_span); + + EXPECT_EQ(Hex(span->GetContext().trace_id()), "000000000000000080f198ee56343ba8"); + EXPECT_EQ(Hex(span->GetContext().span_id()), "e457b5a2e4d86bd1"); + EXPECT_EQ(span->GetContext().IsSampled(), true); + EXPECT_EQ(span->GetContext().IsRemote(), true); +} + +TEST(B3PropagationTest, SetRemoteSpan_SingleHeaderNoFlags) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"b3", "80f198ee56343ba864fe8b2a57d3eff7-e457b5a2e4d86bd1"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); + + auto span = nostd::get>(ctx2_span); + + EXPECT_EQ(Hex(span->GetContext().trace_id()), "80f198ee56343ba864fe8b2a57d3eff7"); + EXPECT_EQ(Hex(span->GetContext().span_id()), "e457b5a2e4d86bd1"); + EXPECT_EQ(span->GetContext().IsSampled(), false); + EXPECT_EQ(span->GetContext().IsRemote(), true); +} + +TEST(B3PropagationTest, SetRemoteSpanMultiHeader) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"X-B3-TraceId", "80f198ee56343ba864fe8b2a57d3eff7"}, + {"X-B3-SpanId", "e457b5a2e4d86bd1"}, + {"X-B3-Sampled", "1"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); + + auto span = nostd::get>(ctx2_span); + + EXPECT_EQ(Hex(span->GetContext().trace_id()), "80f198ee56343ba864fe8b2a57d3eff7"); + EXPECT_EQ(Hex(span->GetContext().span_id()), "e457b5a2e4d86bd1"); + EXPECT_EQ(span->GetContext().IsSampled(), true); + EXPECT_EQ(span->GetContext().IsRemote(), true); +} + +TEST(B3PropagationTest, GetCurrentSpan) +{ + TextMapCarrierTest carrier; + constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; + constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, + trace::TraceFlags{true}, false}; + nostd::shared_ptr sp{new trace::DefaultSpan{span_context}}; + + // Set `sp` as the currently active span, which must be used by `Inject`. + trace::Scope scoped_span{sp}; + + format.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["b3"], "0102030405060708090a0b0c0d0e0f10-0102030405060708-1"); +} + +TEST(B3PropagationTest, GetCurrentSpanMultiHeader) +{ + TextMapCarrierTest carrier; + constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; + constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, + trace::TraceFlags{true}, false}; + nostd::shared_ptr sp{new trace::DefaultSpan{span_context}}; + + // Set `sp` as the currently active span, which must be used by `Inject`. + trace::Scope scoped_span{sp}; + + formatMultiHeader.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["X-B3-TraceId"], "0102030405060708090a0b0c0d0e0f10"); + EXPECT_EQ(carrier.headers_["X-B3-SpanId"], "0102030405060708"); + EXPECT_EQ(carrier.headers_["X-B3-Sampled"], "1"); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/http_text_format_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/http_text_format_test.cc new file mode 100644 index 000000000..8fa0e44ed --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/http_text_format_test.cc @@ -0,0 +1,211 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/context/propagation/global_propagator.h" +#include "opentelemetry/context/runtime_context.h" +#include "opentelemetry/trace/context.h" +#include "opentelemetry/trace/propagation/http_trace_context.h" +#include "opentelemetry/trace/scope.h" +#include "util.h" + +#include +#include + +#include + +using namespace opentelemetry; + +class TextMapCarrierTest : public context::propagation::TextMapCarrier +{ +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override + { + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); + } + + std::map headers_; +}; + +using MapHttpTraceContext = trace::propagation::HttpTraceContext; + +static MapHttpTraceContext format = MapHttpTraceContext(); + +TEST(TextMapPropagatorTest, TraceFlagsBufferGeneration) +{ + EXPECT_EQ(MapHttpTraceContext::TraceFlagsFromHex("00"), trace::TraceFlags()); +} + +TEST(TextMapPropagatorTest, NoSendEmptyTraceState) +{ + // If the trace state is empty, do not set the header. + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}}; + context::Context ctx1 = context::Context{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + context::Context ctx2 = format.Extract(carrier, ctx1); + TextMapCarrierTest carrier2; + format.Inject(carrier2, ctx2); + EXPECT_TRUE(carrier2.headers_.count("traceparent") > 0); + EXPECT_FALSE(carrier2.headers_.count("tracestate") > 0); +} + +TEST(TextMapPropagatorTest, PropogateTraceState) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"tracestate", "congo=t61rcWkgMzE"}}; + context::Context ctx1 = context::Context{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + TextMapCarrierTest carrier2; + format.Inject(carrier2, ctx2); + + EXPECT_TRUE(carrier2.headers_.count("traceparent") > 0); + EXPECT_TRUE(carrier2.headers_.count("tracestate") > 0); + EXPECT_EQ(carrier2.headers_["tracestate"], "congo=t61rcWkgMzE"); +} + +TEST(TextMapPropagatorTest, PropagateInvalidContext) +{ + // Do not propagate invalid trace context. + TextMapCarrierTest carrier; + context::Context ctx{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + format.Inject(carrier, ctx); + EXPECT_TRUE(carrier.headers_.count("traceparent") == 0); + EXPECT_TRUE(carrier.headers_.count("tracestate") == 0); +} + +TEST(TextMapPropagatorTest, SetRemoteSpan) +{ + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto ctx2_span = ctx2.GetValue(trace::kSpanKey); + EXPECT_TRUE(nostd::holds_alternative>(ctx2_span)); + + auto span = nostd::get>(ctx2_span); + + EXPECT_EQ(Hex(span->GetContext().trace_id()), "4bf92f3577b34da6a3ce929d0e0e4736"); + EXPECT_EQ(Hex(span->GetContext().span_id()), "0102030405060708"); + EXPECT_EQ(span->GetContext().IsSampled(), true); + EXPECT_EQ(span->GetContext().IsRemote(), true); +} + +TEST(TextMapPropagatorTest, GetCurrentSpan) +{ + TextMapCarrierTest carrier; + constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; + constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + + auto trace_state = trace::TraceState::FromHeader("congo=t61rcWkgMzE"); + trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, + trace::TraceFlags{true}, false, trace_state}; + nostd::shared_ptr sp{new trace::DefaultSpan{span_context}}; + + // Set `sp` as the currently active span, which must be used by `Inject`. + trace::Scope scoped_span{sp}; + + format.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["traceparent"], + "00-0102030405060708090a0b0c0d0e0f10-0102030405060708-01"); + EXPECT_EQ(carrier.headers_["tracestate"], "congo=t61rcWkgMzE"); +} + +TEST(TextMapPropagatorTest, InvalidIdentitiesAreNotExtracted) +{ + TextMapCarrierTest carrier; + std::vector traces = { + "ff-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", + "00-0af7651916cd43dd8448eb211c80319c1-b9c7c989f97918e1-01", + "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e11-01", + "0-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", + "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-0", + "00-0af7651916cd43dd8448eb211c8031-b9c7c989f97918e1-01", + "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97-01", + "00-1-1-00", + "00--b9c7c989f97918e1-01", + "00-0af7651916cd43dd8448eb211c80319c1--01", + "", + "---", + }; + + for (auto &trace : traces) + { + carrier.headers_ = {{"traceparent", trace}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto span = trace::GetSpan(ctx2)->GetContext(); + EXPECT_FALSE(span.IsValid()); + } +} + +TEST(GlobalTextMapPropagator, NoOpPropagator) +{ + + auto propagator = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + TextMapCarrierTest carrier; + + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"tracestate", "congo=t61rcWkgMzE"}}; + context::Context ctx1 = context::Context{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + context::Context ctx2 = propagator->Extract(carrier, ctx1); + + TextMapCarrierTest carrier2; + propagator->Inject(carrier2, ctx2); + + EXPECT_TRUE(carrier2.headers_.count("tracestate") == 0); + EXPECT_TRUE(carrier2.headers_.count("traceparent") == 0); +} + +TEST(GlobalPropagator, SetAndGet) +{ + + auto trace_state_value = "congo=t61rcWkgMzE"; + context::propagation::GlobalTextMapPropagator::SetGlobalPropagator( + nostd::shared_ptr(new MapHttpTraceContext())); + + auto propagator = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator(); + + TextMapCarrierTest carrier; + carrier.headers_ = {{"traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-0102030405060708-01"}, + {"tracestate", trace_state_value}}; + context::Context ctx1 = context::Context{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + context::Context ctx2 = propagator->Extract(carrier, ctx1); + + TextMapCarrierTest carrier2; + propagator->Inject(carrier2, ctx2); + + EXPECT_TRUE(carrier.headers_.count("traceparent") > 0); + EXPECT_TRUE(carrier.headers_.count("tracestate") > 0); + EXPECT_EQ(carrier.headers_["tracestate"], trace_state_value); + + std::vector fields; + propagator->Fields([&fields](nostd::string_view field) { + fields.push_back(field.data()); + return true; + }); + EXPECT_EQ(fields.size(), 2); + EXPECT_EQ(fields[0], trace::propagation::kTraceParent); + EXPECT_EQ(fields[1], trace::propagation::kTraceState); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/jaeger_propagation_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/jaeger_propagation_test.cc new file mode 100644 index 000000000..c33761738 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/jaeger_propagation_test.cc @@ -0,0 +1,168 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/propagation/jaeger.h" +#include "opentelemetry/trace/scope.h" +#include "util.h" + +#include + +#include + +using namespace opentelemetry; + +class TextMapCarrierTest : public context::propagation::TextMapCarrier +{ +public: + virtual nostd::string_view Get(nostd::string_view key) const noexcept override + { + auto it = headers_.find(std::string(key)); + if (it != headers_.end()) + { + return nostd::string_view(it->second); + } + return ""; + } + virtual void Set(nostd::string_view key, nostd::string_view value) noexcept override + { + headers_[std::string(key)] = std::string(value); + } + + std::map headers_; +}; + +using Propagator = trace::propagation::JaegerPropagator; + +static Propagator format = Propagator(); + +TEST(JaegerPropagatorTest, ExtractValidSpans) +{ + struct TestTrace + { + std::string trace_state; + std::string expected_trace_id; + std::string expected_span_id; + bool sampled; + }; + + std::vector traces = { + { + "4bf92f3577b34da6a3ce929d0e0e4736:0102030405060708:0:00", + "4bf92f3577b34da6a3ce929d0e0e4736", + "0102030405060708", + false, + }, + { + "4bf92f3577b34da6a3ce929d0e0e4736:0102030405060708:0:ff", + "4bf92f3577b34da6a3ce929d0e0e4736", + "0102030405060708", + true, + }, + { + "4bf92f3577b34da6a3ce929d0e0e4736:0102030405060708:0:f", + "4bf92f3577b34da6a3ce929d0e0e4736", + "0102030405060708", + true, + }, + { + "a3ce929d0e0e4736:0102030405060708:0:00", + "0000000000000000a3ce929d0e0e4736", + "0102030405060708", + false, + }, + { + "A3CE929D0E0E4736:ABCDEFABCDEF1234:0:01", + "0000000000000000a3ce929d0e0e4736", + "abcdefabcdef1234", + true, + }, + { + "ff:ABCDEFABCDEF1234:0:0", + "000000000000000000000000000000ff", + "abcdefabcdef1234", + false, + }, + { + "4bf92f3577b34da6a3ce929d0e0e4736:0102030405060708:0102030405060708:00", + "4bf92f3577b34da6a3ce929d0e0e4736", + "0102030405060708", + false, + }, + + }; + + for (TestTrace &test_trace : traces) + { + TextMapCarrierTest carrier; + carrier.headers_ = {{"uber-trace-id", test_trace.trace_state}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto span = trace::GetSpan(ctx2)->GetContext(); + EXPECT_TRUE(span.IsValid()); + + EXPECT_EQ(Hex(span.trace_id()), test_trace.expected_trace_id); + EXPECT_EQ(Hex(span.span_id()), test_trace.expected_span_id); + EXPECT_EQ(span.IsSampled(), test_trace.sampled); + EXPECT_EQ(span.IsRemote(), true); + } +} + +TEST(JaegerPropagatorTest, ExctractInvalidSpans) +{ + TextMapCarrierTest carrier; + std::vector traces = { + "4bf92f3577b34da6a3ce929d0e0e47344:0102030405060708:0:00", // too long trace id + "4bf92f3577b34da6a3ce929d0e0e4734:01020304050607089:0:00", // too long span id + "4bf92f3577b34da6x3ce929d0y0e4734:01020304050607089:0:00", // invalid trace id character + "4bf92f3577b34da6a3ce929d0e0e4734:01020304g50607089:0:00", // invalid span id character + "4bf92f3577b34da6a3ce929d0e0e4734::0:00", + "", + "::::", + "0:0:0:0", + ":abcdef12:0:0", + }; + + for (auto &trace : traces) + { + carrier.headers_ = {{"uber-trace-id", trace}}; + context::Context ctx1 = context::Context{}; + context::Context ctx2 = format.Extract(carrier, ctx1); + + auto span = trace::GetSpan(ctx2)->GetContext(); + EXPECT_FALSE(span.IsValid()); + } +} + +TEST(JaegerPropagatorTest, InjectsContext) +{ + TextMapCarrierTest carrier; + constexpr uint8_t buf_span[] = {1, 2, 3, 4, 5, 6, 7, 8}; + constexpr uint8_t buf_trace[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + trace::SpanContext span_context{trace::TraceId{buf_trace}, trace::SpanId{buf_span}, + trace::TraceFlags{true}, false}; + nostd::shared_ptr sp{new trace::DefaultSpan{span_context}}; + trace::Scope scoped_span{sp}; + + format.Inject(carrier, context::RuntimeContext::GetCurrent()); + EXPECT_EQ(carrier.headers_["uber-trace-id"], + "0102030405060708090a0b0c0d0e0f10:0102030405060708:0:01"); + + std::vector fields; + format.Fields([&fields](nostd::string_view field) { + fields.push_back(field.data()); + return true; + }); + EXPECT_EQ(fields.size(), 1); + EXPECT_EQ(fields[0], opentelemetry::trace::propagation::kJaegerTraceHeader); +} + +TEST(JaegerPropagatorTest, DoNotInjectInvalidContext) +{ + TextMapCarrierTest carrier; + context::Context ctx{ + "current-span", + nostd::shared_ptr(new trace::DefaultSpan(trace::SpanContext::GetInvalid()))}; + format.Inject(carrier, ctx); + EXPECT_TRUE(carrier.headers_.count("uber-trace-id") == 0); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/util.h b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/util.h new file mode 100644 index 000000000..ae234d92e --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/propagation/util.h @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +template +static std::string Hex(const T &id_item) +{ + char buf[T::kSize * 2]; + id_item.ToLowerBase16(buf); + return std::string(buf, sizeof(buf)); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/provider_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/provider_test.cc new file mode 100644 index 000000000..21e361933 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/provider_test.cc @@ -0,0 +1,36 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" + +#include + +using opentelemetry::trace::Provider; +using opentelemetry::trace::Tracer; +using opentelemetry::trace::TracerProvider; + +namespace nostd = opentelemetry::nostd; + +class TestProvider : public TracerProvider +{ + nostd::shared_ptr GetTracer(nostd::string_view /* library_name */, + nostd::string_view /* library_version */, + nostd::string_view /* schema_url */) noexcept override + { + return nostd::shared_ptr(nullptr); + } +}; + +TEST(Provider, GetTracerProviderDefault) +{ + auto tf = Provider::GetTracerProvider(); + EXPECT_NE(nullptr, tf); +} + +TEST(Provider, SetTracerProvider) +{ + auto tf = nostd::shared_ptr(new TestProvider()); + Provider::SetTracerProvider(tf); + ASSERT_EQ(tf, Provider::GetTracerProvider()); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/scope_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/scope_test.cc new file mode 100644 index 000000000..b74905b16 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/scope_test.cc @@ -0,0 +1,51 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/context/context.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/noop.h" + +#include + +using opentelemetry::trace::kSpanKey; +using opentelemetry::trace::NoopSpan; +using opentelemetry::trace::Scope; +using opentelemetry::trace::Span; +namespace nostd = opentelemetry::nostd; +namespace context = opentelemetry::context; + +TEST(ScopeTest, Construct) +{ + nostd::shared_ptr span(new NoopSpan(nullptr)); + Scope scope(span); + + context::ContextValue active_span_value = context::RuntimeContext::GetValue(kSpanKey); + ASSERT_TRUE(nostd::holds_alternative>(active_span_value)); + + auto active_span = nostd::get>(active_span_value); + ASSERT_EQ(active_span, span); +} + +TEST(ScopeTest, Destruct) +{ + nostd::shared_ptr span(new NoopSpan(nullptr)); + Scope scope(span); + + { + nostd::shared_ptr span_nested(new NoopSpan(nullptr)); + Scope scope_nested(span_nested); + + context::ContextValue active_span_value = context::RuntimeContext::GetValue(kSpanKey); + ASSERT_TRUE(nostd::holds_alternative>(active_span_value)); + + auto active_span = nostd::get>(active_span_value); + ASSERT_EQ(active_span, span_nested); + } + + context::ContextValue active_span_value = context::RuntimeContext::GetValue(kSpanKey); + ASSERT_TRUE(nostd::holds_alternative>(active_span_value)); + + auto active_span = nostd::get>(active_span_value); + ASSERT_EQ(active_span, span); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_benchmark.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_benchmark.cc new file mode 100644 index 000000000..3120eb0e5 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_benchmark.cc @@ -0,0 +1,129 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/context.h" +#include "opentelemetry/trace/noop.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_id.h" + +#include + +#include + +using opentelemetry::trace::SpanContext; +namespace trace_api = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace context = opentelemetry::context; + +namespace +{ + +std::shared_ptr initTracer() +{ + return std::shared_ptr(new trace_api::NoopTracer()); +} + +// Test to measure performance for span creation +void BM_SpanCreation(benchmark::State &state) +{ + auto tracer = initTracer(); + while (state.KeepRunning()) + { + auto span = tracer->StartSpan("span"); + span->End(); + } +} +BENCHMARK(BM_SpanCreation); + +// Test to measure performance for single span creation with scope +void BM_SpanCreationWithScope(benchmark::State &state) +{ + auto tracer = initTracer(); + while (state.KeepRunning()) + { + auto span = tracer->StartSpan("span"); + auto scope = tracer->WithActiveSpan(span); + span->End(); + } +} +BENCHMARK(BM_SpanCreationWithScope); + +// Test to measure performance for nested span creation with scope +void BM_NestedSpanCreationWithScope(benchmark::State &state) +{ + auto tracer = initTracer(); + while (state.KeepRunning()) + { + auto o_span = tracer->StartSpan("outer"); + auto o_scope = tracer->WithActiveSpan(o_span); + { + auto i_span = tracer->StartSpan("inner"); + auto i_scope = tracer->WithActiveSpan(i_span); + { + auto im_span = tracer->StartSpan("innermost"); + auto im_scope = tracer->WithActiveSpan(im_span); + im_span->End(); + } + i_span->End(); + } + o_span->End(); + } +} + +BENCHMARK(BM_NestedSpanCreationWithScope); + +// Test to measure performance for nested span creation with manual span context management +void BM_SpanCreationWithManualSpanContextPropagation(benchmark::State &state) +{ + auto tracer = initTracer(); + constexpr uint8_t buf1[] = {1, 2, 3, 4, 5, 6, 7, 8}; + trace_api::SpanId span_id(buf1); + constexpr uint8_t buf2[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; + trace_api::TraceId trace_id(buf2); + + while (state.KeepRunning()) + { + auto outer_span = nostd::shared_ptr( + new trace_api::DefaultSpan(SpanContext(trace_id, span_id, trace_api::TraceFlags(), false))); + trace_api::StartSpanOptions options; + options.parent = outer_span->GetContext(); + auto inner_span = tracer->StartSpan("inner", options); + auto inner_span_context = inner_span->GetContext(); + options.parent = inner_span_context; + auto innermost_span = tracer->StartSpan("innermost", options); + innermost_span->End(); + inner_span->End(); + } +} +BENCHMARK(BM_SpanCreationWithManualSpanContextPropagation); + +// Test to measure performance for nested span creation with context propagation +void BM_SpanCreationWitContextPropagation(benchmark::State &state) +{ + auto tracer = initTracer(); + constexpr uint8_t buf1[] = {1, 2, 3, 4, 5, 6, 7, 8}; + trace_api::SpanId span_id(buf1); + constexpr uint8_t buf2[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; + trace_api::TraceId trace_id(buf2); + + while (state.KeepRunning()) + { + auto current_ctx = context::RuntimeContext::GetCurrent(); + auto outer_span_context = SpanContext(trace_id, span_id, trace_api::TraceFlags(), false); + auto outer_span = + nostd::shared_ptr(new trace_api::DefaultSpan(outer_span_context)); + trace_api::SetSpan(current_ctx, outer_span); + auto inner_child = tracer->StartSpan("inner"); + auto inner_scope = tracer->WithActiveSpan(inner_child); + { + auto innermost_child = tracer->StartSpan("innermost"); + auto innermost_scope = tracer->WithActiveSpan(innermost_child); + innermost_child->End(); + } + inner_child->End(); + } +} +BENCHMARK(BM_SpanCreationWitContextPropagation); +} // namespace +BENCHMARK_MAIN(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_context_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_context_test.cc new file mode 100644 index 000000000..a3fd9a84a --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_context_test.cc @@ -0,0 +1,55 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/span_context.h" +#include "opentelemetry/trace/span_id.h" +#include "opentelemetry/trace/trace_id.h" + +#include + +using opentelemetry::trace::SpanContext; +namespace trace_api = opentelemetry::trace; + +TEST(SpanContextTest, IsSampled) +{ + SpanContext s1(true, true); + + ASSERT_EQ(s1.IsSampled(), true); + + SpanContext s2(false, true); + + ASSERT_EQ(s2.IsSampled(), false); +} + +TEST(SpanContextTest, IsRemote) +{ + SpanContext s1(true, true); + + ASSERT_EQ(s1.IsRemote(), true); + + SpanContext s2(true, false); + + ASSERT_EQ(s2.IsRemote(), false); +} + +TEST(SpanContextTest, TraceFlags) +{ + SpanContext s1(true, true); + + ASSERT_EQ(s1.trace_flags().flags(), 1); + + SpanContext s2(false, true); + + ASSERT_EQ(s2.trace_flags().flags(), 0); +} + +// Test that SpanContext is invalid +TEST(SpanContextTest, Invalid) +{ + SpanContext s1 = SpanContext::GetInvalid(); + EXPECT_FALSE(s1.IsValid()); + + // Test that trace id and span id are invalid + EXPECT_EQ(s1.trace_id(), trace_api::TraceId()); + EXPECT_EQ(s1.span_id(), trace_api::SpanId()); +} diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_id_benchmark.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_id_benchmark.cc new file mode 100644 index 000000000..42d4aeb46 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_id_benchmark.cc @@ -0,0 +1,55 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/span_id.h" + +#include +#include + +namespace +{ +using opentelemetry::trace::SpanId; +constexpr uint8_t bytes[] = {1, 2, 3, 4, 5, 6, 7, 8}; + +void BM_SpanIdDefaultConstructor(benchmark::State &state) +{ + while (state.KeepRunning()) + { + benchmark::DoNotOptimize(SpanId()); + } +} +BENCHMARK(BM_SpanIdDefaultConstructor); + +void BM_SpanIdConstructor(benchmark::State &state) +{ + while (state.KeepRunning()) + { + benchmark::DoNotOptimize(SpanId(bytes)); + } +} +BENCHMARK(BM_SpanIdConstructor); + +void BM_SpanIdToLowerBase16(benchmark::State &state) +{ + SpanId id(bytes); + char buf[SpanId::kSize * 2]; + while (state.KeepRunning()) + { + id.ToLowerBase16(buf); + benchmark::DoNotOptimize(buf); + } +} +BENCHMARK(BM_SpanIdToLowerBase16); + +void BM_SpanIdIsValid(benchmark::State &state) +{ + SpanId id(bytes); + while (state.KeepRunning()) + { + benchmark::DoNotOptimize(id.IsValid()); + } +} +BENCHMARK(BM_SpanIdIsValid); + +} // namespace +BENCHMARK_MAIN(); diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_id_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_id_test.cc new file mode 100644 index 000000000..52bb9b7de --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/span_id_test.cc @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/span_id.h" + +#include +#include + +#include + +namespace +{ + +using opentelemetry::trace::SpanId; + +std::string Hex(const opentelemetry::trace::SpanId &span) +{ + char buf[16]; + span.ToLowerBase16(buf); + return std::string(buf, sizeof(buf)); +} + +TEST(SpanIdTest, DefaultConstruction) +{ + SpanId id; + EXPECT_FALSE(id.IsValid()); + EXPECT_EQ("0000000000000000", Hex(id)); +} + +TEST(SpanIdTest, ValidId) +{ + constexpr uint8_t buf[] = {1, 2, 3, 4, 5, 6, 7, 8}; + SpanId id(buf); + EXPECT_TRUE(id.IsValid()); + EXPECT_EQ("0102030405060708", Hex(id)); + EXPECT_NE(SpanId(), id); + EXPECT_EQ(SpanId(buf), id); +} + +TEST(SpanIdTest, LowercaseBase16) +{ + constexpr uint8_t buf[] = {1, 2, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + SpanId id(buf); + EXPECT_TRUE(id.IsValid()); + EXPECT_EQ("0102aabbccddeeff", Hex(id)); + EXPECT_NE(SpanId(), id); + EXPECT_EQ(SpanId(buf), id); +} + +TEST(SpanIdTest, CopyBytesTo) +{ + constexpr uint8_t src[] = {1, 2, 3, 4, 5, 6, 7, 8}; + SpanId id(src); + uint8_t buf[8]; + id.CopyBytesTo(buf); + EXPECT_TRUE(memcmp(src, buf, 8) == 0); +} +} // namespace diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_flags_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_flags_test.cc new file mode 100644 index 000000000..783b56d83 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_flags_test.cc @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/trace_flags.h" + +#include +#include + +#include + +namespace +{ + +using opentelemetry::trace::TraceFlags; + +std::string Hex(const TraceFlags &flags) +{ + char buf[2]; + flags.ToLowerBase16(buf); + return std::string(buf, sizeof(buf)); +} + +TEST(TraceFlagsTest, DefaultConstruction) +{ + TraceFlags flags; + EXPECT_FALSE(flags.IsSampled()); + EXPECT_EQ(0, flags.flags()); + EXPECT_EQ("00", Hex(flags)); +} + +TEST(TraceFlagsTest, Sampled) +{ + TraceFlags flags{TraceFlags::kIsSampled}; + EXPECT_TRUE(flags.IsSampled()); + EXPECT_EQ(1, flags.flags()); + EXPECT_EQ("01", Hex(flags)); + + uint8_t buf[1]; + flags.CopyBytesTo(buf); + EXPECT_EQ(1, buf[0]); +} + +} // namespace diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_id_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_id_test.cc new file mode 100644 index 000000000..f903bfe9e --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_id_test.cc @@ -0,0 +1,58 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/trace_id.h" + +#include +#include + +#include + +namespace +{ + +using opentelemetry::trace::TraceId; + +std::string Hex(const opentelemetry::trace::TraceId &trace) +{ + char buf[32]; + trace.ToLowerBase16(buf); + return std::string(buf, sizeof(buf)); +} + +TEST(TraceIdTest, DefaultConstruction) +{ + TraceId id; + EXPECT_FALSE(id.IsValid()); + EXPECT_EQ("00000000000000000000000000000000", Hex(id)); +} + +TEST(TraceIdTest, ValidId) +{ + constexpr uint8_t buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; + TraceId id(buf); + EXPECT_TRUE(id.IsValid()); + EXPECT_EQ("01020304050607080807060504030201", Hex(id)); + EXPECT_NE(TraceId(), id); + EXPECT_EQ(TraceId(buf), id); +} + +TEST(TraceIdTest, LowercaseBase16) +{ + constexpr uint8_t buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + TraceId id(buf); + EXPECT_TRUE(id.IsValid()); + EXPECT_EQ("01020304050607080807aabbccddeeff", Hex(id)); + EXPECT_NE(TraceId(), id); + EXPECT_EQ(TraceId(buf), id); +} + +TEST(TraceIdTest, CopyBytesTo) +{ + constexpr uint8_t src[] = {1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}; + TraceId id(src); + uint8_t buf[TraceId::kSize]; + id.CopyBytesTo(buf); + EXPECT_TRUE(memcmp(src, buf, sizeof(buf)) == 0); +} +} // namespace diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_state_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_state_test.cc new file mode 100644 index 000000000..ed6c7e827 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/trace_state_test.cc @@ -0,0 +1,196 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/trace/trace_state.h" + +#include +#include "opentelemetry/nostd/string_view.h" + +namespace +{ + +using opentelemetry::trace::TraceState; +namespace nostd = opentelemetry::nostd; + +// Random string of length 257. Used for testing strings with max length 256. +const char *kLongString = + "4aekid3he76zgytjavudqqeltyvu5zqio2lx7d92dlxlf0z4883irvxuwelsq27sx1mlrjg3r7ad3jeq09rjppyd9veorg" + "2nmihy4vilabfts8bsxruih0urusmjnglzl3iwpjinmo835dbojcrd73p56nw80v4xxrkye59ytmu5v84ysfa24d58ovv9" + "w1n54n0mhhf4z0mpv6oudywrp9vfoks6lrvxv3uihvbi2ihazf237kvt1nbsjn3kdvfdb"; + +// -------------------------- TraceState class tests --------------------------- + +std::string create_ts_return_header(std::string header) +{ + auto ts = TraceState::FromHeader(header); + return ts->ToHeader(); +} + +std::string header_with_max_members() +{ + std::string header = ""; + auto max_members = TraceState::kMaxKeyValuePairs; + for (int i = 0; i < max_members; i++) + { + std::string key = "key" + std::to_string(i); + std::string value = "value" + std::to_string(i); + header += key + "=" + value; + if (i != max_members - 1) + { + header += ","; + } + } + return header; +} + +TEST(TraceStateTest, ValidateHeaderParsing) +{ + auto max_trace_state_header = header_with_max_members(); + + struct + { + const char *input; + const char *expected; + } testcases[] = {{"k1=v1", "k1=v1"}, + {"K1=V1", ""}, + {"k1=v1,k2=v2,k3=v3", "k1=v1,k2=v2,k3=v3"}, + {"k1=v1,k2=v2,,", "k1=v1,k2=v2"}, + {"k1=v1,k2=v2,invalidmember", ""}, + {"1a-2f@foo=bar1,a*/foo-_/bar=bar4", "1a-2f@foo=bar1,a*/foo-_/bar=bar4"}, + {"1a-2f@foo=bar1,*/foo-_/bar=bar4", ""}, + {",k1=v1", "k1=v1"}, + {",", ""}, + {",=,", ""}, + {"", ""}, + {max_trace_state_header.data(), max_trace_state_header.data()}}; + for (auto &testcase : testcases) + { + EXPECT_EQ(create_ts_return_header(testcase.input), testcase.expected); + } +} + +TEST(TraceStateTest, TraceStateGet) +{ + + std::string trace_state_header = header_with_max_members(); + auto ts = TraceState::FromHeader(trace_state_header); + + std::string value; + EXPECT_TRUE(ts->Get("key0", value)); + EXPECT_EQ(value, "value0"); + EXPECT_TRUE(ts->Get("key16", value)); + EXPECT_EQ(value, "value16"); + EXPECT_TRUE(ts->Get("key31", value)); + EXPECT_EQ(value, "value31"); + EXPECT_FALSE(ts->Get("key32", value)); +} + +TEST(TraceStateTest, TraceStateSet) +{ + std::string trace_state_header = "k1=v1,k2=v2"; + auto ts1 = TraceState::FromHeader(trace_state_header); + auto ts1_new = ts1->Set("k3", "v3"); + EXPECT_EQ(ts1_new->ToHeader(), "k3=v3,k1=v1,k2=v2"); + + trace_state_header = header_with_max_members(); + auto ts2 = TraceState::FromHeader(trace_state_header); + auto ts2_new = + ts2->Set("n_k1", "n_v1"); // adding to max list, should return copy of existing list + EXPECT_EQ(ts2_new->ToHeader(), trace_state_header); + + trace_state_header = "k1=v1,k2=v2"; + auto ts3 = TraceState::FromHeader(trace_state_header); + auto ts3_new = ts3->Set("*n_k1", "n_v1"); // adding invalid key, should return empty + EXPECT_EQ(ts3_new->ToHeader(), ""); +} + +TEST(TraceStateTest, TraceStateDelete) +{ + std::string trace_state_header = "k1=v1,k2=v2,k3=v3"; + auto ts1 = TraceState::FromHeader(trace_state_header); + auto ts1_new = ts1->Delete(std::string("k1")); + EXPECT_EQ(ts1_new->ToHeader(), "k2=v2,k3=v3"); + + trace_state_header = "k1=v1"; // single list member + auto ts2 = TraceState::FromHeader(trace_state_header); + auto ts2_new = ts2->Delete(std::string("k1")); + EXPECT_EQ(ts2_new->ToHeader(), ""); + + trace_state_header = "k1=v1"; // single list member, delete invalid entry + auto ts3 = TraceState::FromHeader(trace_state_header); + auto ts3_new = ts3->Delete(std::string("InvalidKey")); + EXPECT_EQ(ts3_new->ToHeader(), ""); +} + +TEST(TraceStateTest, Empty) +{ + std::string trace_state_header = ""; + auto ts = TraceState::FromHeader(trace_state_header); + EXPECT_TRUE(ts->Empty()); + + trace_state_header = "k1=v1,k2=v2"; + auto ts1 = TraceState::FromHeader(trace_state_header); + EXPECT_FALSE(ts1->Empty()); +} + +TEST(TraceStateTest, GetAllEntries) +{ + std::string trace_state_header = "k1=v1,k2=v2,k3=v3"; + auto ts1 = TraceState::FromHeader(trace_state_header); + const int kNumPairs = 3; + nostd::string_view keys[kNumPairs] = {"k1", "k2", "k3"}; + nostd::string_view values[kNumPairs] = {"v1", "v2", "v3"}; + size_t index = 0; + ts1->GetAllEntries([&keys, &values, &index](nostd::string_view key, nostd::string_view value) { + EXPECT_EQ(key, keys[index]); + EXPECT_EQ(value, values[index]); + index++; + return true; + }); +} + +TEST(TraceStateTest, IsValidKey) +{ + EXPECT_TRUE(TraceState::IsValidKey("valid-key23/*")); + EXPECT_FALSE(TraceState::IsValidKey("Invalid_key")); + EXPECT_FALSE(TraceState::IsValidKey("invalid$Key&")); + EXPECT_FALSE(TraceState::IsValidKey("")); + EXPECT_FALSE(TraceState::IsValidKey(kLongString)); +} + +TEST(TraceStateTest, IsValidValue) +{ + EXPECT_TRUE(TraceState::IsValidValue("valid-val$%&~")); + EXPECT_FALSE(TraceState::IsValidValue("\tinvalid")); + EXPECT_FALSE(TraceState::IsValidValue("invalid=")); + EXPECT_FALSE(TraceState::IsValidValue("invalid,val")); + EXPECT_FALSE(TraceState::IsValidValue("")); + EXPECT_FALSE(TraceState::IsValidValue(kLongString)); +} + +// Tests that keys and values don't depend on null terminators +TEST(TraceStateTest, MemorySafe) +{ + std::string trace_state_header = ""; + auto ts = TraceState::FromHeader(trace_state_header); + const int kNumPairs = 3; + nostd::string_view key_string = "test_key_1test_key_2test_key_3"; + nostd::string_view val_string = "test_val_1test_val_2test_val_3"; + nostd::string_view keys[kNumPairs] = {key_string.substr(0, 10), key_string.substr(10, 10), + key_string.substr(20, 10)}; + nostd::string_view values[kNumPairs] = {val_string.substr(0, 10), val_string.substr(10, 10), + val_string.substr(20, 10)}; + + auto ts1 = ts->Set(keys[2], values[2]); + auto ts2 = ts1->Set(keys[1], values[1]); + auto ts3 = ts2->Set(keys[0], values[0]); + size_t index = 0; + + ts3->GetAllEntries([&keys, &values, &index](nostd::string_view key, nostd::string_view value) { + EXPECT_EQ(key, keys[index]); + EXPECT_EQ(value, values[index]); + index++; + return true; + }); +} +} // namespace diff --git a/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/tracer_test.cc b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/tracer_test.cc new file mode 100644 index 000000000..8e16f15e2 --- /dev/null +++ b/extra/otel/opentelemetry-cpp-1.10.0/api/test/trace/tracer_test.cc @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/noop.h" +#include "opentelemetry/trace/scope.h" + +#include + +namespace trace_api = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace context = opentelemetry::context; + +TEST(TracerTest, GetCurrentSpan) +{ + std::unique_ptr tracer(new trace_api::NoopTracer()); + nostd::shared_ptr span_first(new trace_api::NoopSpan(nullptr)); + nostd::shared_ptr span_second(new trace_api::NoopSpan(nullptr)); + + auto current = tracer->GetCurrentSpan(); + ASSERT_FALSE(current->GetContext().IsValid()); + + { + auto scope_first = tracer->WithActiveSpan(span_first); + current = tracer->GetCurrentSpan(); + ASSERT_EQ(current, span_first); + + { + auto scope_second = tracer->WithActiveSpan(span_second); + current = tracer->GetCurrentSpan(); + ASSERT_EQ(current, span_second); + } + current = tracer->GetCurrentSpan(); + ASSERT_EQ(current, span_first); + } + + current = tracer->GetCurrentSpan(); + ASSERT_FALSE(current->GetContext().IsValid()); +} diff --git a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/baggage_context.h b/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/baggage_context.h deleted file mode 100644 index 9a92bac77..000000000 --- a/extra/otel/opentelemetry-cpp-1.8.3/api/include/opentelemetry/baggage/baggage_context.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include "opentelemetry/baggage/baggage.h" -#include "opentelemetry/context/context.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/version.h" - -OPENTELEMETRY_BEGIN_NAMESPACE - -namespace baggage -{ - -static const std::string kBaggageHeader = "baggage"; - -inline nostd::shared_ptr GetBaggage( - const opentelemetry::context::Context &context) noexcept -{ - context::ContextValue context_value = context.GetValue(kBaggageHeader); - if (nostd::holds_alternative>(context_value)) - { - return nostd::get>(context_value); - } - static nostd::shared_ptr empty_baggage{ - new opentelemetry::baggage::Baggage()}; - return empty_baggage; -} - -inline context::Context SetBaggage( - opentelemetry::context::Context &context, - nostd::shared_ptr baggage) noexcept -{ - return context.SetValue(kBaggageHeader, baggage); -} - -} // namespace baggage -OPENTELEMETRY_END_NAMESPACE diff --git a/installer/CMakeLists.txt b/installer/CMakeLists.txt index 72ee582b8..14fcb0145 100644 --- a/installer/CMakeLists.txt +++ b/installer/CMakeLists.txt @@ -37,6 +37,11 @@ ENDIF(DL_INCLUDES) ADD_EXECUTABLE(myodbc-installer myodbc-installer.cc) +add_version_info(myodbc-installer + "MySQL Connector/ODBC installer tool." + "Provides installer tool functionality." +) + TARGET_LINK_LIBRARIES(myodbc-installer otel_api) IF(WIN32) diff --git a/setupgui/CMakeLists.txt b/setupgui/CMakeLists.txt index 80aa827b8..0a41e82b1 100644 --- a/setupgui/CMakeLists.txt +++ b/setupgui/CMakeLists.txt @@ -97,7 +97,12 @@ add_compile_options(${PLATFORM_CFLAGS}) add_library(awsmysqlodbcS SHARED ${SETUP_SRCS}) -target_link_libraries(awsmysqlodbcS ${ODBCLIB} ${ODBCINSTLIB}) +add_version_info(awsmysqlodbcS + "AWS ODBC Driver for MySQL setup library." + "Provides driver configuration GUI." +) + +target_link_libraries(awsmysqlodbcS ${ODBCLIB} ${ODBCINSTLIB} otel_api) # Note: When using GTK+, these libraries will be linked to -gtk modules. diff --git a/setupgui/windows/odbcdialogparams.rc b/setupgui/windows/odbcdialogparams.rc index 174d07200..2cde77abd 100644 --- a/setupgui/windows/odbcdialogparams.rc +++ b/setupgui/windows/odbcdialogparams.rc @@ -52,44 +52,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 -#include "..\..\VersionInfo.h" -#include -VS_VERSION_INFO VERSIONINFO -FILEVERSION MYODBC_FILEVER -PRODUCTVERSION MYODBC_PRODUCTVER -FILEFLAGSMASK 0x3L -#ifdef _DEBUG - FILEFLAGS 0x29L -#else - FILEFLAGS 0x28L -#endif - FILEOS 0x40004L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "Comments", "provides setup library functionality\0" - VALUE "CompanyName", "Amazon.com Inc. or affiliates.\0" - VALUE "FileDescription", "AWS ODBC Driver for MySQL Setup Library\0" - VALUE "FileVersion", MYODBC_STRFILEVER - VALUE "InternalName", "awsmysqlodbcS\0" - VALUE "LegalCopyright", "Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright (c) 1995, 2018, Oracle and/or its affiliates.\0" - VALUE "LegalTrademarks", "MySQL, MyODBC, Connector/ODBC are trademarks of Oracle Corporation\0" - VALUE "OriginalFilename", "awsmysqlodbcS.dll\0" - VALUE "PrivateBuild", "Production\0" - VALUE "ProductName", "Connector/ODBC 8.2\0" - VALUE "ProductVersion", MYODBC_STRPRODUCTVER - VALUE "SpecialBuild", "GA release\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END ///////////////////////////////////////////////////////////////////////////// // diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b897af79b..ee2bc4274 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -63,6 +63,11 @@ FOREACH(FN my_basics.c my_blob.c my_bulk.c my_catalog1.c my_catalog2.c ADD_EXECUTABLE(${T} ${FN}) ENDIF(WIN32) + add_version_info(${T} + "MySQL Connector/ODBC unit test." + "Tests the driver functionality." + ) + add_dependencies(${T} generate_test_config_files) set_target_properties(${T} PROPERTIES FOLDER Tests) @@ -130,6 +135,11 @@ IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ADD_EXECUTABLE(${T} ${T}.c) ENDIF(WIN32) + add_version_info(${T} + "MySQL Connector/ODBC unit test." + "Tests the driver functionality." + ) + IF(MYSQL_CXX_LINKAGE) SET_TARGET_PROPERTIES(${T} PROPERTIES LINKER_LANGUAGE CXX diff --git a/test/my_auth.cc b/test/my_auth.cc index a9cea88e7..7ad64d56f 100644 --- a/test/my_auth.cc +++ b/test/my_auth.cc @@ -650,37 +650,37 @@ DECLARE_TEST(t_dummy_test) /** - * Testing FIDO connection + * Testing Webauthn connection * * The test is designed for manual run. * It requires the following preparation steps: * - * 1. Install FIDO auth plugin on the server: - * INSTALL PLUGIN authentication_fido SONAME 'authentication_fido.so' + * 1. Install Webauthn auth plugin on the server: + * INSTALL PLUGIN authentication_fido SONAME 'authentication_webauthn.so' * * 2. Create user with FIDO authentication: - * CREATE USER 'u2'@'localhost' IDENTIFIED WITH caching_sha2_password - * BY 'sha2_password' AND IDENTIFIED WITH authentication_fido + * CREATE USER 'uwebauthn'@'localhost' IDENTIFIED WITH caching_sha2_password + * BY 'sha2_password' AND IDENTIFIED WITH authentication_webauthn * * 3. Register FIDO: - * mysql --port=13000 --protocol=tcp --user=u2 --password1 + * mysql --port=13000 --protocol=tcp --user=uwebauthn --password1 * --fido-register-factor=2 * - * 4. Set env variable MYSQL_FIDO to non-empty value + * 4. Set env variable MYSQL_WEBAUTHN to non-empty value */ -DECLARE_TEST(t_fido_test) +DECLARE_TEST(t_webauthn_test) { DECLARE_BASIC_HANDLES(henv1, hdbc1, hstmt1); - if (!getenv("MYSQL_FIDO")) + if (!getenv("MYSQL_WEBAUTHN")) { SKIP_REASON = "This test needs to be run manually. " - "Set MYSQL_FIDO environment variable to enable running this test"; + "Set MYSQL_WEBAUTHN environment variable to enable running this test"; return SKIP; } is(OK == alloc_basic_handles_with_opt(&henv1, &hdbc1, &hstmt1, NULL, - (SQLCHAR*)"u3", (SQLCHAR*)"sha2_password", + (SQLCHAR*)"uwebauthn", (SQLCHAR*)"sha2_password", NULL, (SQLCHAR*)"DATABASE=;")); free_basic_handles(&henv1, &hdbc1, &hstmt1); @@ -708,20 +708,18 @@ int fido_var2[] = { FIDO_VAL_DEFAULT, DECLARE_TEST(t_fido_callback_test) { - if (!getenv("MYSQL_FIDO")) + if (!getenv("MYSQL_WEBAUTHN")) { SKIP_REASON = "This test needs to be run manually. " - "Set MYSQL_FIDO environment variable to enable running this test"; + "Set MYSQL_WEBAUTHN environment variable to enable running this test"; return SKIP; } SQLHDBC hdbc1 = NULL, hdbc2 = NULL; - std::vector connstrs = { + std::string str_connstr = (char*)make_conn_str(NULL, (SQLCHAR*)"uwebauthn", (SQLCHAR*)"sha2_password", - NULL, (SQLCHAR*)"DATABASE=;", 0), - (char*)make_conn_str(NULL, (SQLCHAR*)"ufido", (SQLCHAR*)"sha2_password", - NULL, (SQLCHAR*)"DATABASE=;", 0), - }; + NULL, (SQLCHAR*)"DATABASE=;", 0); + fido_var = FIDO_VAL_DEFAULT; // We cannot use the C++ random distribution because @@ -735,22 +733,19 @@ DECLARE_TEST(t_fido_callback_test) * for connection and CB_FIDO_NOFUNC for not setting any callback) and * check if after connection `fido_var` equals `result`. */ - auto fido_test_check = [henv, connstrs](int attr_type, void (*callback_func)(const char*), int result) - { - // Get a random string. - std::string s = connstrs[std::rand() % 2]; - { - SQLHDBC hdbc = NULL; - SQLCHAR *connstr = (SQLCHAR*)s.c_str(); - ok_env(henv, SQLAllocConnect(henv, &hdbc)); - if (attr_type != CB_FIDO_NOFUNC) - ok_con(hdbc, SQLSetConnectAttr(hdbc, attr_type, (void*)callback_func, SQL_IS_POINTER)); - fido_var = FIDO_VAL_DEFAULT; - SQLDriverConnect(hdbc, NULL, connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); - SQLDisconnect(hdbc); - SQLFreeHandle(SQL_HANDLE_DBC, hdbc); - is_num(result, fido_var); - } + auto fido_test_check = [henv, str_connstr](int attr_type, void (*callback_func)(const char*), int result) + { + SQLHDBC hdbc = NULL; + SQLCHAR *connstr = (SQLCHAR*)str_connstr.c_str(); + ok_env(henv, SQLAllocConnect(henv, &hdbc)); + if (attr_type != CB_FIDO_NOFUNC) + ok_con(hdbc, SQLSetConnectAttr(hdbc, attr_type, (void*)callback_func, SQL_IS_POINTER)); + fido_var = FIDO_VAL_DEFAULT; + ok_con(hdbc, SQLDriverConnect(hdbc, NULL, connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT)); + SQLDisconnect(hdbc); + SQLFreeHandle(SQL_HANDLE_DBC, hdbc); + is_num(result, fido_var); + return SQL_SUCCESS; }; @@ -833,53 +828,45 @@ DECLARE_TEST(t_fido_callback_test) * callback was called. * For global callbacks there should be a check that a callback was set at all. */ - auto fido_thr_global_check = [henv, connstrs, fido_func_global]() + auto fido_thr_global_check = [henv, str_connstr, fido_func_global]() { auto ptr = (void (*)(const char*))fido_func_global; - // Get a random string. - std::string s = connstrs[std::rand() % 2]; + SQLCHAR *connstr = (SQLCHAR*)str_connstr.c_str(); + fido_var = FIDO_VAL_DEFAULT; + for (int i = 0; i < 3; ++i) { - SQLCHAR *connstr = (SQLCHAR*)s.c_str(); - fido_var = FIDO_VAL_DEFAULT; - for (int i = 0; i < 3; ++i) - { - SQLHDBC hdbc = NULL; - ok_env(henv, SQLAllocConnect(henv, &hdbc)); - ok_con(hdbc, SQLSetConnectAttr(hdbc, CB_FIDO_GLOBAL, - (void*)(ptr), SQL_IS_POINTER)); + SQLHDBC hdbc = NULL; + ok_env(henv, SQLAllocConnect(henv, &hdbc)); + ok_con(hdbc, SQLSetConnectAttr(hdbc, CB_FIDO_GLOBAL, + (void*)(ptr), SQL_IS_POINTER)); - SQLDriverConnect(hdbc, NULL, (SQLCHAR*)connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); - SQLDisconnect(hdbc); - SQLFreeHandle(SQL_HANDLE_DBC, hdbc); + SQLDriverConnect(hdbc, NULL, (SQLCHAR*)connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); + SQLDisconnect(hdbc); + SQLFreeHandle(SQL_HANDLE_DBC, hdbc); - is(fido_var != FIDO_VAL_DEFAULT); - } + is(fido_var != FIDO_VAL_DEFAULT); } return SQL_SUCCESS; }; - auto fido_thr_conn_check = [henv, connstrs]( + auto fido_thr_conn_check = [henv, str_connstr]( void (*callback_func)(const char*), int idx) { - // Get a random string. - std::string s = connstrs[std::rand() % 2]; + SQLCHAR* connstr = (SQLCHAR*)str_connstr.c_str(); + for (int i = 0; i < 3; ++i) { - SQLCHAR* connstr = (SQLCHAR*)s.c_str(); - for (int i = 0; i < 3; ++i) - { - SQLHDBC hdbc = NULL; - ok_env(henv, SQLAllocConnect(henv, &hdbc)); - ok_con(hdbc, SQLSetConnectAttr(hdbc, CB_FIDO_CONNECTION, - (void *)(callback_func), SQL_IS_POINTER)); - fido_var2[idx] = FIDO_VAL_DEFAULT; - - SQLDriverConnect(hdbc, NULL, (SQLCHAR*)connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); - SQLDisconnect(hdbc); - SQLFreeHandle(SQL_HANDLE_DBC, hdbc); - int expected_val = idx + 1; - is_num(expected_val, fido_var2[idx]); - } + SQLHDBC hdbc = NULL; + ok_env(henv, SQLAllocConnect(henv, &hdbc)); + ok_con(hdbc, SQLSetConnectAttr(hdbc, CB_FIDO_CONNECTION, + (void *)(callback_func), SQL_IS_POINTER)); + fido_var2[idx] = FIDO_VAL_DEFAULT; + + SQLDriverConnect(hdbc, NULL, (SQLCHAR*)connstr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); + SQLDisconnect(hdbc); + SQLFreeHandle(SQL_HANDLE_DBC, hdbc); + int expected_val = idx + 1; + is_num(expected_val, fido_var2[idx]); } return SQL_SUCCESS; }; @@ -948,7 +935,7 @@ BEGIN_TESTS ADD_TEST(t_kerberos_mode) #endif ADD_TEST(t_fido_callback_test) - ADD_TEST(t_fido_test) + ADD_TEST(t_webauthn_test) // ADD_TEST(t_plugin_auth) TODO: Fix ADD_TEST(t_dummy_test) ADD_TEST(t_ldap_auth) diff --git a/test/my_crash.c b/test/my_crash.c index 1f075d136..8ddfd8245 100644 --- a/test/my_crash.c +++ b/test/my_crash.c @@ -866,8 +866,11 @@ DECLARE_TEST(t_bug18286118) sprintf((char*)tmpBuff, "DROP TABLE IF EXISTS %s,%s CASCADE", tabname2,tabname1); ok_stmt(hstmt1, SQLExecDirect(hstmt1, (SQLCHAR*)tmpBuff, SQL_NTS)); - sprintf((char*)tmpBuff, "CREATE TABLE %s (id int, %s bigint, primary key(%s,id)) "\ - "COMMENT \" Comment1 \"", tabname1, colname1, colname1); + sprintf(tmpBuff, + "CREATE TABLE %s (id int, %s bigint unique, primary key(%s,id))" + " COMMENT \" Comment1 \"", + tabname1, colname1, colname1 + ); ok_stmt(hstmt1, SQLExecDirect(hstmt1, (SQLCHAR*)tmpBuff, SQL_NTS)); sprintf((char*)tmpBuff, "CREATE TABLE %s (id int, `%s` bigint, bd1 double, "\ diff --git a/test/my_data.cc b/test/my_data.cc index 390eb8f45..68f4037e3 100644 --- a/test/my_data.cc +++ b/test/my_data.cc @@ -956,7 +956,59 @@ DECLARE_TEST(t_bug35520983_sjis) { ENDCATCH; } +/* + Bug #26474471/61991 - SQLGetData return shorter than expected + string when multiple rows are fetched. + + NOTE: The issue happens with multiple rows fetch when the fetch + positions change. +*/ +DECLARE_TEST(t_bug26474471) +{ + try { + odbc::connection conn; + SQLHSTMT hstmt = conn.hstmt; + odbc::table tab(hstmt, "t_bug26474471", "names VARCHAR(32)"); + odbc::xstring data[] = {"02 Str 0123456789ABCDEF", "01 Str 0123456789"}; + + for(auto &d : data) + tab.insert("('" + d + "')"); + + odbc::sql(hstmt, "SELECT * FROM " + tab.table_name + " ORDER BY names DESC"); + + SQLULEN rows_fetched = 0; + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_ROWS_FETCHED_PTR, + &rows_fetched, 0)); + + ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, + (SQLPOINTER)100, 0)); + + ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0)); + // Two rows should be fetched at this point. + is_num(2, rows_fetched); + + // To ensure correctness of SQLGetData() the row positions + // will increase and decrease over iterations. + int row_positions[] = {1, 2, 1}; + SQLLEN len = 0; + odbc::xbuf buf(65536); + + // Check that setting the position changes the data and the length + for (auto pos : row_positions) { + ok_stmt(hstmt, SQLSetPos(hstmt, pos, SQL_POSITION, SQL_LOCK_NO_CHANGE)); + + ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, buf, buf.size, &len)); + + is_num(data[pos - 1].length(), (size_t)len); + is_str((const char *)data[pos - 1], (const char*)buf, len); + } + + } + ENDCATCH; +} + BEGIN_TESTS + ADD_TEST(t_bug26474471) ADD_TEST(t_bug35520983_sjis) ADD_TEST(t_utf8mb4_param) ADD_TEST(t_bug_34350417_performance) diff --git a/test/my_param.c b/test/my_param.c index 3903ea4a4..d6cae832f 100644 --- a/test/my_param.c +++ b/test/my_param.c @@ -2392,8 +2392,181 @@ DECLARE_TEST(t_wl14217) return OK; } +DECLARE_TEST(t_wl15967) +{ + SQLINTEGER p_param = 40, p1_int = 50; + char *p2_char = "char attribute"; + SQLHANDLE ipd = NULL; + char query[1024]; + const char* names[] = { + "my_attr_name1", "my_attr_name2", "my_attr_name3", "no_value" + }; + + int p_select = 1; + SQLINTEGER v_param = 0, v_select = 0; + SQLUINTEGER v1_int = 0; + SQLLEN len1 = 0, len2 = 0, len3 = 0, len4 = 0; + + TIMESTAMP_STRUCT p3_ts; + /* insert using SQL_C_TIMESTAMP to SQL_TIMESTAMP */ + p3_ts.year = 2020; + p3_ts.month = 12; + p3_ts.day = 21; + p3_ts.hour = 15; + p3_ts.minute = 34; + p3_ts.second = 59; + p3_ts.fraction = 0; + + /* + If component is already installed the query will return error. + Ignoring the result. + */ + SQLExecDirect(hstmt, + "INSTALL COMPONENT \"file://component_query_attributes\"", + SQL_NTS); + + if (SQL_ERROR == SQLExecDirect(hstmt, + "SELECT mysql_query_attribute_string('abc')", SQL_NTS)) + { + skip("Query Attributes are not supported by current MySQL Server"); + } + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + // Real param + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, + SQL_INTEGER, 0, 0, &p_param, 0, NULL)); + + // Query Attribute value - int + ok_stmt(hstmt, SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, + SQL_INTEGER, 0, 0, &p1_int, 0, NULL)); + + // Query Attribute value - char string + ok_stmt(hstmt, SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, + SQL_CHAR, 0, 0, p2_char, (SQLLEN)strlen(p2_char), + NULL)); + + // Query Attribute value - datetime + ok_stmt(hstmt, SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, + SQL_C_TIMESTAMP, SQL_TIMESTAMP, + 0, 0, &p3_ts, (SQLLEN)sizeof(p3_ts), NULL)); + + + ok_stmt(hstmt, SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_DESC, &ipd, 0, 0)); + + for (int i = 0; i < 4; ++i) + { + ok_stmt(hstmt, SQLSetDescField(ipd, i + 2, + SQL_DESC_NAME, (SQLPOINTER)names[i], SQL_NTS)); + } + + while(p_select < 4) + { + v_select = 0; + SQLCHAR v2_char[32]; + TIMESTAMP_STRUCT v3_ts; + SQLCHAR v4_char[32]; + v1_int = 0; + len1 = 0; len2 = 0; len3 = 0; len4 = 0; + SQLLEN exp_len2 = strlen(p2_char); + SQLLEN exp_len3 = sizeof(v3_ts); + + memset(&v2_char, 0, sizeof(v2_char)); + memset(&v3_ts, 0, sizeof(v3_ts)); + memset(&v4_char, 0, sizeof(v4_char)); + + snprintf(query, sizeof(query), + "SELECT ?, %d, mysql_query_attribute_string('%s')," + "mysql_query_attribute_string('%s')," + "mysql_query_attribute_string('%s')," + "mysql_query_attribute_string('%s')" + , p_select, names[0], names[1], names[2], names[3]); + + printf("Running query, iteration number: %d\n", p_select); + + // On 3rd run we should reset STMT and remove statement attributes + if (p_select == 3) + { + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS)); + p1_int = 0; + p2_char = ""; + exp_len2 = -1; + memset(&p3_ts, 0, sizeof(p3_ts)); + exp_len3 = -1; + + // Have to re-bind the non-QA param or the whole query will fail. + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, + SQL_INTEGER, 0, 0, &p_param, 0, NULL)); + + } + + ok_stmt(hstmt, SQLExecDirect(hstmt, (SQLCHAR *)query, SQL_NTS)); + ok_stmt(hstmt, SQLFetch(hstmt)); + + is_num(p_param, my_fetch_int(hstmt, 1)); + is_num(p_select, my_fetch_int(hstmt, 2)); + is_num(p1_int, my_fetch_int(hstmt, 3)); + + ok_stmt(hstmt, SQLGetData(hstmt, 4, SQL_C_CHAR, &v2_char, sizeof(v2_char), &len2)); + is_num(exp_len2, len2); + is_str(p2_char, v2_char, strlen(p2_char)); + + ok_stmt(hstmt, SQLGetData(hstmt, 5, SQL_C_TIMESTAMP, &v3_ts, sizeof(v3_ts), &len3)); + is_num(exp_len3, len3); + is_num(0, memcmp(&p3_ts, &v3_ts, sizeof(p3_ts))); + + // Attribute with name only, but no data + ok_stmt(hstmt, SQLGetData(hstmt, 6, SQL_C_CHAR, &v4_char, sizeof(v4_char), &len4)); + is_num(-1, len4); + + expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + ++p_select; + } + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + // Bind just a parameter, no name + p1_int = 99; + len1 = 0; + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, + SQL_INTEGER, 0, 0, &p1_int, 0, NULL)); + + ok_stmt(hstmt, SQLExecDirect(hstmt, (SQLCHAR*)"SELECT 98, ?", SQL_NTS)); + ok_stmt(hstmt, SQLFetch(hstmt)); + + is_num(98, my_fetch_int(hstmt, 1)); + is_num(p1_int, my_fetch_int(hstmt, 2)); + expect_stmt(hstmt, SQLGetData(hstmt, 3, SQL_C_ULONG, &v1_int, 0, &len1), + SQL_ERROR); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS)); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + // Bind parameters with gaps + p1_int = 199; + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, + SQL_INTEGER, 0, 0, &p1_int, 0, NULL)); + + ok_stmt(hstmt, SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_LONG, + SQL_INTEGER, 0, 0, &p1_int, 0, NULL)); + + ok_stmt(hstmt, SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_DESC, &ipd, 0, 0)); + ok_stmt(hstmt, SQLSetDescField(ipd, 3, SQL_DESC_NAME, (SQLPOINTER)names[2], SQL_NTS)); + + expect_stmt(hstmt, SQLExecDirect(hstmt, (SQLCHAR*)query, SQL_NTS), + SQL_ERROR); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_RESET_PARAMS)); + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + return OK; +} + BEGIN_TESTS + ADD_TEST(t_wl15967) ADD_TEST(t_odbcoutparams) ADD_TEST(t_bug14501952) ADD_TEST(t_bug14563386) diff --git a/test/my_param2.cc b/test/my_param2.cc index 7cd1fb6a8..3fcd2089e 100644 --- a/test/my_param2.cc +++ b/test/my_param2.cc @@ -357,9 +357,69 @@ void sig_handler(int sig) { } #endif +/* + Bug #35790175: Cannot run parameterized stored procedure + using My SQL ODBC 8.1 connector +*/ +DECLARE_TEST(t_bug35790175_ado_call) +{ + for (int no_ssps = 0; no_ssps < 2; ++no_ssps) + try + { + // Try how preparing "{ call ... }" works with and without SSPS + odbc::xstring opts = ";NO_SSPS=" + odbc::xstring(no_ssps); + odbc::connection con(nullptr, nullptr, nullptr, nullptr, opts); + SQLHSTMT hstmt = con.hstmt; + odbc::procedure proc(hstmt, "proc_bug35790175", + "(IN p1 INT, IN p2 VARCHAR(32))" + "BEGIN " + " SELECT p1, p2; " + "END"); + + // The bug in ODBC driver caused the prepare call to fail. + odbc::stmt_prepare(hstmt, "{ CALL " + proc.proc_name + "(?,?) }"); + + SQLLEN len1 = 0, len2 = 0; // Param lengths + int p1 = 0; // Param 1 + odbc::xbuf p2(32); // Param 2 + odbc::xbuf r2(32); // Buffer for reading result + + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, + SQL_C_LONG, SQL_INTEGER, 0, 0, &p1, 0, &len1)); + ok_stmt(hstmt, SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, + SQL_C_CHAR, SQL_CHAR, 0, 0, p2, p2.size, &len2)); + + int i_vals[] = {100, 234}; + odbc::xstring s_vals[] = {"mysql string", "another string"}; + + for (int i = 0 ; i < 2; ++i) { + auto &s = s_vals[i]; + + len1 = 0; + len2 = s.length(); + p1 = i_vals[i]; + p2.setval(s.c_str()); + + odbc::stmt_execute(hstmt); + + ok_stmt(hstmt, SQLFetch(hstmt)); + is_num(i_vals[i], my_fetch_int(hstmt, 1)); + const char *col2 = my_fetch_str(hstmt, r2, 2); + is_str((char *)s_vals[i], (char *)col2, s.length()); + + // Only one row is expected. + is_no_data(SQLFetch(hstmt)); + odbc::stmt_close(hstmt); + } + } + ENDCATCH; +} + + BEGIN_TESTS // TODO: enable test when the problem is fixed // ADD_TEST(t_stmt_thread) + ADD_TEST(t_bug35790175_ado_call) ADD_TEST(t_bug30578291_inout_param) ADD_TEST(t_bug30578291_in_param) ADD_TEST(t_bug30578291_just_rows) diff --git a/test/my_result2.c b/test/my_result2.c index 9c52d8f5e..f42c3ff88 100644 --- a/test/my_result2.c +++ b/test/my_result2.c @@ -1106,7 +1106,7 @@ DECLARE_TEST(t_bookmark) { SQLLEN len= 0; SQLINTEGER abookmark[4]; - SQLINTEGER outlen; + SQLLEN outlen; SQLUSMALLINT rowStatus[4]; SQLUINTEGER numRowsFetched; SQLINTEGER nData[4]; diff --git a/test/odbctap.h b/test/odbctap.h index 97f469d95..6cef6188c 100644 --- a/test/odbctap.h +++ b/test/odbctap.h @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -587,9 +588,9 @@ do { \ */ #define is_wstr(a, b, c) \ do { \ - SQLWCHAR *val_a= (a), *val_b= (b); \ + wchar_t *val_a= (a), *val_b= (b); \ int val_len= (int)(c); \ - if (memcmp(val_a, val_b, val_len * sizeof(SQLWCHAR)) != 0) { \ + if (wmemcmp(val_a, val_b, val_len) != 0) { \ printf("# %s ('%*ls') != '%*ls' in %s on line %d\n", \ #a, val_len, val_a, val_len, val_b, __FILE__, __LINE__); \ TEST_RETURN_FAIL; \ diff --git a/testframework/src/test/java/host/IntegrationContainerTest.java b/testframework/src/test/java/host/IntegrationContainerTest.java index 8bc45c906..db9e6bda5 100644 --- a/testframework/src/test/java/host/IntegrationContainerTest.java +++ b/testframework/src/test/java/host/IntegrationContainerTest.java @@ -181,9 +181,9 @@ private void buildDriver(boolean enableIntegrationTests, boolean enablePerforman "unixodbc", "unixodbc-dev", "curl", "libcurl4-openssl-dev", "libssl-dev", "uuid-dev", "zlib1g-dev", "-y"); System.out.println(result.getStdout()); - System.out.println("curl -L https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-8.3.0-linux-glibc2.28-x86_64.tar.xz -o mysql.tar.gz"); + System.out.println("curl -L https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.0-linux-glibc2.28-x86_64.tar.xz -o mysql.tar.gz"); result = testContainer.execInContainer( - "curl", "-L", "https://dev.mysql.com/get/Downloads/MySQL-8.3/mysql-8.3.0-linux-glibc2.28-x86_64.tar.xz", "-o", "mysql.tar.gz"); + "curl", "-L", "https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-8.4.0-linux-glibc2.28-x86_64.tar.xz", "-o", "mysql.tar.gz"); System.out.println(result.getStdout()); System.out.println("tar xf mysql.tar.gz"); diff --git a/testframework/src/test/java/utility/ContainerHelper.java b/testframework/src/test/java/utility/ContainerHelper.java index add2be9d1..648861cc2 100644 --- a/testframework/src/test/java/utility/ContainerHelper.java +++ b/testframework/src/test/java/utility/ContainerHelper.java @@ -202,7 +202,7 @@ protected boolean isRunning(InspectContainerResponse containerInfo) { } public static GenericContainer createMysqlContainer(Network network) { - return new GenericContainer<>("mysql:8.3.0") + return new GenericContainer<>("mysql:8.4.0") .withNetwork(network) .withNetworkAliases("mysql-instance") .withEnv("MYSQL_ROOT_PASSWORD", "root") diff --git a/unit_testing/CMakeLists.txt b/unit_testing/CMakeLists.txt index 7ecd16c45..90d36eaa0 100644 --- a/unit_testing/CMakeLists.txt +++ b/unit_testing/CMakeLists.txt @@ -76,7 +76,7 @@ target_link_libraries( unit_testing gtest_main gmock_main - myodbc-util + myodbc-util resolv awsmysqlodbca-static ) diff --git a/util/installer.cc b/util/installer.cc index 809f0b6f9..34366d14a 100644 --- a/util/installer.cc +++ b/util/installer.cc @@ -1154,23 +1154,28 @@ int DataSource::add() { return rc; #endif -#define MFA_COND(X) || k == W_##X -#define SKIP_COND(X) || k == W_##X - +#define OR_K_EQUAL(X) || k == W_##X for (const auto &el : m_opt_map) { auto &k = el.first; auto &v = el.second; - // Skip non-set options, default values and aliases - if (!v.is_set() SKIP_OPTIONS_LIST(SKIP_COND) || - v.is_default() || - std::find(m_alias_list.begin(), m_alias_list.end(), k) != m_alias_list.end()) - continue; + + // Make sure not to allow skiping non-skippable options. + if (!(false NON_SKIP_OPTIONS_LIST(OR_K_EQUAL))) { + // Skip non-set options, default values and aliases. + if (!v.is_set() SKIP_OPTIONS_LIST(OR_K_EQUAL) || + v.is_default() || + std::find(m_alias_list.begin(), m_alias_list.end(), k) != m_alias_list.end()) + continue; + } SQLWSTRING val = v; - if (k == W_PWD MFA_OPTS(MFA_COND)) { + if (k == W_PWD MFA_OPTS(OR_K_EQUAL)) { // Escape the password(s) val = escape_brackets(v, false); + } else if (val.empty()) { + // For options without value that were not skipped set '0' as their value. + val = {(SQLWCHAR)'0'}; } if (write_opt(k.c_str(), val.c_str())) diff --git a/util/installer.h b/util/installer.h index 244f05be0..588beb6fc 100644 --- a/util/installer.h +++ b/util/installer.h @@ -419,6 +419,11 @@ unsigned int get_network_timeout(unsigned int seconds); #define SKIP_OPTIONS_LIST(X) \ X(DRIVER) X(DSN) +// Options that should be always written to DSN even if not set +// explicitly: in this case DSN will contain OPT_NAME = 0 +#define NON_SKIP_OPTIONS_LIST(X) \ + X(NO_CATALOG) X(NO_SCHEMA) + class DataSource { private: // Map containing options, the key is SQLWSTRING for easier search diff --git a/version.cmake b/version.cmake index c686b2568..12884c8b9 100644 --- a/version.cmake +++ b/version.cmake @@ -34,6 +34,11 @@ SET(CONNECTOR_PATCH "0") SET(CONNECTOR_LEVEL "") SET(CONNECTOR_QUALITY "GA") +# Note: To be used in copyright notes of generated files + +set(COPYRIGHT_YEAR 2024) + + # ---------------------------------------------------------------------- # Set other variables that are about the version # ----------------------------------------------------------------------