Add OpenTelemetry support via adding the traceparent header from $http_traceparent#340
Open
sriemer wants to merge 2 commits intoledgetech:masterfrom
Open
Add OpenTelemetry support via adding the traceparent header from $http_traceparent#340sriemer wants to merge 2 commits intoledgetech:masterfrom
traceparent header from $http_traceparent#340sriemer wants to merge 2 commits intoledgetech:masterfrom
Conversation
NGINX can be used together with OpenTelemetry (OTel) support and the `nginx-otel` module provides it. In the Observability space it is required that all HTTP request tracers in the line do trace propagation or trace forwarding at least. This is usually done by sending out an updated `traceparent` header. It contains for example a trace ID and a span ID so that the Observability backend such as Jaeger can correlate all spans to the same trace. To be able to trace HTTP requests sent from regular NGINX code and also the ones sent by LUA HTTP client code with the same NGINX tracer, the LUA HTTP client code has to be extended to add the `traceparent` header from `ngx.var.http_traceparent`. The value of this `$http_traceparent` variable is set by the `nginx-otel` module. It updates the span ID inside the `traceparent` value if NGINX directive `otel_trace_context propagate;` is set. So extend the `send_request()` function for this, because it already adds other headers as well and is used when calling `request_uri()` as well. Check if the `traceparent` header is not set yet but `ngx.var.http_traceparent` is set and set it from there. Also add a code comment describing this as well. References: * https://github.com/nginxinc/nginx-otel * https://nginx.org/en/docs/ngx_otel_module.html * https://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_
The new traceparent header auto-injection from
`ngx.var.http_traceparent` has to be tested.
So add a new file `t/21-traceparent-header.t` containing 3 tests
for that:
* TEST 1: No traceparent header is set
* TEST 2: The traceparent header is correctly added when
ngx.var.http_traceparent is used
* TEST 3: The traceparent header is not modified from
ngx.var.http_traceparent if it is already set
Use an NGINX directive `set $http_traceparent '00-000...-01';` in
front of the LUA block to emulate `nginx-otel` behavior.
The case that there is a `traceparent` header added with
`request_uri()` and `ngx.var.http_traceparent` is not set, is already
covered by tests 1 and 3.
Author
Author
|
The |
Author
|
@pintsized Please review. TIA Also let me know if you need help from an experienced FOSS maintainer like me in reviewing open PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
http: Extend
send_request()with OTel supportNGINX can be used together with OpenTelemetry (OTel) support
and the
nginx-otelmodule provides it. In the Observabilityspace it is required that all HTTP request tracers in the line
do trace propagation or trace forwarding at least. This is usually
done by sending out an updated
traceparentheader. It contains forexample a trace ID and a span ID so that the Observability backend
such as Jaeger can correlate all spans to the same trace.
To be able to trace HTTP requests sent from regular NGINX code and
also the ones sent by LUA HTTP client code with the same NGINX tracer,
the LUA HTTP client code has to be extended to add the
traceparentheader from
ngx.var.http_traceparent. The value of this$http_traceparentvariable is set by thenginx-otelmodule. Itupdates the span ID inside the
traceparentvalue if NGINX directiveotel_trace_context propagate;is set.So extend the
send_request()function for this, because it alreadyadds other headers as well and is used when calling
request_uri()as well.
Check if the
traceparentheader is not set yet butngx.var.http_traceparentis set and set it from there.Also add a code comment describing this as well.
References:
t: Add 3 traceparent header tests
The new traceparent header auto-injection from
ngx.var.http_traceparenthas to be tested.So add a new file
t/21-traceparent-header.tcontaining 3 testsfor that:
ngx.var.http_traceparent is used
ngx.var.http_traceparent if it is already set
Use an NGINX directive
set $http_traceparent '00-000...-01';infront of the LUA block to emulate
nginx-otelbehavior.The case that there is a
traceparentheader added withrequest_uri()andngx.var.http_traceparentis not set, is alreadycovered by tests 1 and 3.