From b9066210ac378a6255c1e3de5fc01ee29904a05c Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Wed, 23 Oct 2024 16:30:39 -0700 Subject: otel: add header parsing and test call state Enables Unit to parse the tracestate and traceparent headers and add it to the list, as well as calls to nxt_otel_test_and_call_state. Signed-off-by: Ava Hahn Signed-off-by: Gabor Javorszky --- src/nxt_h1proto.c | 9 +++++++++ src/nxt_http_request.c | 4 ++++ src/nxt_otel.h | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index 48c2697b..9a9ad553 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -178,6 +178,10 @@ static nxt_http_field_proc_t nxt_h1p_fields[] = { { nxt_string("Content-Length"), &nxt_http_request_content_length, 0 }, { nxt_string("Authorization"), &nxt_http_request_field, offsetof(nxt_http_request_t, authorization) }, +#if (NXT_HAVE_OTEL) + { nxt_string("Traceparent"), &nxt_otel_parse_traceparent, 0 }, + { nxt_string("Tracestate"), &nxt_otel_parse_tracestate, 0 }, +#endif }; @@ -518,6 +522,9 @@ nxt_h1p_conn_request_init(nxt_task_t *task, void *obj, void *data) h1p->parser.discard_unsafe_fields = skcf->discard_unsafe_fields; nxt_h1p_conn_request_header_parse(task, c, h1p); + + NXT_OTEL_TRACE(); + return; } @@ -1332,6 +1339,8 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r, nxt_debug(task, "h1p request header send"); + NXT_OTEL_TRACE(); + r->header_sent = 1; h1p = r->proto.h1; n = r->status; diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c index 417b5a39..722197b8 100644 --- a/src/nxt_http_request.c +++ b/src/nxt_http_request.c @@ -322,6 +322,8 @@ nxt_http_request_start(nxt_task_t *task, void *obj, void *data) r = obj; + NXT_OTEL_TRACE(); + r->state = &nxt_http_request_body_state; skcf = r->conf->socket_conf; @@ -593,6 +595,8 @@ nxt_http_request_ready(nxt_task_t *task, void *obj, void *data) r = obj; action = r->conf->socket_conf->action; + NXT_OTEL_TRACE(); + if (r->chunked) { ret = nxt_http_request_chunked_transform(r); if (nxt_slow_path(ret != NXT_OK)) { diff --git a/src/nxt_otel.h b/src/nxt_otel.h index f5a2de8b..112f054c 100644 --- a/src/nxt_otel.h +++ b/src/nxt_otel.h @@ -9,6 +9,13 @@ #include +#if (NXT_HAVE_OTEL) +#define NXT_OTEL_TRACE() nxt_otel_test_and_call_state(task, r) +#else +#define NXT_OTEL_TRACE() +#endif + + #if (NXT_HAVE_OTEL) extern void nxt_otel_rs_send_trace(void *trace); extern void * nxt_otel_rs_get_or_create_trace(u_char *trace_id); -- cgit