diff options
| author | Ava Hahn <a.hahn@f5.com> | 2025-01-06 18:47:47 -0800 |
|---|---|---|
| committer | Ava Hahn <110854134+avahahn@users.noreply.github.com> | 2025-01-08 11:31:06 -0800 |
| commit | d699fb9da6858b57d713a0567b4a9fbe47574cbd (patch) | |
| tree | f9b9b70957bc02d0ce864ae28c6ea0b2b7bdc920 | |
| parent | 706b994fb586330828ff7d445c60e39390cc35c6 (diff) | |
| download | unit-d699fb9da6858b57d713a0567b4a9fbe47574cbd.tar.gz unit-d699fb9da6858b57d713a0567b4a9fbe47574cbd.tar.bz2 | |
otel: fix segfaults when otel not configured
This commit adds NULL checks for the request->otel object that
were missed in the Traceparent and Tracestate routines.
Closes: https://github.com/nginx/unit/issues/1523
Closes: https://github.com/nginx/unit/issues/1526
Fixes: 9d3dcb800 ("otel: add build tooling to include otel code")
Signed-off-by: Ava Hahn <a.hahn@f5.com>
| -rw-r--r-- | src/nxt_otel.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/nxt_otel.c b/src/nxt_otel.c index eea12e24..ef796a7c 100644 --- a/src/nxt_otel.c +++ b/src/nxt_otel.c @@ -311,17 +311,13 @@ nxt_otel_test_and_call_state(nxt_task_t *task, nxt_http_request_t *r) void nxt_otel_request_error_path(nxt_task_t *task, nxt_http_request_t *r) { - if (r->otel->trace == NULL) { + if (r->otel == NULL || r->otel->trace == NULL) { return; } // response headers have been cleared nxt_otel_propagate_header(task, r); - - // collect span immediately - if (r->otel) { - nxt_otel_state_transition(r->otel, NXT_OTEL_COLLECT_STATE); - } + nxt_otel_state_transition(r->otel, NXT_OTEL_COLLECT_STATE); nxt_otel_test_and_call_state(task, r); } @@ -344,6 +340,9 @@ nxt_otel_parse_traceparent(void *ctx, nxt_http_field_t *field, uintptr_t data) */ r = ctx; + if (r->otel == NULL) { + return NXT_OK; + } if (field->value_length != NXT_OTEL_TRACEPARENT_LEN) { goto error_state; @@ -391,6 +390,10 @@ nxt_otel_parse_tracestate(void *ctx, nxt_http_field_t *field, uintptr_t data) s.start = field->value; r = ctx; + if (r->otel == NULL) { + return NXT_OK; + } + r->otel->trace_state = s; /* |
