From 0d5314dbcb05d5954651c0dcaf7a12eddfa8a92b Mon Sep 17 00:00:00 2001 From: Aryan Ishan Date: Tue, 5 Dec 2023 10:42:04 +0000 Subject: [PATCH] changes for unable to start proxy automatically error --- instrumentation/otel-webserver-module/README.md | 1 + .../src/nginx/ngx_http_opentelemetry_module.c | 12 +++++++++++- .../src/nginx/ngx_http_opentelemetry_module.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/instrumentation/otel-webserver-module/README.md b/instrumentation/otel-webserver-module/README.md index cc836759..8e17c46c 100644 --- a/instrumentation/otel-webserver-module/README.md +++ b/instrumentation/otel-webserver-module/README.md @@ -176,6 +176,7 @@ Currently, Nginx Webserver module monitores some fixed set of modules, which get |*NginxModuleRequestHeaders* | | OPTIONAL: Specify the request headers to be captured in the span attributes. The headers are Case-Sensitive and should be comma-separated. e.g.```NginxModuleRequestHeaders Accept-Charset,Accept-Encoding,User-Agent;```| |*NginxModuleResponseHeaders* | | OPTIONAL: Specify the response headers to be captured in the span attributes. The headers are Case-Sensitive and should be comma-separated. e.g.```NginxModuleResponseHeaders Content-Length,Content-Type;```| |*NginxModuleOtelExporterOtlpHeaders* | | OPTIONAL: OTEL exporter headers like Meta data related exposrted end point. a list of key value pairs, and these are expected to be represented in a format matching to the W3C Correlation-Context, except that additional semi-colon delimited metadata is not supported, i.e.: key1=value1,key2=value2.| +|*NginxTrustIncomingSpans* | ON | OPTIONAL: Specify if you want to correlate Nginx instrumented traces and spans with incoming requests.| ### Build and Installation #### Prerequisites diff --git a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c index 18bdee98..8e4d5005 100644 --- a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c +++ b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c @@ -376,6 +376,13 @@ static ngx_command_t ngx_http_opentelemetry_commands[] = { NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_opentelemetry_loc_conf_t, nginxModuleResponseHeaders), NULL}, + + { ngx_string("NginxTrustIncomingSpans"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_opentelemetry_loc_conf_t, nginxTrustIncomingSpans), + NULL}, ngx_null_command /* command termination */ }; @@ -437,6 +444,7 @@ static void* ngx_http_opentelemetry_create_loc_conf(ngx_conf_t *cf) conf->nginxModuleTraceAsError = NGX_CONF_UNSET; conf->nginxModuleOtelMaxQueueSize = NGX_CONF_UNSET; conf->nginxModuleOtelSslEnabled = NGX_CONF_UNSET; + conf->nginxTrustIncomingSpans = NGX_CONF_UNSET; return conf; } @@ -453,6 +461,8 @@ static char* ngx_http_opentelemetry_merge_loc_conf(ngx_conf_t *cf, void *parent, ngx_conf_merge_value(conf->nginxModuleTraceAsError, prev->nginxModuleTraceAsError, 0); ngx_conf_merge_value(conf->nginxModuleMaskCookie, prev->nginxModuleMaskCookie, 0); ngx_conf_merge_value(conf->nginxModuleMaskSmUser, prev->nginxModuleMaskSmUser, 0); + ngx_conf_merge_value(conf->nginxTrustIncomingSpans, prev->nginxTrustIncomingSpans, 1); + ngx_conf_merge_str_value(conf->nginxModuleOtelSpanExporter, prev->nginxModuleOtelSpanExporter, ""); ngx_conf_merge_str_value(conf->nginxModuleOtelExporterEndpoint, prev->nginxModuleOtelExporterEndpoint, ""); @@ -1637,7 +1647,7 @@ static void fillRequestPayload(request_payload* req_payload, ngx_http_request_t* for (ngx_uint_t j = 0; j < nelts; j++) { h = &header[j]; - for (int i = 0; i < headers_len; i++) { + for (int i = 0; i < headers_len && conf->nginxTrustIncomingSpans ; i++) { if (strcmp(h->key.data, httpHeaders[i]) == 0) { req_payload->propagation_headers[propagation_headers_idx].name = httpHeaders[i]; diff --git a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.h b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.h index 1d73d70e..6043b5b7 100644 --- a/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.h +++ b/instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.h @@ -103,6 +103,8 @@ typedef struct { ngx_str_t nginxModuleRequestHeaders; ngx_str_t nginxModuleResponseHeaders; ngx_str_t nginxModuleOtelExporterOtlpHeaders; + ngx_flag_t nginxTrustIncomingSpans; + } ngx_http_opentelemetry_loc_conf_t; /*