-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(opentelemetry source): add support for enriching logs with HTTP headers #21674
feat(opentelemetry source): add support for enriching logs with HTTP headers #21674
Conversation
@@ -103,12 +114,69 @@ pub(crate) fn build_warp_filter( | |||
log_filters.or(trace_filters).unify().boxed() | |||
} | |||
|
|||
fn enrich_events( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is similar to SimpleHttpSource::enrich_events
, but it only injects headers into the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the code blocks that injects the headers are identical (except for the source names). I think it would be nice to convert this into a common function and move it to a new file src/sources/util/http_common.rs
.
src/sources/opentelemetry/http.rs
Outdated
|
||
use crate::http::{KeepaliveConfig, MaxConnectionAgeLayer}; | ||
use crate::sources::http_server::{HttpConfigParamKind, SimpleHttpConfig}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure if it's OK to use types from the source::http_server
module here, but other sources (e.g. heroku_logs
) also do it, so I assumed it is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also move HttpConfigParamKind
into the common file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided against making this change for now, as it touches a number of unrelated files and it wasn't super clear which common file to move this type to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jblazquez, thank you for this contribution!
src/sources/opentelemetry/http.rs
Outdated
headers_config.get(header_name).map(HeaderValue::as_bytes); | ||
|
||
log_namespace.insert_source_metadata( | ||
SimpleHttpConfig::NAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with OpentelemetryConfig
(or this can also resolved by the refactoring I suggested above).
@@ -103,12 +114,69 @@ pub(crate) fn build_warp_filter( | |||
log_filters.or(trace_filters).unify().boxed() | |||
} | |||
|
|||
fn enrich_events( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the code blocks that injects the headers are identical (except for the source names). I think it would be nice to convert this into a common function and move it to a new file src/sources/util/http_common.rs
.
@pront, thank you for the review. Now that I'm more confident about these changes, I reworked the PR to address your feedback:
In addition to the commits above, I also added the following commit that extends this PR to also bring support for the
|
src/sources/opentelemetry/http.rs
Outdated
let remote_addr = conn.peer_addr(); | ||
let remote_addr_ref = enable_source_ip.then_some(remote_addr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following is preferable because it's Some
only enable_source_ip
is true
:
let remote_addr = conn.peer_addr(); | |
let remote_addr_ref = enable_source_ip.then_some(remote_addr); | |
let remote_addr = enable_source_ip.then(|| conn.peer_addr()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, if I come back to this work to add host_key
to opentelemetry
I will do this. I had copied what the http_server
source did.
@@ -0,0 +1,3 @@ | |||
The `opentelemetry` source can now be configured to enrich log events with the source IP and any HTTP headers received in the OTLP/HTTP request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also mention that now a host_key
can be specified.
Note, I am skeptical about the connection of the host_key
with source_ip
. I understand there's precedence in other sources but I can see an argument in favor of making it a different setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit ea5c56f mentioned this, but I reverted that commit to reduce the scope of this PR, since you said you were not sure that host_key
should mean source_ip
.
src/sources/opentelemetry/http.rs
Outdated
if let Some(remote_addr_inner) = remote_addr_ref.as_ref() { | ||
request.extensions_mut().insert(*remote_addr_inner); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Some(remote_addr_inner) = remote_addr_ref.as_ref() { | |
request.extensions_mut().insert(*remote_addr_inner); | |
} | |
if let Some(addr) = remote_addr { | |
request.extensions_mut().insert(addr); | |
} |
src/sources/opentelemetry/tests.rs
Outdated
.unwrap() | ||
.is_timestamp()); | ||
assert_eq!( | ||
meta.get(path!("opentelemetry", "host")).unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this to be remote_ip
. I think this is also broken in http_server
because we hardcode path!("host")
when enriching events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wondered this, but I assumed it was intentional that - when using log namespacing - the source IP was always under path!("host")
and that the host_key
configuration was only for the legacy namespace.
But you bring up some good questions about the behavior of this setting, so I reverted the host_key
change from this PR.
Thank you @jblazquez, much appreciated 👍 Adding the |
ea5c56f
to
0bf233c
Compare
@pront Appreciate the review! You brought up some good questions about how Let me know if there are other changes needed. Thanks! |
Sounds great. Will review again today. If you are still interested in adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jblazquez!
Summary
This PR adds a new
http.headers
configuration to theopentelemetry
source, which injects HTTP headers received in the OTLP/HTTP request into the log events, similarly to howhttp_server
does it. Please see #21673 for the motivation behind this change.This is my first contribution to Vector, so I'm not sure whether the changes in this PR are in the right form to be accepted. I wanted to create the PR to show other contributors the proposed implementation, but I'm open to different approaches.
Change Type
Is this a breaking change?
How did you test this PR?
Added unit tests.
Also tested with an existing OTEL processing pipeline, replacing an existing
http_server
source (see below) with anopentelemetry
source using the newhttp.headers
config from this change.Also ran a
wrk
load test to verify that performance is much higher with this solution than with anhttp_source
that looks like this:See the linked issue (#21673) for more info on the performance impact of this new feature.
Does this PR include user facing changes?
Checklist
References
Closes: #21673