|
1 | 1 | //! # Apollo Studio Extension for Performance Tracing for async_graphql crates |
| 2 | +mod compression; |
2 | 3 | mod packages; |
3 | 4 | mod proto; |
4 | 5 | pub mod register; |
5 | 6 |
|
6 | 7 | #[macro_use] |
7 | 8 | extern crate tracing; |
8 | | -/* |
9 | | - * TODO: |
10 | | - * - Gzip compression (libflate) |
11 | | - */ |
12 | 9 | use packages::uname::Uname; |
13 | 10 | use std::collections::HashMap; |
14 | 11 | use std::sync::Arc; |
@@ -203,41 +200,22 @@ impl ApolloTracing { |
203 | 200 | } |
204 | 201 | }; |
205 | 202 |
|
206 | | - let result = if cfg!(features = "compression") { |
207 | | - let mut encoder = libflate::gzip::Encoder::new(Vec::new()).unwrap(); |
208 | | - let mut msg = std::io::Cursor::new(msg); |
209 | | - match std::io::copy(&mut msg, &mut encoder) { |
210 | | - Ok(_) => {} |
211 | | - Err(e) => { |
212 | | - error!(target: TARGET_LOG, message = "An issue happened while GZIP compression", err = ?e); |
213 | | - continue; |
214 | | - } |
215 | | - }; |
216 | | - match encoder.finish().into_result() { |
217 | | - Ok(msg) => { |
218 | | - client |
219 | | - .post(REPORTING_URL) |
220 | | - .body(msg) |
221 | | - .header("content-type", "application/protobuf") |
222 | | - .header("X-Api-Key", &authorization_token) |
223 | | - .send() |
224 | | - .await |
225 | | - } |
226 | | - Err(e) => { |
227 | | - error!(target: TARGET_LOG, message = "An issue happened while GZIP compression", err = ?e); |
228 | | - continue; |
229 | | - } |
| 203 | + let msg = match compression::compress(msg) { |
| 204 | + Ok(result) => result, |
| 205 | + Err(e) => { |
| 206 | + error!(target: TARGET_LOG, message = "An issue happened while GZIP compression", err = ?e); |
| 207 | + continue; |
230 | 208 | } |
231 | | - } else { |
232 | | - client |
233 | | - .post(REPORTING_URL) |
234 | | - .body(msg) |
235 | | - .header("content-type", "application/protobuf") |
236 | | - .header("X-Api-Key", &authorization_token) |
237 | | - .send() |
238 | | - .await |
239 | 209 | }; |
240 | 210 |
|
| 211 | + let result = client |
| 212 | + .post(REPORTING_URL) |
| 213 | + .body(msg) |
| 214 | + .header("content-type", "application/protobuf") |
| 215 | + .header("X-Api-Key", &authorization_token) |
| 216 | + .send() |
| 217 | + .await; |
| 218 | + |
241 | 219 | match result { |
242 | 220 | Ok(data) => { |
243 | 221 | span_batch.record("response", &debug(&data)); |
|
0 commit comments