@@ -21,7 +21,6 @@ use crate::{
21
21
provider:: convert_span_to_provider_format,
22
22
utils:: { get_llm_usage_for_span, record_labels_to_db_and_ch, record_span_to_db} ,
23
23
} ,
24
- utils:: estimate_json_size,
25
24
} ;
26
25
27
26
pub mod attributes;
@@ -39,10 +38,16 @@ pub const OBSERVATIONS_QUEUE: &str = "observations_queue";
39
38
pub const OBSERVATIONS_EXCHANGE : & str = "observations_exchange" ;
40
39
pub const OBSERVATIONS_ROUTING_KEY : & str = "observations_routing_key" ;
41
40
41
+ pub struct IngestedBytes {
42
+ pub span_bytes : usize ,
43
+ pub events_bytes : usize ,
44
+ }
45
+
42
46
pub async fn process_spans_and_events (
43
47
span : & mut Span ,
44
48
events : Vec < Event > ,
45
49
project_id : & Uuid ,
50
+ ingested_bytes : & IngestedBytes ,
46
51
db : Arc < DB > ,
47
52
clickhouse : clickhouse:: Client ,
48
53
cache : Arc < Cache > ,
@@ -120,9 +125,7 @@ pub async fn process_spans_and_events(
120
125
let _ = acker. ack ( ) . await . map_err ( |e| {
121
126
log:: error!( "Failed to ack MQ delivery (span): {:?}" , e) ;
122
127
} ) ;
123
- estimate_json_size (
124
- & serde_json:: to_value ( & span. get_attributes ( ) . attributes ) . unwrap_or_default ( ) ,
125
- )
128
+ ingested_bytes. span_bytes
126
129
}
127
130
Err ( e) => {
128
131
log:: error!(
@@ -147,7 +150,7 @@ pub async fn process_spans_and_events(
147
150
}
148
151
149
152
let recorded_events_bytes = match record_events ( db. clone ( ) , clickhouse. clone ( ) , & events) . await {
150
- Ok ( _) => estimate_json_size ( & serde_json :: to_value ( & events ) . unwrap_or_default ( ) ) ,
153
+ Ok ( _) => ingested_bytes . events_bytes ,
151
154
Err ( e) => {
152
155
log:: error!( "Failed to record events: {:?}" , e) ;
153
156
0
@@ -157,7 +160,7 @@ pub async fn process_spans_and_events(
157
160
if let Err ( e) = increment_project_spans_bytes_ingested (
158
161
& db. pool ,
159
162
& project_id,
160
- recorded_span_bytes + recorded_events_bytes ,
163
+ recorded_events_bytes + recorded_span_bytes ,
161
164
)
162
165
. await
163
166
{
0 commit comments