Skip to content

Commit 64549d7

Browse files
Fix .with_headers to support multiple k/v pairs (#2699)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent edab145 commit 64549d7

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

opentelemetry-otlp/CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## vNext
44

55
- The `OTEL_EXPORTER_OTLP_TIMEOUT`, `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`, `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT` and `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` are changed from seconds to miliseconds.
6+
- Fixed `.with_headers()` in `HttpExporterBuilder` to correctly support multiple key/value pairs. [#2699](https://github.com/open-telemetry/opentelemetry-rust/pull/2699)
67

78
## 0.28.0
89

@@ -41,7 +42,7 @@ Released 2024-Nov-11
4142
- Update `opentelemetry-http` dependency version to 0.27
4243
- Update `opentelemetry-proto` dependency version to 0.27
4344

44-
- **BREAKING**:
45+
- **BREAKING**:
4546
- ([#2217](https://github.com/open-telemetry/opentelemetry-rust/pull/2217)) **Replaced**: The `MetricsExporterBuilder` interface is modified from `with_temporality_selector` to `with_temporality` example can be seen below:
4647
Previous Signature:
4748
```rust
@@ -88,9 +89,9 @@ Released 2024-Nov-11
8889
- `MetricsExporterBuilder` -> `MetricExporterBuilder`
8990

9091
- [#2263](https://github.com/open-telemetry/opentelemetry-rust/pull/2263)
91-
Support `hyper` client for opentelemetry-otlp. This can be enabled using flag `hyper-client`.
92+
Support `hyper` client for opentelemetry-otlp. This can be enabled using flag `hyper-client`.
9293
Refer example: https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-otlp/examples/basic-otlp-http
93-
94+
9495
## v0.26.0
9596
Released 2024-Sep-30
9697

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ impl<B: HasHttpConfig> WithHttpConfig for B {
449449

450450
fn with_headers(mut self, headers: HashMap<String, String>) -> Self {
451451
// headers will be wrapped, so we must do some logic to unwrap first.
452-
self.http_client_config()
452+
let http_client_headers = self
453+
.http_client_config()
453454
.headers
454-
.iter_mut()
455-
.zip(headers)
456-
.for_each(|(http_client_headers, (key, value))| {
457-
http_client_headers.insert(key, super::url_decode(&value).unwrap_or(value));
458-
});
455+
.get_or_insert(HashMap::new());
456+
headers.into_iter().for_each(|(key, value)| {
457+
http_client_headers.insert(key, super::url_decode(&value).unwrap_or(value));
458+
});
459459
self
460460
}
461461
}
@@ -671,11 +671,14 @@ mod tests {
671671
}
672672

673673
#[test]
674-
fn test_http_exporter_builder_with_header() {
674+
fn test_http_exporter_builder_with_headers() {
675675
use std::collections::HashMap;
676676
// Arrange
677677
let initial_headers = HashMap::from([("k1".to_string(), "v1".to_string())]);
678-
let extra_headers = HashMap::from([("k2".to_string(), "v2".to_string())]);
678+
let extra_headers = HashMap::from([
679+
("k2".to_string(), "v2".to_string()),
680+
("k3".to_string(), "v3".to_string()),
681+
]);
679682
let expected_headers = initial_headers.iter().chain(extra_headers.iter()).fold(
680683
HashMap::new(),
681684
|mut acc, (k, v)| {

0 commit comments

Comments
 (0)