Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry vcpkg fixes #3716

Merged
merged 12 commits into from
Jun 7, 2022
107 changes: 57 additions & 50 deletions sdk/core/azure-core-tracing-opentelemetry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ az_vcpkg_integrate()
cmake_minimum_required (VERSION 3.12)
project(azure-core-tracing-opentelemetry LANGUAGES CXX)

if (NOT VCPKG_TARGET_TRIPLET MATCHES "windows" OR VCPKG_TARGET_TRIPLET MATCHES "static" OR NOT WIN32)
set(BUILD_AZURE_CORE_TRACING_OPENTELEMETRY ON)
endif()

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
Expand All @@ -23,66 +27,69 @@ include(AzureConfigRTTI)
# Add create_map_file function
include(CreateMapFile)

find_package(Threads REQUIRED)

if(NOT AZ_ALL_LIBRARIES)
find_package(azure-core-cpp "1.5.0" CONFIG QUIET)
if(NOT azure-core-cpp_FOUND)
find_package(azure-core-cpp "1.5.0" REQUIRED)
endif()
if (BUILD_AZURE_CORE_TRACING_OPENTELEMETRY)
find_package(Threads REQUIRED)

if(NOT AZ_ALL_LIBRARIES)
find_package(azure-core-cpp CONFIG QUIET)
if(NOT azure-core-cpp_FOUND)
find_package(azure-core-cpp REQUIRED)
endif()
endif()
find_package(opentelemetry-cpp "1.3.0" CONFIG REQUIRED)

set(
AZURE_CORE_OPENTELEMETRY_HEADER
inc/azure/core/tracing/opentelemetry/opentelemetry.hpp
)

set(
AZURE_CORE_OPENTELEMETRY_SOURCE
src/opentelemetry.cpp
)

add_library(azure-core-tracing-opentelemetry ${AZURE_CORE_OPENTELEMETRY_HEADER} ${AZURE_CORE_OPENTELEMETRY_SOURCE})

target_include_directories(
azure-core-tracing-opentelemetry
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:include>
)

# make sure that users can consume the project as a library.
add_library(Azure::azure-core-tracing-opentelemetry ALIAS azure-core-tracing-opentelemetry)

# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF
create_code_coverage(core azure-core-tracing-opentelemetry azure-core-tracing-opentelemetry-test "tests?/*;samples?/*")

target_link_libraries(azure-core-tracing-opentelemetry INTERFACE Threads::Threads)

target_link_libraries(azure-core-tracing-opentelemetry PRIVATE azure-core
opentelemetry-cpp::api
opentelemetry-cpp::ext
opentelemetry-cpp::sdk
opentelemetry-cpp::trace)
endif()
find_package(opentelemetry-cpp "1.3.0" CONFIG REQUIRED)

set(
AZURE_CORE_OPENTELEMETRY_HEADER
inc/azure/core/tracing/opentelemetry/opentelemetry.hpp
)

set(
AZURE_CORE_OPENTELEMETRY_SOURCE
src/opentelemetry.cpp
)

add_library(azure-core-tracing-opentelemetry ${AZURE_CORE_OPENTELEMETRY_HEADER} ${AZURE_CORE_OPENTELEMETRY_SOURCE})

target_include_directories(
azure-core-tracing-opentelemetry
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
$<INSTALL_INTERFACE:include>
)

# make sure that users can consume the project as a library.
add_library(Azure::azure-core-tracing-opentelemetry ALIAS azure-core-tracing-opentelemetry)

# coverage. Has no effect if BUILD_CODE_COVERAGE is OFF
create_code_coverage(core azure-core-tracing-opentelemetry azure-core-tracing-opentelemetry-test "tests?/*;samples?/*")

target_link_libraries(azure-core-tracing-opentelemetry INTERFACE Threads::Threads)

target_link_libraries(azure-core-tracing-opentelemetry PRIVATE azure-core
opentelemetry-cpp::api
opentelemetry-cpp::ext
opentelemetry-cpp::sdk
opentelemetry-cpp::trace)


get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/src/private/package_version.hpp")
generate_documentation(azure-core-opentelemetry ${AZ_LIBRARY_VERSION})
generate_documentation(azure-core-tracing-opentelemetry ${AZ_LIBRARY_VERSION})

