-
Notifications
You must be signed in to change notification settings - Fork 457
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
OTLP tonic metadata from env variable #1377
OTLP tonic metadata from env variable #1377
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1377 +/- ##
=======================================
+ Coverage 55.4% 55.6% +0.2%
=======================================
Files 147 145 -2
Lines 18083 18022 -61
=======================================
+ Hits 10021 10037 +16
+ Misses 8062 7985 -77 ☔ View full report in Codecov by Sentry. |
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 for the contribution!
} | ||
for (key, value) in parse_header_string(input) { | ||
if let (Ok(key), Ok(value)) = (HeaderName::from_str(key), HeaderValue::from_str(value)) { | ||
headers.insert(key, value); |
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.
Overall, I love the cleanup. I wonder if one more little step here could eliminate the for loop by leveraging the std::iter::Extend
trait that HashMap
implements? Something like:
headers.extend(
parse_header_string(input)
.filter_map(|(k,v)| {
let key = HeaderName::from_str(k)?;
let value = HeaderName::from_str(v)?;
Some((key, value))
)
);
(I may have the .filter_map
lambda totally wrong, but hopefully the gist comes across.
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.
Good suggestion, I updated it
fn add_header_from_string(input: &str, headers: &mut HashMap<HeaderName, HeaderValue>) {
headers.extend(parse_header_string(input).filter_map(|(key, value)| {
Some((
HeaderName::from_str(key).ok()?,
HeaderValue::from_str(value).ok()?,
))
}));
}
Both |
🤕 latest tests fail. |
There seem to be random failures during |
I finally reverted to use For fn add_headers_from_string(input: &str, headers: &mut HashMap<String, String>) {
headers.extend(
parse_header_string(&input).map(|(key, value)| (key.to_string(), value.to_string())),
);
} |
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.
Nicely done. Thanks.
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 again!
Fixes #1336
Changes
As per the specs, the custom headers for OTLP exporter can be specified through env variables -
OTEL_EXPORTER_OTLP_HEADERS
,OTEL_EXPORTER_OTLP_TRACES_HEADERS
,OTEL_EXPORTER_OTLP_METRICS_HEADERS
.This PR completes the work already done in PR #1290 adding support for tonic metadata
To reproduce the same behavior as http exporter, the env-variable takes precedence (as discussed in open-telemetry/opentelemetry-rust-contrib#10)
I moved common code for http and tonic exporters in
exporter/mod.rs
(function to parse header from string and test helper to run tests with isolated env variables)I wanted to minimize the changes but maybe it should be a good idea to use a crate like https://crates.io/crates/temp-env for environment related testing
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes