Skip to content

Commit

Permalink
otel: fix segfaults when otel not configured
Browse files Browse the repository at this point in the history
This commit adds null checks for the request->otel object that
were missed in the Traceparent and Tracestate routines. This
fix solves issues 1526 and 1523

Signed-off-by: Ava Hahn <[email protected]>
  • Loading branch information
avahahn committed Jan 7, 2025
1 parent 706b994 commit b7aad93
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/nxt_otel.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ 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;
}

Expand Down Expand Up @@ -345,6 +345,11 @@ nxt_otel_parse_traceparent(void *ctx, nxt_http_field_t *field, uintptr_t data)

r = ctx;

// opentelemetry unconfigured
if (r->otel == NULL) {
return NXT_OK;
}

if (field->value_length != NXT_OTEL_TRACEPARENT_LEN) {
goto error_state;
}
Expand Down Expand Up @@ -391,6 +396,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;

/*
Expand Down

0 comments on commit b7aad93

Please sign in to comment.