diff options
| author | Ava Hahn <a.hahn@f5.com> | 2025-01-06 18:47:47 -0800 |
|---|---|---|
| committer | Konstantin Pavlov <pavlov.konstantin@gmail.com> | 2025-01-10 13:01:46 -0800 |
| commit | 43130a58c7189384793e89c6f31b3d472a3bbc2d (patch) | |
| tree | c20c8fe57d3215c99cc5ac9d70e309b195566f6b /src | |
| parent | 8b1959f1185ea34df5d361ff5dcac8fdd1342046 (diff) | |
| download | unit-43130a58c7189384793e89c6f31b3d472a3bbc2d.tar.gz unit-43130a58c7189384793e89c6f31b3d472a3bbc2d.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>
Diffstat (limited to 'src')
| -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; /* |
