From 6dc46959743c666b53bbe211f1e1c917f475cc1b Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Fri, 21 Feb 2025 13:25:02 +0800 Subject: [PATCH] otel:remove duplicate ctx --- src/otel/otel_manager.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/otel/otel_manager.c b/src/otel/otel_manager.c index 53f9c11a..fefd92e2 100644 --- a/src/otel/otel_manager.c +++ b/src/otel/otel_manager.c @@ -186,6 +186,20 @@ void neu_otel_free_span(Opentelemetry__Proto__Trace__V1__Span *span) neu_otel_trace_ctx neu_otel_create_trace(const char *trace_id, void *req_ctx, uint32_t flags, const char *tracestate) { + trace_ctx_table_ele_t *find = NULL; + + pthread_mutex_lock(&table_mutex); + + HASH_FIND(hh, traces_table, &req_ctx, sizeof(req_ctx), find); + + if (find) { + HASH_DEL(traces_table, find); + neu_otel_free_trace(find->ctx); + free(find); + } + + pthread_mutex_unlock(&table_mutex); + trace_ctx_t *ctx = calloc(1, sizeof(trace_ctx_t)); opentelemetry__proto__trace__v1__traces_data__init(&ctx->trace_data); strncpy((char *) ctx->trace_id, trace_id, 64);