Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/nxt_otel.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ nxt_otel_propagate_header(nxt_task_t *task, nxt_http_request_t *r)
* if we didn't inherit a trace id then we need to add the
* traceparent header to the request
*/
} else if (r->otel->trace_id == NULL) {
} else {

nxt_otel_rs_copy_traceparent(traceval, r->otel->trace);

Expand All @@ -92,15 +92,6 @@ nxt_otel_propagate_header(nxt_task_t *task, nxt_http_request_t *r)

nxt_otel_rs_add_event_to_trace(r->otel->trace,
&traceparent_name, &traceparent);

/*
* potentially nxt_http_request_error called before headers
* finished parsing
*/
} else {
nxt_log(task, NXT_LOG_DEBUG,
"not propagating tracing headers for missing trace");
return;
}

f = nxt_list_add(r->resp.fields);
Expand Down Expand Up @@ -311,17 +302,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);
}

Expand All @@ -344,6 +331,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;
Expand Down Expand Up @@ -391,6 +381,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
Loading