Skip to content

Commit

Permalink
Fixes with GRPC ProcessId
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Oct 8, 2024
1 parent 3c06584 commit 7c47db1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions my-grpc-extensions/src/grpc_client_interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ impl GrpcClientInterceptor {
Self { ctx }
}

pub fn to_string(&self) -> String {
pub fn to_string(&self) -> Option<String> {
match &self.ctx {
MyTelemetryContext::Single(process_id) => process_id.to_string(),
MyTelemetryContext::Single(process_id) => Some(process_id.to_string()),
MyTelemetryContext::Multiple(ids) => {
let mut result = String::new();
let mut index = 0;
Expand All @@ -26,8 +26,9 @@ impl GrpcClientInterceptor {
index += 1;
}

result
Some(result)
}
MyTelemetryContext::Empty => None,
}
}
}
Expand All @@ -37,9 +38,12 @@ impl Interceptor for GrpcClientInterceptor {
&mut self,
mut request: tonic::Request<()>,
) -> Result<tonic::Request<()>, tonic::Status> {
request
.metadata_mut()
.insert("process-id", self.to_string().parse().unwrap());
if let Some(process_id) = self.to_string() {
request
.metadata_mut()
.insert("process-id", process_id.parse().unwrap());
}

Ok(request)
}
}

0 comments on commit 7c47db1

Please sign in to comment.