From 415f1824df55d8c35793c72af68742d7f999b3e2 Mon Sep 17 00:00:00 2001 From: Damien Mehala Date: Sun, 9 Jun 2024 15:05:25 +0200 Subject: [PATCH] fix: set error status on span with 5xx status code (#443) --- instrumentation/nginx/src/otel_ngx_module.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/instrumentation/nginx/src/otel_ngx_module.cpp b/instrumentation/nginx/src/otel_ngx_module.cpp index c69a545a1..5b2aa218b 100644 --- a/instrumentation/nginx/src/otel_ngx_module.cpp +++ b/instrumentation/nginx/src/otel_ngx_module.cpp @@ -545,7 +545,14 @@ ngx_int_t FinishNgxSpan(ngx_http_request_t* req) { } auto span = context->request_span; - span->SetAttribute("http.status_code", req->headers_out.status); + const auto status_code = req->headers_out.status; + span->SetAttribute("http.status_code", status_code); + + if (status_code >= 500) { + span->SetStatus(trace::StatusCode::kError); + } else { + span->SetStatus(trace::StatusCode::kOk); + } OtelNgxLocationConf* locConf = GetOtelLocationConf(req);