Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate opentelemetry tracing headers in requests to limitador #49

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion src/filter/http_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Filter {
pub context_id: u32,
pub config: Rc<FilterConfig>,
pub response_headers_to_add: Vec<(String, String)>,
pub tracing_headers: Vec<(String, String)>,
}

impl Filter {
Expand Down Expand Up @@ -51,11 +52,17 @@ impl Filter {

let rl_req_serialized = Message::write_to_bytes(&rl_req).unwrap(); // TODO(rahulanand16nov): Error Handling

let rl_tracing_headers = self
.tracing_headers
.iter()
.map(|(header, value)| (header.as_str(), value.as_bytes()))
.collect();

match self.dispatch_grpc_call(
rlp.service.as_str(),
RATELIMIT_SERVICE_NAME,
RATELIMIT_METHOD_NAME,
Vec::new(),
rl_tracing_headers,
Some(&rl_req_serialized),
Duration::from_secs(5),
) {
Expand Down Expand Up @@ -207,6 +214,15 @@ impl HttpContext for Filter {
fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
info!("on_http_request_headers #{}", self.context_id);

let req_headers = self.get_http_request_headers();
for (header, value) in req_headers.iter() {
match header.as_str() {
"traceparent" | "tracestate" | "baggage" => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.get_http_request_headers returns lowercase header names? in other words, if the header is TraceParent, is the value captured? According to https://w3c.github.io/trace-context/#traceparent-header

The header name is [ASCII case-insensitive](https://infra.spec.whatwg.org/#ascii-case-insensitive). That is, TRACEPARENT, TraceParent, and traceparent are considered the same header. The header name is a single word; it does not contain any delimiters such as a hyphen.

Copy link
Member Author

@adam-cattermole adam-cattermole Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep from what I could tell no matter the provided format the headers were retrieved in lowercase - perhaps due to this https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/header_casing

I could add a .to_lowercase() before the match for safety in case though (perhaps this preserve case formatter causes the headers to no longer be lowercase when received by wasm shim). Also considering moving the three header strings out to constants

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's only used there, no need for a constant.

self.tracing_headers.push((header.clone(), value.clone()))
}
_ => (),
}
}
match self
.config
.index
Expand Down
1 change: 1 addition & 0 deletions src/filter/root_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl RootContext for FilterRoot {
context_id,
config: Rc::clone(&self.config),
response_headers_to_add: Vec::default(),
tracing_headers: Vec::default(),
}))
}

Expand Down
Loading