Skip to content

Commit 543e463

Browse files
committed
feat: add predicate for traces size
1 parent 4ff6298 commit 543e463

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const REPORTING_URL: &str = "https://usage-reporting.api.apollographql.com/api/i
7979
const TARGET_LOG: &str = "apollo-studio-extension";
8080
const VERSION: &str = env!("CARGO_PKG_VERSION");
8181
const RUNTIME_VERSION: &str = "Rust - No runtime version provided yet";
82+
const MAX_TRACES_SIZE: i32 = 3_500_000;
8283

8384
/// An ENUM describing the various HTTP Methods existing.
8485
#[derive(Debug, Clone)]
@@ -204,6 +205,7 @@ impl ApolloTracing {
204205
let mut hashmap: HashMap<String, TracesAndStats> =
205206
HashMap::with_capacity(batch_target + 1);
206207
let mut count = 0;
208+
let mut actual_size: i32 = 0;
207209
while let Some((name, trace)) = match Runtime::locate() {
208210
#[cfg(feature = "tokio-comp")]
209211
Runtime::Tokio => receiver.recv().await,
@@ -212,9 +214,6 @@ impl ApolloTracing {
212214
} {
213215
trace!(target: TARGET_LOG, message = "Trace registered", trace = ?trace, name = ?name);
214216

215-
let size = size_of::<TracesAndStats>();
216-
info!(target: "size-ext", size = ?size);
217-
218217
// We bufferize traces and create a Full Report every X
219218
// traces
220219
match hashmap.get_mut(&name) {
@@ -230,10 +229,12 @@ impl ApolloTracing {
230229
}
231230

232231
count += 1;
232+
actual_size += size_of::<TracesAndStats>() as i32;
233233

234-
if count > batch_target {
234+
if count > batch_target || actual_size > MAX_TRACES_SIZE {
235235
use tracing::{field, field::debug, span, Level};
236236

237+
actual_size = 0;
237238
let span_batch = span!(
238239
Level::DEBUG,
239240
"Sending traces by batch to Apollo Studio",

0 commit comments

Comments
 (0)