Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
cmake_minimum_required(VERSION 3.10)
project(rrd_otel_cpp_wrapper VERSION 1.0.0 LANGUAGES CXX)

# Include GNUInstallDirs to define CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_INCLUDEDIR, etc.
include(GNUInstallDirs)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find OpenTelemetry-CPP
find_package(opentelemetry-cpp CONFIG QUIET)

# Track which method found the package
set(FOUND_BY_CMAKE FALSE)
set(FOUND_BY_PKGCONFIG FALSE)

if(opentelemetry-cpp_FOUND)
message(STATUS "OpenTelemetry-CPP found via CMake config")
set(FOUND_BY_CMAKE TRUE)
else()
# Fall back to pkg-config (common in Yocto)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
# Try different possible package names
pkg_check_modules(OPENTELEMETRY QUIET opentelemetry-cpp)
if(NOT OPENTELEMETRY_FOUND)
pkg_check_modules(OPENTELEMETRY QUIET opentelemetry)
endif()
if(NOT OPENTELEMETRY_FOUND)
# Try individual components
pkg_check_modules(OTEL_TRACE QUIET opentelemetry_trace)
pkg_check_modules(OTEL_COMMON QUIET opentelemetry_common)
pkg_check_modules(OTEL_RESOURCES QUIET opentelemetry_resources)
pkg_check_modules(OTEL_OTLP QUIET opentelemetry_otlp_http_exporter)
if(OTEL_TRACE_FOUND AND OTEL_COMMON_FOUND)
message(STATUS "OpenTelemetry-CPP found via pkg-config (individual components)")
set(FOUND_BY_PKGCONFIG TRUE)
# Combine all the variables
set(OPENTELEMETRY_INCLUDE_DIRS ${OTEL_TRACE_INCLUDE_DIRS} ${OTEL_COMMON_INCLUDE_DIRS} ${OTEL_RESOURCES_INCLUDE_DIRS} ${OTEL_OTLP_INCLUDE_DIRS})
set(OPENTELEMETRY_LIBRARIES ${OTEL_TRACE_LIBRARIES} ${OTEL_COMMON_LIBRARIES} ${OTEL_RESOURCES_LIBRARIES} ${OTEL_OTLP_LIBRARIES})
set(OPENTELEMETRY_LIBRARY_DIRS ${OTEL_TRACE_LIBRARY_DIRS} ${OTEL_COMMON_LIBRARY_DIRS} ${OTEL_RESOURCES_LIBRARY_DIRS} ${OTEL_OTLP_LIBRARY_DIRS})
list(REMOVE_DUPLICATES OPENTELEMETRY_INCLUDE_DIRS)
list(REMOVE_DUPLICATES OPENTELEMETRY_LIBRARY_DIRS)
endif()
else()
message(STATUS "OpenTelemetry-CPP found via pkg-config")
set(FOUND_BY_PKGCONFIG TRUE)
endif()
endif()
endif()

if(NOT FOUND_BY_CMAKE AND NOT FOUND_BY_PKGCONFIG)
message(WARNING "OpenTelemetry-CPP not found via CMake or pkg-config")
message(WARNING "Attempting to use direct library linking...")
# Last resort: try to find libraries directly
find_library(OTEL_TRACE_LIB opentelemetry_trace)
find_library(OTEL_COMMON_LIB opentelemetry_common)
if(OTEL_TRACE_LIB AND OTEL_COMMON_LIB)
message(STATUS "OpenTelemetry libraries found directly")
set(FOUND_BY_PKGCONFIG TRUE)
set(OPENTELEMETRY_LIBRARIES
${OTEL_TRACE_LIB}
${OTEL_COMMON_LIB}
)
# Try to find additional libraries
find_library(OTEL_RESOURCES_LIB opentelemetry_resources)
find_library(OTEL_OTLP_LIB opentelemetry_otlp_http_exporter)
if(OTEL_RESOURCES_LIB)
list(APPEND OPENTELEMETRY_LIBRARIES ${OTEL_RESOURCES_LIB})
endif()
if(OTEL_OTLP_LIB)
list(APPEND OPENTELEMETRY_LIBRARIES ${OTEL_OTLP_LIB})
endif()
else()
message(FATAL_ERROR "OpenTelemetry-CPP not found. Please install opentelemetry-cpp package.")
endif()
endif()

