Skip to content

Commit 142d0a0

Browse files
authored
Added ResultString to StatusTrace event (#1213)
* Added ResultString to StatusTrace event * updated TelemetryTest::ProcessStatusTraceEvent * addressed comments
1 parent 139847e commit 142d0a0

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/common/telemetry/Telemetry.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static inline void OSConfigGetElapsedTime(int64_t* elapsed_us_var)
167167
const char* _timestamp = GetFormattedTime(); \
168168
int64_t _elapsed_us = 0; \
169169
const char* _distroName = OSConfigTelemetryGetCachedOsName(); \
170+
const char* _resultString = strerror(status); \
170171
OSConfigGetElapsedTime(&_elapsed_us); \
171172
telemetry_json = FormatAllocateString( \
172173
"{" \
@@ -178,6 +179,7 @@ static inline void OSConfigGetElapsedTime(int64_t* elapsed_us_var)
178179
"\"RuleCodename\":\"%s\"," \
179180
"\"CallingFunctionName\":\"%s\"," \
180181
"\"ResultCode\":\"%d\"," \
182+
"\"ResultString\":\"%s\"," \
181183
"\"ScenarioName\":\"%s\"," \
182184
"\"Microseconds\":\"%" PRId64 \
183185
"\"," \
@@ -186,7 +188,7 @@ static inline void OSConfigGetElapsedTime(int64_t* elapsed_us_var)
186188
"\"Version\":\"%s\"" \
187189
"}", \
188190
_timestamp ? _timestamp : TELEMETRY_NOTFOUND_STRING, __FILE__, line, __func__, _ruleCodename ? _ruleCodename : TELEMETRY_NOTFOUND_STRING, \
189-
(callingFunctionName) ? (callingFunctionName) : TELEMETRY_NOTFOUND_STRING, status, _scenarioName, _elapsed_us, \
191+
(callingFunctionName) ? (callingFunctionName) : TELEMETRY_NOTFOUND_STRING, status, _resultString, _scenarioName, _elapsed_us, \
190192
_distroName ? _distroName : TELEMETRY_NOTFOUND_STRING, _correlationId ? _correlationId : TELEMETRY_NOTFOUND_STRING, OSCONFIG_VERSION); \
191193
if (NULL != telemetry_json) \
192194
{ \

src/common/telemetry/lib/ParameterSets.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const std::set<std::string> RULE_COMPLETE_OPTIONAL_PARAMS = {
3434

3535
// StatusTrace
3636
const std::set<std::string> STATUS_TRACE_REQUIRED_PARAMS = {
37-
"FileName", "LineNumber", "ScenarioName", "FunctionName", "RuleCodename", "CallingFunctionName", "Microseconds", "ResultCode"};
37+
"FileName", "LineNumber", "ScenarioName", "FunctionName", "RuleCodename", "CallingFunctionName", "Microseconds", "ResultCode", "ResultString"};
3838
const std::set<std::string> STATUS_TRACE_OPTIONAL_PARAMS = {
3939
// No optional params for now
4040
};

src/common/telemetry/lib/tests/TelemetryTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ TEST_F(TelemetryTest, ProcessBaselineRunMissingTimestampEvent)
137137

138138
TEST_F(TelemetryTest, ProcessStatusTraceEvent)
139139
{
140-
std::string realEvent = R"({"EventName":"StatusTrace","Timestamp":"2025-10-17 22:52:56+0000","FileName":"/workspaces/azure-osconfig/src/common/asb/Asb.c","LineNumber":"1109","FunctionName":"AsbShutdown","RuleCodename":"auditEnsureSmbWithSambaIsDisabled","CallingFunctionName":"TestingStatusTrace","ResultCode":"0","ScenarioName":"TestingScenario","Microseconds":"101807","DistroName":"CentOS","CorrelationId":"","Version":"1.0.5.20251017-g03b36b7d"})";
140+
std::string realEvent = R"({"EventName":"StatusTrace","Timestamp":"2025-10-17 22:52:56+0000","FileName":"/workspaces/azure-osconfig/src/common/asb/Asb.c","LineNumber":"1109","FunctionName":"AsbShutdown","RuleCodename":"auditEnsureSmbWithSambaIsDisabled","CallingFunctionName":"TestingStatusTrace","ResultCode":"0","ResultString":"OK","ScenarioName":"TestingScenario","Microseconds":"101807","DistroName":"CentOS","CorrelationId":"","Version":"1.0.5.20251017-g03b36b7d"})";
141141
ASSERT_TRUE(CreateTestJsonFile(realEvent));
142142
Telemetry::TelemetryManager telemetryManager(false, std::chrono::seconds(1));
143143
EXPECT_TRUE(telemetryManager.ProcessJsonFile(m_testJsonFile));

0 commit comments

Comments
 (0)