Skip to content

Commit edba0d9

Browse files
committed
fix: do not send over than 100 traces
1 parent a2aa4a2 commit edba0d9

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/lib.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +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;
82+
const MAX_TRACES: usize = 100;
8383

8484
/// An ENUM describing the various HTTP Methods existing.
8585
#[derive(Debug, Clone)]
@@ -175,8 +175,8 @@ impl ApolloTracing {
175175
/// * graph_ref - <ref>@<variant> Graph reference with variant
176176
/// * release_name - Your release version or release name from Git for example
177177
/// * batch_target - The number of traces to batch, it depends on your traffic, if you have.
178-
/// When the accumulated traces are ~4Mb, they are sent event if we did not reach the
179-
/// batch_target limit.
178+
/// You cannot send batch traces with a size over 4Mb, so we batch every 100 traces even if
179+
/// your batch_target is set higher.
180180
pub fn new(
181181
authorization_token: String,
182182
hostname: String,
@@ -206,7 +206,6 @@ impl ApolloTracing {
206206
let mut hashmap: HashMap<String, TracesAndStats> =
207207
HashMap::with_capacity(batch_target + 1);
208208
let mut count = 0;
209-
let mut actual_size: i32 = 0;
210209
while let Some((name, trace)) = match Runtime::locate() {
211210
#[cfg(feature = "tokio-comp")]
212211
Runtime::Tokio => receiver.recv().await,
@@ -224,19 +223,15 @@ impl ApolloTracing {
224223
None => {
225224
let mut trace_and_stats = TracesAndStats::new();
226225
trace_and_stats.mut_trace().push(trace);
227-
228-
info!(target: "size-ext-2", size = ?size_of_val(&trace_and_stats));
229226
hashmap.insert(name, trace_and_stats);
230227
}
231228
}
232229

233230
count += 1;
234-
actual_size += size_of::<TracesAndStats>() as i32;
235231

236-
if count > batch_target || actual_size > MAX_TRACES_SIZE {
232+
if count > batch_target || count > MAX_TRACES {
237233
use tracing::{field, field::debug, span, Level};
238234

239-
actual_size = 0;
240235
let span_batch = span!(
241236
Level::DEBUG,
242237
"Sending traces by batch to Apollo Studio",
@@ -255,18 +250,6 @@ impl ApolloTracing {
255250
report.set_traces_per_query(hashmap_to_send);
256251
report.set_header((*header_tokio).clone());
257252

258-
let test = match protobuf::Message::write_to_bytes(&report) {
259-
Ok(message) => {
260-
info!(target: "size-ext-3", size = ?message.len());
261-
info!(target: "size-ext", size = ?size_of_val(&message));
262-
},
263-
Err(err) => {
264-
span_batch.in_scope(|| {
265-
error!(target: TARGET_LOG, error = ?err, report = ?report);
266-
});
267-
}
268-
};
269-
270253
let msg = match protobuf::Message::write_to_bytes(&report) {
271254
Ok(message) => message,
272255
Err(err) => {

0 commit comments

Comments
 (0)