Skip to content

C++ Application Integration


By collecting metric data from C++ applications, analyze application performance visually. The current C++ SDK supports Windows and Linux platforms.

Reading Path

Prerequisites

Note

If you have already activated the RUM Headless service, the prerequisites are automatically configured and you can directly integrate the application.

Application Integration

Log in to the Guance console, navigate to the RUM page, click Create in the top left corner to start creating a new application.

After creation, please record the corresponding RUM App ID for the application, which will be needed later when initializing FTRUMConfig.

Installation

Source Code Repository: https://github.com/GuanceCloud/datakit-cpp

Demo Repository: 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 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 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 SDK
target_link_libraries(${PROJECT_NAME} PRIVATE ${FT-SDK_LIBRARY})

Include Header

#include "datakit-sdk-cpp/FTSDKFactory.h"

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 Conflicting Fields

To avoid conflicts between custom fields and SDK data, it is recommended to add a project abbreviation prefix to tag names, for example, df_tag_name. Reserved keys 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, the field in RUM or Log will override 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. After enabling enable_sdk_log debug logs, manually trigger a View, Action, or Log report, then check the console to confirm if the data appears.

What to Do If There Is No Data After Initialization

First, check the following items:

  • Whether the DataKit address configured in setServerUrl is accessible from the current device
  • Whether setRumAppId is 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 identified, please refer to Troubleshooting.

Feedback

Is this page helpful? ×