Add service to stream custom otel traces to otel-collector (#262)

This commit is contained in:
Adil Hafeez 2024-11-12 11:09:40 -08:00 committed by GitHub
parent d87105882b
commit 30647fd508
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 368 additions and 9 deletions

View file

@ -33,7 +33,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::str::FromStr;
use std::time::Duration;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
#[derive(Debug, Clone)]
pub enum ResponseHandlerType {
@ -77,6 +77,8 @@ pub struct StreamContext {
pub chat_completions_request: Option<ChatCompletionsRequest>,
pub prompt_guards: Rc<PromptGuards>,
pub request_id: Option<String>,
pub start_upstream_llm_request_time: u128,
pub time_to_first_token: Option<u128>,
pub traceparent: Option<String>,
pub tracing: Rc<Option<Tracing>>,
}
@ -113,6 +115,8 @@ impl StreamContext {
request_id: None,
traceparent: None,
tracing,
start_upstream_llm_request_time: 0,
time_to_first_token: None,
}
}
@ -1003,6 +1007,11 @@ impl StreamContext {
};
debug!("archgw => llm request: {}", llm_request_str);
self.start_upstream_llm_request_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos();
self.set_http_request_body(0, self.request_body_size, &llm_request_str.into_bytes());
self.resume_http_request();
}