az_vcpkg_export(
if(BUILD_AZURE_CORE_TRACING_OPENTELEMETRY)
az_vcpkg_export(
azure-core-tracing-opentelemetry
CORE_TRACING_OPENTELEMETRY
"azure/core/tracing/opentelemetry/dll_import_export.hpp"
)

az_rtti_setup(
azure-core-tracing-opentelemetry
CORE_TRACING_OPENTELEMETRY
"azure/core/tracing/opentelemetry/rtti.hpp"
)
az_rtti_setup(
azure-core-tracing-opentelemetry
CORE_TRACING_OPENTELEMETRY
"azure/core/tracing/opentelemetry/rtti.hpp"
)
endif()

if(BUILD_TESTING)
if(BUILD_AZURE_CORE_TRACING_OPENTELEMETRY AND BUILD_TESTING)
# define a symbol that enables some test hooks in code
add_compile_definitions(TESTING_BUILD)

Expand Down
4 changes: 2 additions & 2 deletions sdk/core/azure-core-tracing-opentelemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Then, use in your CMake file:

```CMake
find_package(azure-core-tracing-opentelemetry-cpp CONFIG REQUIRED)
target_link_libraries(<your project name> PRIVATE Azure::azure-core-opentelemetry)
target_link_libraries(<your project name> PRIVATE Azure::azure-core-tracing-opentelemetry)
```

## Key concepts
Expand All @@ -39,7 +39,7 @@ below for more details.
### OpenTelemetry Compatibility

Most Azure SDKs use [OpenTelemetry](https://opentelemetry.io/) to support tracing. Specifically, we depend on
the [azure-core-opentelemetry](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/docs/building-with-vcpkg.md) VCPKG package.
the [opentelemetry-cpp](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/docs/building-with-vcpkg.md) VCPKG package.


## Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project (azure-core-tracing-opentelemetry-test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include(AzureBuildTargetForCI)
include(GoogleTest)

add_executable (
Expand Down Expand Up @@ -51,9 +52,9 @@ target_link_libraries(azure-core-tracing-opentelemetry-test PRIVATE azure-core-t
create_per_service_target_build(core azure-core-tracing-opentelemetry-test)
create_map_file(azure-core-tracing-opentelemetry-test azure-core-tracing-opentelemetry-test.map)

# gtest_discover_tests will scan the test from azure-core-opentelemetry-test and call add_test
# gtest_discover_tests will scan the test from azure-core-tracing-opentelemetry-test and call add_test
# for each test to ctest. This enables `ctest -r` to run specific tests directly.
gtest_discover_tests(azure-core-tracing-opentelemetry-test
TEST_PREFIX azure-core-opentelemetry.
TEST_PREFIX azure-core-tracing-opentelemetry.
NO_PRETTY_TYPES
NO_PRETTY_VALUES)
7 changes: 6 additions & 1 deletion sdk/core/azure-core-tracing-opentelemetry/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "azure-core-tracing-opentelemetry-cpp",
"version-string": "1.0.0-beta.1",
"supports": "!(windows & !static)",
"dependencies": [
{
"name": "azure-core-cpp",
"default-features": false
},
{
"name": "opentelemetry-cpp",
"platform": "!uwp"
"platform": "!(windows & !static)"
},
{
"name": "vcpkg-cmake",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(azure-core-cpp "1.7.0-beta.1")
find_dependency(Threads)

find_dependency(opentelemetry-cpp@CURL_MIN_REQUIRED_VERSION@)
find_dependency(opentelemetry-cpp)

include("${CMAKE_CURRENT_LIST_DIR}/azure-core-opentelemetry-cppTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/azure-core-tracing-opentelemetry-cppTargets.cmake")

check_required_components("azure-core-opentelemetry-cpp")
check_required_components("azure-core-tracing-opentelemetry-cpp")
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO Azure/azure-sdk-for-cpp
REF azure-core_coretracing@AZ_LIBRARY_VERSION@
REF azure-core-tracing-opentelemetry_@AZ_LIBRARY_VERSION@
SHA512 0
)

vcpkg_cmake_configure(
SOURCE_PATH ${SOURCE_PATH}/sdk/core/azure-core/
SOURCE_PATH ${SOURCE_PATH}/sdk/core/azure-core-tracing-opentelemetry/
OPTIONS
${FEATURE_OPTIONS}
-DWARNINGS_AS_ERRORS=OFF
)

Expand Down
19 changes: 13 additions & 6 deletions sdk/core/azure-core-tracing-opentelemetry/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@
# SPDX-License-Identifier: MIT

{
"name": "azure-core-opentelemetry-cpp",
"name": "azure-core-tracing-opentelemetry-cpp",
"version-semver": "@AZ_LIBRARY_VERSION@",
"description": [
"Microsoft Azure Core OpenTelemetry SDK for C++",
"Microsoft Azure Core Tracing OpenTelemetry SDK for C++",
"This library provides support for modern Azure SDK client libraries written in C++ to leverage OpenTelemetry APIs."
],
"homepage": "https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/core/azure-core-opentelemetry",
"homepage": "https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/core/azure-core-tracing-opentelemetry",
"license": "MIT",
"supports": "!(windows & !static)",
antkmsft marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": [
{
"name": "azure-core-cpp",
"default-features": false,
"version>=": "1.7.0-beta.1"
},
{
"name": "opentelemetry-cpp",
"version>=": "1.3.0"
},
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "opentelemetry-cpp"
}
]
}
3 changes: 3 additions & 0 deletions sdk/core/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ stages:
- Name: azure-core
Path: azure-core
VcpkgPortName: azure-core-cpp
- Name: azure-core-tracing-opentelemetry
Path: azure-core-tracing-opentelemetry
VcpkgPortName: azure-core-tracing-opentelemetry-cpp
# Since Azure Core will run all service's tests, it requires all the expected env vars from services
TestEnv:
# Key Vault
Expand Down