message(STATUS "OpenTelemetry-CPP found - building C++ wrapper for remote_debugger")

# ============================================================================
# OpenTelemetry C++ Wrapper Library
# ============================================================================
add_library(rrd_otel_cpp_wrapper STATIC
src/rrdOpenTelemetry_cpp_wrapper.cpp
)
Comment on lines +85 to +87
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library is built as STATIC but this may cause issues if multiple binaries in the same process try to use it, as each will have its own copy of the global state (g_wrapper, etc.). If this wrapper is only used by the remotedebugger binary this is fine, but if shared across multiple binaries, consider building as SHARED instead to ensure a single instance of the global state.

Copilot uses AI. Check for mistakes.

target_compile_features(rrd_otel_cpp_wrapper PRIVATE cxx_std_17)

# Link OpenTelemetry libraries based on how they were found
if(FOUND_BY_CMAKE)
# Use CMake targets
target_link_libraries(rrd_otel_cpp_wrapper PUBLIC
opentelemetry-cpp::trace
opentelemetry-cpp::common
opentelemetry-cpp::ostream_span_exporter
Comment on lines +89 to +97
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenTelemetry library names may not match the actual package: The target names use opentelemetry-cpp:: prefix (lines 19-24), which suggests use of CMake's imported targets from find_package(). However, there's no find_package(opentelemetry-cpp) or similar command in the CMakeLists.txt.

Add the appropriate find_package() command for OpenTelemetry C++, or use the correct raw library names (e.g., -lopentelemetry_trace instead of opentelemetry-cpp::trace). The current configuration will fail with "Target opentelemetry-cpp::trace not found" errors.

Copilot uses AI. Check for mistakes.
opentelemetry-cpp::otlp_http_exporter
opentelemetry-cpp::resources
)
else()
# Use pkg-config variables
target_include_directories(rrd_otel_cpp_wrapper PUBLIC ${OPENTELEMETRY_INCLUDE_DIRS})
target_link_libraries(rrd_otel_cpp_wrapper PUBLIC ${OPENTELEMETRY_LIBRARIES})
target_link_directories(rrd_otel_cpp_wrapper PUBLIC ${OPENTELEMETRY_LIBRARY_DIRS})
if(OPENTELEMETRY_CFLAGS_OTHER)
target_compile_options(rrd_otel_cpp_wrapper PUBLIC ${OPENTELEMETRY_CFLAGS_OTHER})
endif()
endif()

