tracing_actions_otlp/
header_interceptor.rs1use tonic::metadata::{AsciiMetadataKey, AsciiMetadataValue};
2
3use crate::RequestInterceptor;
4
5struct HeaderInterceptor {
6 headers: Vec<(AsciiMetadataKey, AsciiMetadataValue)>,
7}
8impl RequestInterceptor for HeaderInterceptor {
9 fn intercept_request(
10 &self,
11 request: &mut tonic::Request<
12 crate::proto::opentelemetry::collector::trace::v1::ExportTraceServiceRequest,
13 >,
14 ) {
15 let metadata = request.metadata_mut();
16 for (name, value) in &self.headers {
17 metadata.insert(name, value.clone());
18 }
19 }
20}
21
22pub fn header_interceptor(
26 headers: Vec<(&'static str, String)>,
27) -> Option<Box<dyn RequestInterceptor>> {
28 Some(Box::new(HeaderInterceptor {
29 headers: headers
30 .into_iter()
31 .map(|(k, v)| {
32 (
33 AsciiMetadataKey::from_static(k),
34 v.try_into().expect("headers must be ascii values"),
35 )
36 })
37 .collect(),
38 }))
39}