Skip to content

Commit

Permalink
encode_text: formatting enhancements
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Feb 11, 2025
1 parent 6332524 commit c209248
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/ctr_encode_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void format_event(cfl_sds_t *buf, struct ctrace_span_event *event, int le

}

static void format_span(cfl_sds_t *buf, struct ctrace *ctx, struct ctrace_span *span, int level)
static void format_span(cfl_sds_t *buf, struct ctrace *ctx, int id, struct ctrace_span *span, int level)
{
int min;
int off = 1 + (level * 4);
Expand All @@ -188,7 +188,7 @@ static void format_span(cfl_sds_t *buf, struct ctrace *ctx, struct ctrace_span *

min = off + 4;

snprintf(tmp, sizeof(tmp) - 1, "%*s[span '%s']\n", off, "", span->name);
snprintf(tmp, sizeof(tmp) - 1, "%*s[span #%i '%s']\n", off, "", id, span->name);
sds_cat_safe(buf, tmp);

/* trace_id */
Expand Down Expand Up @@ -244,14 +244,29 @@ static void format_span(cfl_sds_t *buf, struct ctrace *ctx, struct ctrace_span *
span->dropped_events_count);
sds_cat_safe(buf, tmp);

snprintf(tmp, sizeof(tmp) - 1, "%*s- dropped_links_count : %" PRIu32 "\n", min, "",
span->dropped_links_count);
sds_cat_safe(buf, tmp);

/* trace_state */
snprintf(tmp, sizeof(tmp) - 1, "%*s- trace_state : %s\n", min, "", span->trace_state);
sds_cat_safe(buf, tmp);

/* schema_url */
if (span->schema_url) {
snprintf(tmp, sizeof(tmp) - 1, "%*s- schema_url : %s\n", min, "", span->schema_url);
sds_cat_safe(buf, tmp);
}

/* Status */
snprintf(tmp, sizeof(tmp) - 1, "%*s- status:\n", min, "");
sds_cat_safe(buf, tmp);
snprintf(tmp, sizeof(tmp) - 1, "%*s- code : %i\n", min + 4, "", span->status.code);
snprintf(tmp, sizeof(tmp) - 1, "%*s- code : %i\n", min + 4, "", span->status.code);
sds_cat_safe(buf, tmp);

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

/* span attributes */
Expand Down Expand Up @@ -330,13 +345,14 @@ static void format_span(cfl_sds_t *buf, struct ctrace *ctx, struct ctrace_span *
else {
snprintf(tmp, sizeof(tmp) - 1, "%*s- attributes : ", off, "");
sds_cat_safe(buf, tmp);
format_attributes(buf, span->attr->kv, off);
format_attributes(buf, link->attr->kv, off);
}
}
}

static void format_spans(cfl_sds_t *buf, struct ctrace *ctx, struct cfl_list *spans)
{
int id = 0;
struct cfl_list *head;
struct ctrace_span *span;

Expand All @@ -347,7 +363,8 @@ static void format_spans(cfl_sds_t *buf, struct ctrace *ctx, struct cfl_list *sp
span = cfl_list_entry(head, struct ctrace_span, _head);

/* skip resource if there is no match */
format_span(buf, ctx, span, 2);
format_span(buf, ctx, id, span, 2);
id++;
}
}

Expand All @@ -360,7 +377,7 @@ static void format_instrumentation_scope(cfl_sds_t *buf,
cfl_sds_printf(buf, " - dropped_attributes_count: %i\n", scope->dropped_attr_count);

if (scope->attr) {
cfl_sds_printf(buf, " - attributes:\n");
cfl_sds_printf(buf, " - attributes:");
format_attributes(buf, scope->attr->kv, 8);
}
else {
Expand Down Expand Up @@ -430,10 +447,10 @@ cfl_sds_t ctr_encode_text_create(struct ctrace *ctx)

/* schema_url */
if (resource_span->schema_url) {
cfl_sds_printf(&buf, " schema_url: %s\n", resource_span->schema_url);
cfl_sds_printf(&buf, " - schema_url: %s\n", resource_span->schema_url);
}
else {
cfl_sds_printf(&buf, " schema_url: \"\"\n");
cfl_sds_printf(&buf, " - schema_url: \"\"\n");
}

/* scope spans */
Expand Down

0 comments on commit c209248

Please sign in to comment.