target_include_directories(rrd_otel_cpp_wrapper PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# Optimize for size
if(NOT MSVC)
target_compile_options(rrd_otel_cpp_wrapper PRIVATE
-fno-rtti
$<$<CONFIG:Release>:-O3>
)
endif()

# Install library for Makefile to link against
install(TARGETS rrd_otel_cpp_wrapper
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# Install header for C code to include
install(FILES src/rrdOpenTelemetry_cpp_wrapper.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Comment on lines +123 to +132
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_INSTALL_LIBDIR/CMAKE_INSTALL_INCLUDEDIR are used but GNUInstallDirs is not included, so these variables may be empty/undefined depending on the CMake version/toolchain. Add include(GNUInstallDirs) before the install() commands to ensure correct install destinations.

Copilot uses AI. Check for mistakes.

# ============================================================================
# Summary
# ============================================================================
message(STATUS "")
message(STATUS "C++ Wrapper Build Configuration:")
message(STATUS " C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS " Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS " Install Prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS " Output Library: librrd_otel_cpp_wrapper.a")
message(STATUS "")
message(STATUS "NOTE: Main binary built by existing Makefile")
message(STATUS "")
Comment on lines +144 to +145
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository is built with Autotools (configure.ac/Makefile.am), but this new CMake build for rrd_otel_cpp_wrapper is not invoked from the existing build/install flow. Add documentation or tooling to ensure the wrapper is built/installed as part of the standard build, otherwise users will get link-time failures when remotedebugger expects librrd_otel_cpp_wrapper to exist.

Suggested change
message(STATUS "NOTE: Main binary built by existing Makefile")
message(STATUS "")
message(STATUS "NOTE:")
message(STATUS " The main remotedebugger binary is built by the existing Autotools/Makefile")
message(STATUS " build system. This CMake project only builds and installs the")
message(STATUS " librrd_otel_cpp_wrapper library that remotedebugger expects to link against.")
message(STATUS "")
message(STATUS " To integrate this wrapper into your normal build/install flow, ensure that")
message(STATUS " you run the following (or equivalent) commands in addition to the Autotools")
message(STATUS " build, so that librrd_otel_cpp_wrapper is available at link time:")
message(STATUS "")
message(STATUS " mkdir -p build && cd build")
message(STATUS " cmake -S .. -B . -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX}")
message(STATUS " cmake --build .")
message(STATUS " cmake --install .")
message(STATUS "")
message(STATUS " If this step is skipped, remotedebugger may fail to link because")
message(STATUS " librrd_otel_cpp_wrapper cannot be found.")
message(STATUS "")

Copilot uses AI. Check for mistakes.
15 changes: 11 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
# limitations under the License.
##########################################################################

bin_PROGRAMS = remotedebugger
bin_PROGRAMS = remotedebugger rrdTestApp

remotedebuggerincludedir = $(includedir)/rrd
rrdTestAppincludedir = $(includedir)/rrd
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent variable name: Line 12 defines rrdTestAppincludedir but this variable is never used. The rrdTestApp_SOURCES is defined but there's no corresponding include directory usage. If the test app needs special includes, they should be added via rrdTestApp_CFLAGS, or this line should be removed if not needed.

Suggested change
rrdTestAppincludedir = $(includedir)/rrd

Copilot uses AI. Check for mistakes.
remotedebuggerinclude_HEADERS = rrdCommon.h rrdInterface.h \
rrd_archive.h rrd_config.h rrd_logproc.h rrd_sysinfo.h rrd_upload.h
rrd_archive.h rrd_config.h rrd_logproc.h rrd_sysinfo.h rrd_upload.h rrdOpenTelemetry.h
rrdTestApp_SOURCES = rrdTraceTestApp.c
remotedebugger_SOURCES = rrdMain.c rrdEventProcess.c rrdJsonParser.c rrdRunCmdThread.c rrdCommandSanity.c rrdDynamic.c rrdExecuteScript.c rrdMsgPackDecoder.c rrdInterface.c uploadRRDLogs.c rrd_config.c rrd_sysinfo.c rrd_logproc.c rrd_archive.c rrd_upload.c rrdOpenTelemetry.c
Comment on lines +9 to +16
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test app target is named "rrdTestApp", but the source file and in-app docs refer to "rrdTraceTestApp". Consider renaming the target to match the documented name (or update the documentation strings) to avoid confusion for users and scripts.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C++ wrapper implementation file 'rrdOpenTelemetry_cpp_wrapper.cpp' is not included in the remotedebugger_SOURCES list. This file contains the actual OpenTelemetry SDK integration that is called from rrdOpenTelemetry.c. Without compiling and linking this file, the build will fail with undefined references to functions like rrdOtel_Initialize_Cpp, rrdOtel_StartSpan_Cpp, etc. Add 'rrdOpenTelemetry_cpp_wrapper.cpp' to the remotedebugger_SOURCES variable.

Suggested change
remotedebugger_SOURCES = rrdMain.c rrdEventProcess.c rrdJsonParser.c rrdRunCmdThread.c rrdCommandSanity.c rrdDynamic.c rrdExecuteScript.c rrdMsgPackDecoder.c rrdInterface.c uploadRRDLogs.c rrd_config.c rrd_sysinfo.c rrd_logproc.c rrd_archive.c rrd_upload.c rrdOpenTelemetry.c
remotedebugger_SOURCES = rrdMain.c rrdEventProcess.c rrdJsonParser.c rrdRunCmdThread.c rrdCommandSanity.c rrdDynamic.c rrdExecuteScript.c rrdMsgPackDecoder.c rrdInterface.c uploadRRDLogs.c rrd_config.c rrd_sysinfo.c rrd_logproc.c rrd_archive.c rrd_upload.c rrdOpenTelemetry.c rrdOpenTelemetry_cpp_wrapper.cpp

Copilot uses AI. Check for mistakes.

remotedebugger_SOURCES = rrdMain.c rrdEventProcess.c rrdJsonParser.c rrdRunCmdThread.c rrdCommandSanity.c rrdDynamic.c rrdExecuteScript.c rrdMsgPackDecoder.c rrdInterface.c uploadRRDLogs.c rrd_config.c rrd_sysinfo.c rrd_logproc.c rrd_archive.c rrd_upload.c
# Allow wrapper library path to be overridden (for Yocto builds)
RRD_OTEL_WRAPPER_DIR ?= $(STAGING_DIR)/usr/lib

remotedebugger_CFLAGS = -I$(top_srcdir)/include/rrd -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/trower-base64/ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rbus/ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir} $(CJSON_CFLAGS)
rrdTestApp_CFLAGS = -I$(top_srcdir)/include/rrd -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/trower-base64/ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rbus/ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir} $(CJSON_CFLAGS)
AM_LDFLAGS="-lpthread -lrdkloggers -lmsgpackc -ltrower-base64 -lwebconfig_framework -lrbus -lsecure_wrapper "
remotedebugger_LDADD = -lfwutils -luploadstblogs -lz
if IARMBUS_ENABLE
remotedebugger_SOURCES += rrdIarmEvents.c
remotedebugger_CFLAGS += -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmbus/ -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs/rdmmgr -I$(PKG_CONFIG_SYSROOT_DIR)${includedir}/rdk/iarmmgrs-hal -DIARMBUS_SUPPORT
AM_LDFLAGS += "-lIARMBus -lrfcapi -ltr181api"
endif
remotedebugger_LDFLAGS = $(AM_LDFLAGS) $(CJSON_LDFLAGS) $(CJSON_LIBS) -luploadstblogs -fno-common
rrdTestApp_LDFLAGS = $(AM_LDFLAGS) $(CJSON_LDFLAGS) $(CJSON_LIBS) -luploadstblogs -fno-common
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rrdTestApp_LDFLAGS references libraries that may not be needed for the test application. The test app only uses RBUS APIs and doesn't appear to need -lwebconfig_framework, -lmsgpackc, -ltrower-base64, -lsecure_wrapper, -lfwutils, -luploadstblogs, or -lz. This could cause unnecessary build dependencies or linking errors if these libraries aren't available. Consider using only the minimal set of libraries needed for the test app, likely just -lrbus and -lrdkloggers.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +30
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rrdTestApp_LDADD variable is not defined, but rrdTestApp_LDFLAGS is. This means rrdTestApp won't link against the libraries specified in remotedebugger_LDADD (like -lfwutils, -luploadstblogs, -lz). The test app should either have its own rrdTestApp_LDADD or should not require these libraries. If RBUS functionality is needed for the test app, ensure it links against all required libraries.

Copilot uses AI. Check for mistakes.
remotedebugger_LDFLAGS = $(AM_LDFLAGS) $(CJSON_LDFLAGS) $(CJSON_LIBS) -luploadstblogs -fno-common -L$(RRD_OTEL_WRAPPER_DIR) -lrrd_otel_cpp_wrapper -lopentelemetry_trace -lopentelemetry_otlp_http_exporter -lopentelemetry_common -lopentelemetry_resources
Comment on lines +16 to +31
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remotedebugger binary is linked with the OpenTelemetry C++ wrapper library and dependencies, but rrdOpenTelemetry_cpp_wrapper.cpp is not listed in remotedebugger_SOURCES. The wrapper library needs to be built separately (presumably by CMake as indicated in CMakeLists.txt) and then linked. However, there's no clear indication in this Makefile that the C++ wrapper library will be built first or is available. Consider adding a dependency or build rule to ensure the C++ wrapper is built before linking.

Copilot uses AI. Check for mistakes.

4 changes: 4 additions & 0 deletions src/rrdCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ typedef struct mbuffer {
bool inDynamic;
bool appendMode;
deepsleep_event_et dsEvent;
/* OpenTelemetry trace context for distributed tracing */
char *traceParent;
char *traceState;
uint64_t spanHandle;
} data_buf;
Comment on lines +100 to 104
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data_buf now contains a uint64_t spanHandle but this header does not include <stdint.h>, so uint64_t may be undefined depending on include order. Add <stdint.h> to rrdCommon.h to make the type available to all translation units that include it.

Copilot uses AI. Check for mistakes.

/*Structure for Message Header*/
Expand Down
17 changes: 16 additions & 1 deletion src/rrdIarmEvents.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

#include "rrdInterface.h"
#include "rrdRunCmdThread.h"
#include "rrdRunCmdThread.h"
#include "rrdOpenTelemetry.h"
Comment on lines +21 to +22
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rrdOpenTelemetry APIs are used here, but under GTEST_ENABLE the unit test runner compiles by including C sources and currently does not include rrdOpenTelemetry.c. This change will break unit-test linking unless rrdOpenTelemetry.c is included/linked for tests or these calls are compiled out/stubbed for GTEST_ENABLE builds.

Suggested change
#include "rrdRunCmdThread.h"
#include "rrdOpenTelemetry.h"
#include "rrdRunCmdThread.h"
#if !defined(GTEST_ENABLE)
#include "rrdOpenTelemetry.h"
#endif

Copilot uses AI. Check for mistakes.
#if defined(PWRMGR_PLUGIN)
#include "power_controller.h"
#include <pthread.h>
Expand Down Expand Up @@ -156,7 +157,21 @@ void _pwrManagerEventHandler(const PowerController_PowerState_t currentState,
rbusValue_t value;
rbusValue_Init(&value);
rbusValue_SetString(value,"root");

/* Generate and set trace context before RBUS operation */
rrd_otel_context_t ctx;
rrdOtel_GenerateContext(&ctx);
rrdOtel_SetContext(&ctx);
rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
Comment on lines +163 to +165
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for OpenTelemetry functions. If rrdOtel_GenerateContext, rrdOtel_SetContext, or rbusHandle_SetTraceContextFromString fail, the code continues without checking return values. While trace context failures may not be critical to the main functionality, ignoring these errors could lead to silent trace loss and make debugging difficult. Consider logging errors when these operations fail.

Suggested change
rrdOtel_GenerateContext(&ctx);
rrdOtel_SetContext(&ctx);
rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
int otelStatus = rrdOtel_GenerateContext(&ctx);
if (otelStatus != 0)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: rrdOtel_GenerateContext failed with status %d\n", __FUNCTION__, __LINE__, otelStatus);
}
otelStatus = rrdOtel_SetContext(&ctx);
if (otelStatus != 0)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: rrdOtel_SetContext failed with status %d\n", __FUNCTION__, __LINE__, otelStatus);
}
rbusError_t traceRc = rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
if (traceRc != RBUS_ERROR_SUCCESS)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: rbusHandle_SetTraceContextFromString failed with error [%d]\n", __FUNCTION__, __LINE__, traceRc);
}

