C++ App Integration¶
By collecting metric data from C++ applications, you can analyze application performance visually. The current C++ SDK supports Windows and Linux platforms.
Reading Path¶
- First-time integration: Start with Quick Start
- Full integration: Continue reading this document
- Parameter details: See SDK Initialization, RUM Configuration, Log Configuration, and Trace Configuration
- Custom capabilities: See Custom Tags and Custom Collection Rules
- Troubleshooting: See Troubleshooting
Prerequisites¶
Note
If you have already enabled RUM Headless, the prerequisites are automatically configured and you can integrate your application directly.
- Install DataKit;
- Configure the RUM Collector;
- Make DataKit publicly accessible and install the IP geolocation database.
App Integration¶
Log in to the Guance console, go to Real User Monitoring (RUM), and click Create App in the upper-left corner to start creating a new application.
After the application is created, note the corresponding RUM App ID. You will need it later when initializing FTRUMConfig.
Installation¶
Source code: https://github.com/GuanceCloud/datakit-cpp
Demo: https://github.com/GuanceCloud/datakit-cpp/ft-sdk-sample
git clone https://github.com/microsoft/vcpkg
cd vcpkg
# Download the custom configuration registries file
curl -o vcpkg-configuration.json https://static.guance.com/ft-sdk-package/vcpkg_config/vcpkg-configuration.json
bootstrap-vcpkg.bat
vcpkg install datakit-sdk-cpp:x64-windows
vcpkg integrate install
git clone https://github.com/microsoft/vcpkg
#apt install ninja-build
#apt install pkg-config
./vcpkg/bootstrap-vcpkg.sh
cd vcpkg
# Download the custom configuration registries file
curl -o vcpkg-configuration.json https://static.guance.com/ft-sdk-package/vcpkg_config/vcpkg-configuration.json
# If you are on arm 64, add VCPKG_FORCE_SYSTEM_BINARIES
#export VCPKG_FORCE_SYSTEM_BINARIES=1
./vcpkg install datakit-sdk-cpp:x64-linux
# In the build environment, reference the VCPKG_ROOT variable
export VCPKG_ROOT= [ your_vcpkg_root_dir ]
Add the CMake configuration
cmake_minimum_required(VERSION 3.0)
project(ft-sdk-reference-sample VERSION 1.0.0 LANGUAGES CXX C)
add_definitions(-fPIC -g -Werror=return-type)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O1 -ftree-vectorize -ffast-math ")
set(CMAKE_CXX_STANDARD 17)
if(DEFINED ENV{VCPKG_ROOT})
if (EXISTS "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
include ("$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_CMAKE_SHARE "$ENV{VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share"
CACHE STRING "TEST")
endif ()
else ()
message(STATUS "please set the system environment variable : VCPKG_ROOT" $ENV{VCPKG_ROOT})
endif ()
# Add the Guance SDK reference
find_path(FT-SDK_INCLUDE_DIR datakit-sdk-cpp/FTSDK.h)
find_library(FT-SDK_LIBRARY ft-sdk "${FT-SDK_INCLUDE_DIR}/../lib/")
include_directories(${FT-SDK_INCLUDE_DIR})
file(GLOB PROJECT_SOURCE "*.cpp")
file(GLOB PROJECT_HEADER "../include/*.h" "*.h")
add_executable (${PROJECT_NAME} ${PROJECT_SOURCE} ${PROJECT_HEADER})
# Link the SDK
target_link_libraries(${PROJECT_NAME} PRIVATE ${FT-SDK_LIBRARY})
Including the Header¶
Initialization Notes¶
For a minimal initialization example, see Quick Start.
For full initialization and runtime capabilities, see SDK Initialization.
Detailed Configuration Entry Points¶
Advanced Scenarios¶
FAQ¶
Add a prefix to avoid conflicting fields¶
To avoid conflicts between custom fields and SDK data, it is recommended to prefix your tag names with a project abbreviation, for example custom_tag_name. For the reserved key values used in the project, see the source code.
If a field with the same name exists in both the SDK global variables and RUM or Log data, the field in RUM or Log overrides the corresponding SDK global variable.
How to quickly verify that the integration is successful¶
We recommend starting with the minimal initialization in Quick Start. After enabling the enable_sdk_log debug log, manually trigger a View, Action, or Log report, and then check the console to confirm that the data appears.
What to do if there is no data after initialization¶
Check the following items first:
- Whether the DataKit address configured in
setServerUrlis accessible from the current device - Whether
setRumAppIdis filled in correctly - Whether the DataKit and RUM collector configuration in Prerequisites has been completed
- Whether the current platform is Windows or Linux, which are supported by the C++ SDK
If you still cannot locate the problem, see Troubleshooting.