Skip to content

Commit d699fb9

Browse files
committed
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: #1523 Closes: #1526 Fixes: 9d3dcb8 ("otel: add build tooling to include otel code") Signed-off-by: Ava Hahn <[email protected]>
1 parent 706b994 commit d699fb9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/nxt_otel.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,13 @@ nxt_otel_test_and_call_state(nxt_task_t *task, nxt_http_request_t *r)
311311
void
312312
nxt_otel_request_error_path(nxt_task_t *task, nxt_http_request_t *r)
313313
{
314-
if (r->otel->trace == NULL) {
314+
if (r->otel == NULL || r->otel->trace == NULL) {
315315
return;
316316
}
317317

318318
// response headers have been cleared
319319
nxt_otel_propagate_header(task, r);
320-
321-
// collect span immediately
322-
if (r->otel) {
323-
nxt_otel_state_transition(r->otel, NXT_OTEL_COLLECT_STATE);
324-
}
320+
nxt_otel_state_transition(r->otel, NXT_OTEL_COLLECT_STATE);
325321
nxt_otel_test_and_call_state(task, r);
326322
}
327323

@@ -344,6 +340,9 @@ nxt_otel_parse_traceparent(void *ctx, nxt_http_field_t *field, uintptr_t data)
344340
*/
345341

346342
r = ctx;
343+
if (r->otel == NULL) {
344+
return NXT_OK;
345+
}
347346

348347
if (field->value_length != NXT_OTEL_TRACEPARENT_LEN) {
349348
goto error_state;
@@ -391,6 +390,10 @@ nxt_otel_parse_tracestate(void *ctx, nxt_http_field_t *field, uintptr_t data)
391390
s.start = field->value;
392391

393392
r = ctx;
393+
if (r->otel == NULL) {
394+
return NXT_OK;
395+
}
396+
394397
r->otel->trace_state = s;
395398

396399
/*

0 commit comments

Comments
 (0)