mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 07:06:32 +08:00
reporting incomplete trace when timeout
This commit is contained in:
@@ -107,7 +107,8 @@ int modbus_stack_recv(modbus_stack_t *stack, uint8_t slave_id,
|
||||
neu_otel_trace_ctx trace = NULL;
|
||||
neu_otel_scope_ctx scope = NULL;
|
||||
if (neu_otel_data_is_started()) {
|
||||
trace = neu_otel_find_trace((void *) (intptr_t) stack->read_seq);
|
||||
trace = neu_otel_find_trace(
|
||||
(void *) ((intptr_t) stack + (intptr_t) stack->read_seq));
|
||||
if (trace) {
|
||||
char new_span_id[36] = { 0 };
|
||||
neu_otel_new_span_id(new_span_id);
|
||||
@@ -374,8 +375,10 @@ int modbus_stack_read(modbus_stack_t *stack, uint8_t slave_id,
|
||||
neu_otel_trace_ctx trace = NULL;
|
||||
neu_otel_scope_ctx scope = NULL;
|
||||
trace = neu_otel_create_trace(
|
||||
new_trace_id, (void *) (intptr_t) stack->read_seq, 0,
|
||||
trace_state);
|
||||
new_trace_id,
|
||||
(void *) ((intptr_t) stack +
|
||||
(intptr_t) stack->read_seq),
|
||||
0, trace_state);
|
||||
if (trace) {
|
||||
scope = neu_otel_add_span(trace);
|
||||
neu_otel_scope_set_span_name(scope, "driver cmd send");
|
||||
|
||||
+15
-8
@@ -1072,25 +1072,32 @@ static int otel_timer_cb(void *data)
|
||||
|
||||
HASH_ITER(hh, traces_table, el, tmp)
|
||||
{
|
||||
bool should_send = false;
|
||||
bool is_timeout = false;
|
||||
|
||||
if (neu_time_ms() - el->ctx->ts >= TRACE_TIME_OUT) {
|
||||
nlog_debug("trace:%s time out", (char *) el->ctx->trace_id);
|
||||
HASH_DEL(traces_table, el);
|
||||
neu_otel_free_trace(el->ctx);
|
||||
free(el);
|
||||
should_send = true;
|
||||
is_timeout = true;
|
||||
nlog_debug("trace:%s time out, reporting incomplete trace",
|
||||
(char *) el->ctx->trace_id);
|
||||
} else if (el->ctx->final &&
|
||||
el->ctx->span_num ==
|
||||
el->ctx->trace_data.resource_spans[0]
|
||||
->scope_spans[0]
|
||||
->n_spans &&
|
||||
el->ctx->expected_span_num <= 0) {
|
||||
int data_size = neu_otel_trace_pack_size(el->ctx);
|
||||
should_send = true;
|
||||
}
|
||||
|
||||
uint8_t *data_buf = calloc(1, data_size);
|
||||
if (should_send) {
|
||||
int data_size = neu_otel_trace_pack_size(el->ctx);
|
||||
uint8_t *data_buf = calloc(1, data_size);
|
||||
neu_otel_trace_pack(el->ctx, data_buf);
|
||||
int status = neu_http_post_otel_trace(data_buf, data_size);
|
||||
free(data_buf);
|
||||
nlog_debug("send trace:%s status:%d", (char *) el->ctx->trace_id,
|
||||
status);
|
||||
nlog_debug("send %strace:%s status:%d", is_timeout ? "timeout " : "",
|
||||
(char *) el->ctx->trace_id, status);
|
||||
|
||||
if (status == 200 || status == 400) {
|
||||
HASH_DEL(traces_table, el);
|
||||
neu_otel_free_trace(el->ctx);
|
||||
|
||||
Reference in New Issue
Block a user