Copilot uses AI. Check for mistakes.

Comment on lines +161 to +166
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return values from rrdOtel_GenerateContext, rrdOtel_SetContext, and rbusHandle_SetTraceContextFromString are ignored. If any of these fail, the code proceeds and logs events as if tracing is set up, which can lead to confusing/incorrect telemetry. Check and handle these return codes (and avoid leaving a partially-initialized context active).

Copilot uses AI. Check for mistakes.
Comment on lines 158 to +166
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value from rrdOtel_GenerateContext and rrdOtel_SetContext is not checked. If these calls fail (e.g., return non-zero), the code continues to call rbusHandle_SetTraceContextFromString with potentially uninitialized ctx values. Add error checking and handle failures appropriately.

Suggested change
rbusValue_Init(&value);
rbusValue_SetString(value,"root");
/* Generate and set trace context before RBUS operation */
rrd_otel_context_t ctx;
rrdOtel_GenerateContext(&ctx);
rrdOtel_SetContext(&ctx);
rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
rbusValue_Init(&value);
rbusValue_SetString(value,"root");
/* Generate and set trace context before RBUS operation */
rrd_otel_context_t ctx;
int otelRet = rrdOtel_GenerateContext(&ctx);
if (otelRet != 0)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: rrdOtel_GenerateContext failed (ret=%d), proceeding without trace context\n", __FUNCTION__, __LINE__, otelRet);
}
else
{
otelRet = rrdOtel_SetContext(&ctx);
if (otelRet != 0)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: rrdOtel_SetContext failed (ret=%d), proceeding without trace context\n", __FUNCTION__, __LINE__, otelRet);
}
else
{
rbusError_t traceRc = rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
if (traceRc != RBUS_ERROR_SUCCESS)
{
RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: rbusHandle_SetTraceContextFromString failed with error [%d], proceeding without trace context\n", __FUNCTION__, __LINE__, traceRc);
}
}
}

