C++ Application Integration¶
Collect metrics data from C++ applications to analyze application performance visually. The current C++ SDK supports Windows and Linux platforms.
Reading Path¶
- First-time integration: Start with Quick Start
- Complete integration: Continue reading this document
- Parameter details: Refer to SDK Initialization, RUM Configuration, Log Configuration, Trace Configuration
- Customization capabilities: Refer to Custom Tags, Custom Collection Rules
- Troubleshooting: Refer to Troubleshooting
Prerequisites¶
Note
If you have already activated the RUM Headless service, the prerequisites are automatically configured, and you can proceed directly with application integration.
- Install DataKit;
- Configure the RUM Collector;
- Configure DataKit to be accessible via the public network and install the IP Geolocation Database.
Application Integration¶
Log in to the TrueWatch console, navigate to the RUM page, click Create in the top-left corner to start creating a new application.
After creation, please record the RUM App ID corresponding to the application, as it will be needed later when initializing FTRUMConfig.
Installation¶
Source Code Repository: https://github.com/TrueWatchTech/datakit-cpp
Demo Repository: https://github.com/TrueWatchTech/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.truewatch.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.truewatch.com/ft-sdk-package/vcpkg_config/vcpkg-configuration.json
# If it's arm 64, you need to add VCPKG_FORCE_SYSTEM_BINARIES
#export VCPKG_FORCE_SYSTEM_BINARIES=1
./vcpkg install datakit-sdk-cpp:x64-linux
# In the compilation environment, reference the VCPKG_ROOT variable
export VCPKG_ROOT= [ your_vcpkg_root_dir ]
Add 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 TrueWatch 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 SDK
target_link_libraries(${PROJECT_NAME} PRIVATE ${FT-SDK_LIBRARY})
Include Header¶
Initialization Instructions¶
For the minimal initialization example, please read Quick Start.
For complete initialization and runtime capability instructions, please read SDK Initialization.
Detailed Configuration Entries¶
Advanced Scenarios¶
Frequently Asked Questions¶
Add Project Prefix to Avoid Key Conflicts¶
To avoid conflicts between custom fields and SDK data, it is recommended to add a project abbreviation prefix to tag names, e.g., custom_tag_name. Reserved key used in the project can be queried in the source code.
If a field with the same name appears in the SDK global variables and in RUM or Log data, the field in RUM or Log will overwrite the one in the SDK global variables.
How to Quickly Verify Successful Integration¶
It is recommended to first complete the minimal initialization according to Quick Start, enable enable_sdk_log debug logs, manually trigger a View, Action, or Log report, and then check the console to confirm if data appears.
What to Do If There Is No Data After Initialization¶
First, check the following items:
- Whether the DataKit address configured in
setServerUrlis accessible from the current device - Whether
setRumAppIdis filled in correctly - Whether the DataKit and RUM collector configurations in the Prerequisites have been completed
- Whether the current platform is Windows or Linux, which are supported by the C++ SDK
If the issue still cannot be located, please refer to Troubleshooting.
