Skip to content

Commit 786c3ad

Browse files
authored
Downstream bug fix (#204)
* Downstream bug fix * Indentation * Garbage collection * Removing unused variable
1 parent f6e5874 commit 786c3ad

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

instrumentation/otel-webserver-module/src/nginx/ngx_http_opentelemetry_module.c

+31-3
Original file line numberDiff line numberDiff line change
@@ -721,15 +721,42 @@ static APPD_SDK_STATUS_CODE otel_startInteraction(ngx_http_request_t* r, const c
721721

722722
static void otel_payload_decorator(ngx_http_request_t* r, APPD_SDK_ENV_RECORD* propagationHeaders, int count)
723723
{
724+
ngx_list_part_t *part;
725+
ngx_table_elt_t *header;
724726
ngx_table_elt_t *h;
725727
ngx_http_header_t *hh;
726728
ngx_http_core_main_conf_t *cmcf;
729+
ngx_uint_t nelts;
730+
731+
part = &r->headers_in.headers.part;
732+
header = (ngx_table_elt_t*)part->elts;
733+
nelts = part->nelts;
727734

728735
for(int i=0; i<count; i++){
729-
h = ngx_list_push(&r->headers_in.headers);
730-
if(h == NULL){
731-
return;
736+
737+
int header_found=0;
738+
for(ngx_uint_t j = 0; j<nelts; j++){
739+
h = &header[j];
740+
if(strcmp(httpHeaders[i], h->key.data)==0){
741+
742+
header_found=1;
743+
744+
if(h->key.data)
745+
ngx_pfree(r->pool, h->key.data);
746+
if(h->value.data)
747+
ngx_pfree(r->pool, h->value.data);
748+
749+
break;
750+
}
751+
}
752+
if(header_found==0)
753+
{
754+
h = ngx_list_push(&r->headers_in.headers);
732755
}
756+
757+
if(h == NULL )
758+
return;
759+
733760
h->key.len = strlen(propagationHeaders[i].name);
734761
h->key.data = ngx_pcalloc(r->pool, sizeof(char)*((h->key.len)+1));
735762
strcpy(h->key.data, propagationHeaders[i].name);
@@ -750,6 +777,7 @@ static void otel_payload_decorator(ngx_http_request_t* r, APPD_SDK_ENV_RECORD* p
750777
}
751778

752779
ngx_writeTrace(r->connection->log, __func__, "Value : %s", propagationHeaders[i].value);
780+
753781
}
754782

755783
ngx_http_otel_handles_t* ctx = ngx_http_get_module_ctx(r, ngx_http_opentelemetry_module);

0 commit comments

Comments
 (0)