Copilot uses AI. Check for mistakes.
rc = rbus_set(rrdRbusHandle, RRD_WEBCFG_FORCE_SYNC, value, NULL);

/* Log the operation in trace */
rrdOtel_LogEvent("rbus_set", RRD_WEBCFG_FORCE_SYNC);
Comment on lines +165 to +170
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as in rrdInterface.c: rrdOtel_LogEvent is called when no span is active. A trace context is generated and set (lines 162-165), but no span is created before calling rrdOtel_LogEvent at line 170. According to the rrdOtel_LogEvent implementation, it requires an active span to log events to, so this call will fail. A span should be created before calling LogEvent.

Suggested change
rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
rc = rbus_set(rrdRbusHandle, RRD_WEBCFG_FORCE_SYNC, value, NULL);
/* Log the operation in trace */
rrdOtel_LogEvent("rbus_set", RRD_WEBCFG_FORCE_SYNC);
rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
/* Start a span for the RBUS operation so that events are recorded correctly */
rrdOtel_StartSpan("rbus_set");
rc = rbus_set(rrdRbusHandle, RRD_WEBCFG_FORCE_SYNC, value, NULL);
/* Log the operation in trace */
rrdOtel_LogEvent("rbus_set", RRD_WEBCFG_FORCE_SYNC);
/* End the span after logging the operation */
rrdOtel_EndSpan();

