Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif()
# CTraces Version
set(CTR_VERSION_MAJOR 0)
set(CTR_VERSION_MINOR 7)
set(CTR_VERSION_PATCH 2)
set(CTR_VERSION_PATCH 3)
set(CTR_VERSION_STR "${CTR_VERSION_MAJOR}.${CTR_VERSION_MINOR}.${CTR_VERSION_PATCH}")

# Define __CTR_FILENAME__
Expand Down
3 changes: 3 additions & 0 deletions include/ctraces/ctr_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ struct ctrace_span *ctr_span_create(struct ctrace *ctx, struct ctrace_scope_span
void ctr_span_destroy(struct ctrace_span *span);

/* Span fields */
/* Preserve received status codes (including unknown int32 values) and messages.
* A NULL message clears the message; failure leaves the previous status intact.
*/
int ctr_span_set_status(struct ctrace_span *span, int code, char *message);
void ctr_span_set_dropped_events_count(struct ctrace_span *span, uint32_t count);
void ctr_span_set_dropped_links_count(struct ctrace_span *span, uint32_t count);
Expand Down
3 changes: 0 additions & 3 deletions src/ctr_decode_msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,6 @@ static int unpack_span_status_code(mpack_reader_t *reader, size_t index, void *c

result = ctr_mpack_consume_int32_tag(reader, &code);
if (result == CTR_MPACK_SUCCESS) {
if (code < CTRACE_SPAN_STATUS_CODE_UNSET || code > CTRACE_SPAN_STATUS_CODE_ERROR) {
return CTR_MPACK_CORRUPT_INPUT_DATA_ERROR;
}
context->span->status.code = code;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ctr_encode_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ static void format_span(cfl_sds_t *buf, struct ctrace *ctx, int id, struct ctrac
sds_cat_safe(buf, tmp);

if (span->status.message) {
snprintf(tmp, sizeof(tmp) - 1, "%*s- message : '%s'\n", min + 4, "", span->status.message);
snprintf(tmp, sizeof(tmp) - 1, "%*s- message : ", min + 4, "");
sds_cat_safe(buf, tmp);
format_string(buf, span->status.message, min + 4);
sds_cat_safe(buf, "\n");
}

/* span attributes */
Expand Down
11 changes: 9 additions & 2 deletions src/ctr_span.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <ctraces/ctraces.h>
#include <limits.h>

#include <cfl/cfl.h>
#include <cfl/cfl_time.h>
Expand Down Expand Up @@ -295,10 +296,16 @@ int ctr_span_set_status(struct ctrace_span *span, int code, char *message)
cfl_sds_t new_message;
struct ctrace_span_status *status;

if (span == NULL || code < CTRACE_SPAN_STATUS_CODE_UNSET ||
code > CTRACE_SPAN_STATUS_CODE_ERROR) {
if (span == NULL) {
return -1;
}

/* Proto3 enums preserve unknown signed 32-bit values in received data. */
#if INT_MAX > INT32_MAX || INT_MIN < INT32_MIN
if (code < INT32_MIN || code > INT32_MAX) {
return -1;
}
#endif

new_message = NULL;
if (message) {
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(UNIT_TESTS_FILES
decoding.c
basic.c
span.c
status.c
opentelemetry.c
)

Expand Down Expand Up @@ -34,3 +35,9 @@ endif()
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/tests)
set_tests_properties(${source_file_we} PROPERTIES LABELS "internal")
endforeach()

# Fault injection stays in the test executable and needs GNU-compatible wrapping.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_definitions(ctr-test-status PRIVATE CTR_TEST_ALLOC_WRAP)
target_link_options(ctr-test-status PRIVATE "-Wl,--wrap=malloc" "-Wl,--wrap=calloc")
endif()
8 changes: 2 additions & 6 deletions tests/span.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void test_reject_cross_context_span()
ctr_destroy(ctx_a);
}

void test_reject_invalid_span_enums()
void test_reject_invalid_span_kind()
{
struct ctrace *ctx;
struct ctrace_resource_span *rs;
Expand All @@ -236,10 +236,6 @@ void test_reject_invalid_span_enums()

TEST_CHECK(ctr_span_kind_set(span, CTRACE_SPAN_CONSUMER + 1) != 0);
TEST_CHECK(span->kind == CTRACE_SPAN_INTERNAL);
TEST_CHECK(ctr_span_set_status(span, CTRACE_SPAN_STATUS_CODE_ERROR + 1,
"invalid") != 0);
TEST_CHECK(span->status.code == CTRACE_SPAN_STATUS_CODE_UNSET);
TEST_CHECK(span->status.message == NULL);

ctr_destroy(ctx);
}
Expand All @@ -252,6 +248,6 @@ TEST_LIST = {
{"text_encoder_optional_and_long_strings", test_text_encoder_optional_and_long_strings},
{"owner_self_assignment", test_owner_self_assignment},
{"reject_cross_context_span", test_reject_cross_context_span},
{"reject_invalid_span_enums", test_reject_invalid_span_enums},
{"reject_invalid_span_kind", test_reject_invalid_span_kind},
{ 0 }
};
Loading
Loading