Skip to content

Commit faab663

Browse files
committed
encode_opentelemetry: Encode otel payloads if valid contexts are existing
1 parent 92a16b9 commit faab663

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/cmt_encode_opentelemetry.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,7 @@ int pack_basic_type(struct cmt_opentelemetry_context *context,
23962396
int result;
23972397
struct cfl_list *head;
23982398
uint64_t now;
2399+
int cutoff;
23992400

24002401
sample_count = 0;
24012402
now = cfl_time_now();
@@ -2471,10 +2472,10 @@ int pack_basic_type(struct cmt_opentelemetry_context *context,
24712472
if (context->use_cutoff == CMT_TRUE &&
24722473
check_staled_timestamp(&map->metric, now,
24732474
context->cutoff_threshold)) {
2474-
destroy_metric(metric);
24752475

24762476
/* Skip processing metrics which are staled over the threshold */
2477-
return CMT_ENCODE_OPENTELEMETRY_CUTOFF_ERROR;
2477+
cutoff = CMT_TRUE;
2478+
continue;
24782479
}
24792480

24802481
result = append_sample_to_metric(context,
@@ -2506,6 +2507,10 @@ int pack_basic_type(struct cmt_opentelemetry_context *context,
25062507

25072508
(*metric_index)++;
25082509

2510+
if (cutoff == CMT_TRUE) {
2511+
return CMT_ENCODE_OPENTELEMETRY_CUTOFF_ERROR;
2512+
}
2513+
25092514
return result;
25102515
}
25112516

@@ -2631,10 +2636,9 @@ cfl_sds_t cmt_encode_opentelemetry_create_with_cutoff_opts(struct cmt *cmt,
26312636
}
26322637
}
26332638

2634-
if (result == CMT_ENCODE_OPENTELEMETRY_SUCCESS) {
2639+
if (metric_index > 0) {
26352640
buf = render_opentelemetry_context_to_sds(context);
2636-
}
2637-
else if (result == CMT_ENCODE_OPENTELEMETRY_CUTOFF_ERROR) {
2641+
} else {
26382642
buf = NULL;
26392643
}
26402644

0 commit comments

Comments
 (0)