Copilot uses AI. Check for mistakes.

/* Clear trace context after operation */
rbusHandle_ClearTraceContext(rrdRbusHandle);
Comment on lines +160 to +173
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls ignore return codes (rrdOtel_GenerateContext/SetContext and rbusHandle_SetTraceContextFromString) and then call rrdOtel_LogEvent without ever starting a span (LogEvent currently no-ops when no span is active). Either create a span around this RBUS operation and handle failures, or skip logging when tracing isn't available.

Suggested change
/* Generate and set trace context before RBUS operation */
rrd_otel_context_t ctx;
rrdOtel_GenerateContext(&ctx);
rrdOtel_SetContext(&ctx);
rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
rc = rbus_set(rrdRbusHandle, RRD_WEBCFG_FORCE_SYNC, value, NULL);
/* Log the operation in trace */
rrdOtel_LogEvent("rbus_set", RRD_WEBCFG_FORCE_SYNC);
/* Clear trace context after operation */
rbusHandle_ClearTraceContext(rrdRbusHandle);
/* Generate and set trace context before RBUS operation */
rrd_otel_context_t ctx;
int otelGenRc = rrdOtel_GenerateContext(&ctx);
int otelSetRc = 0;
rbusError_t rbusTraceRc = RBUS_ERROR_BUS_ERROR;
int tracingEnabled = 0;
if (otelGenRc == 0)
{
otelSetRc = rrdOtel_SetContext(&ctx);
if (otelSetRc == 0)
{
rbusTraceRc = rbusHandle_SetTraceContextFromString(rrdRbusHandle, ctx.traceParent, ctx.traceState);
if (rbusTraceRc == RBUS_ERROR_SUCCESS)
{
tracingEnabled = 1;
}
}
}
rc = rbus_set(rrdRbusHandle, RRD_WEBCFG_FORCE_SYNC, value, NULL);
/* Log the operation in trace, if tracing is available */
if (tracingEnabled)
{
rrdOtel_LogEvent("rbus_set", RRD_WEBCFG_FORCE_SYNC);
/* Clear trace context after operation */
rbusHandle_ClearTraceContext(rrdRbusHandle);
}

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leak: The rbusValue_t initialized with rbusValue_Init is never released. After the rbus_set call and before the function returns, rbusValue_Release(value) should be called to free the allocated resources.

Suggested change
rbusHandle_ClearTraceContext(rrdRbusHandle);
rbusHandle_ClearTraceContext(rrdRbusHandle);
rbusValue_Release(value);

Copilot uses AI. Check for mistakes.

Comment on lines +160 to +174
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected. Multiple lines (160-161, 165-166, 169, 173-174) use tabs instead of spaces. The codebase appears to use spaces for indentation (4 spaces per level based on surrounding code). Replace tabs with spaces to maintain consistent formatting throughout the file.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +174
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: Tab characters are mixed with spaces on lines 160, 161, 165, 169, 173. This violates the consistent spacing pattern used throughout the rest of the file.

Convert tabs to spaces to match the existing code style.

Copilot uses AI. Check for mistakes.
#ifndef USE_L2_SUPPORT
if (rc != RBUS_ERROR_SUCCESS)
{
Expand Down
Loading
Loading