2626//!
2727//! * `compression` - To enable GZIP Compression when sending traces to Apollo Studio.
2828mod compression;
29- mod packages;
3029mod proto;
3130pub mod register;
3231mod report_aggregator;
3332
3433mod runtime;
34+ mod packages;
35+
3536use futures:: SinkExt ;
36- use prost_types :: Timestamp ;
37+ use protobuf :: { well_known_types :: timestamp :: Timestamp , EnumOrUnknown , MessageField } ;
3738use report_aggregator:: ReportAggregator ;
3839use runtime:: spawn;
40+ use packages:: serde_json;
3941
4042#[ macro_use]
4143extern crate tracing;
4244
43- use futures_locks:: RwLock ;
4445use std:: collections:: HashMap ;
4546use std:: sync:: Arc ;
47+ use std:: sync:: RwLock ;
4648
4749use async_graphql:: QueryPathSegment ;
4850use chrono:: { DateTime , Utc } ;
@@ -55,13 +57,13 @@ use async_graphql::extensions::{
5557} ;
5658use async_graphql:: parser:: types:: { ExecutableDocument , OperationType , Selection } ;
5759use async_graphql:: { Response , ServerResult , Value , Variables } ;
58- use proto:: report :: {
60+ use proto:: reports :: {
5961 trace:: { self , node, Node } ,
6062 Trace ,
6163} ;
6264use std:: convert:: TryInto ;
6365
64- pub use proto:: report :: trace:: http:: Method ;
66+ pub use proto:: reports :: trace:: http:: Method ;
6567
6668/// Apollo Tracing Extension to send traces to Apollo Studio
6769/// The extension to include to your `async_graphql` instance to connect with Apollo Studio.
@@ -185,7 +187,7 @@ impl Extension for ApolloTracingExtension {
185187 . any ( |( _, operation) | operation. node . selection_set . node . items . iter ( ) . any ( |selection| matches ! ( & selection. node, Selection :: Field ( field) if field. node. name. node == "__schema" ) ) ) ;
186188 if !is_schema {
187189 let result: String =
188- ctx. stringify_execute_doc ( & document, & Variables :: from_json ( serde_json:: json! ( { } ) ) ) ;
190+ ctx. stringify_execute_doc ( & document, & Variables :: from_json ( serde_json:: from_str ( "{}" ) . unwrap ( ) ) ) ;
189191 let name = document
190192 . operations
191193 . iter ( )
@@ -194,7 +196,7 @@ impl Extension for ApolloTracingExtension {
194196 . map ( |x| x. as_str ( ) )
195197 . unwrap_or ( "no_name" ) ;
196198 let query_type = format ! ( "# {name}\n {query}" , name = name, query = result) ;
197- * self . operation_name . write ( ) . await = query_type;
199+ * self . operation_name . write ( ) . unwrap ( ) = query_type;
198200 }
199201 Ok ( document)
200202 }
@@ -227,7 +229,9 @@ impl Extension for ApolloTracingExtension {
227229 let client_version = tracing_extension
228230 . client_version
229231 . unwrap_or_else ( || "no client version" . to_string ( ) ) ;
230- let method = tracing_extension. method . unwrap_or ( Method :: Unknown ) ;
232+ let method = tracing_extension
233+ . method
234+ . or ( <Method as protobuf:: Enum >:: from_str ( "UNKNOWN" ) ) ;
231235 let status_code = tracing_extension. status_code . unwrap_or ( 0 ) ;
232236
233237 let mut trace: Trace = Trace {
@@ -245,34 +249,39 @@ impl Extension for ApolloTracingExtension {
245249 . map ( |x| x. to_string ( ) )
246250 . unwrap_or_else ( || "no operation" . to_string ( ) ) ,
247251 ..Default :: default ( )
248- } ) ;
252+ } )
253+ . into ( ) ;
249254
250- trace. http = Some ( trace:: Http {
251- method : method. into ( ) ,
255+ trace. http = Some ( trace:: HTTP {
256+ method : EnumOrUnknown :: new ( method. unwrap ( ) ) ,
252257 status_code,
253258 ..Default :: default ( )
254- } ) ;
259+ } )
260+ . into ( ) ;
255261
256- trace. end_time = Some ( Timestamp {
262+ trace. end_time = MessageField :: some ( Timestamp {
257263 nanos : inner. end_time . timestamp_subsec_nanos ( ) . try_into ( ) . unwrap ( ) ,
258264 seconds : inner. end_time . timestamp ( ) ,
265+ special_fields : Default :: default ( ) ,
259266 } ) ;
260267
261- trace. start_time = Some ( Timestamp {
262- nanos : inner
263- . start_time
264- . timestamp_subsec_nanos ( )
265- . try_into ( )
266- . unwrap ( ) ,
267- seconds : inner. start_time . timestamp ( ) ,
268- } ) ;
268+ trace. start_time =
269+ protobuf:: MessageField :: some ( protobuf:: well_known_types:: timestamp:: Timestamp {
270+ nanos : inner
271+ . start_time
272+ . timestamp_subsec_nanos ( )
273+ . try_into ( )
274+ . unwrap ( ) ,
275+ seconds : inner. start_time . timestamp ( ) ,
276+ special_fields : Default :: default ( ) ,
277+ } ) ;
269278
270- let root_node = self . root_node . read ( ) . await ;
271- trace. root = Some ( root_node. clone ( ) ) ;
279+ let root_node = self . root_node . read ( ) . unwrap ( ) ;
280+ trace. root = Some ( root_node. clone ( ) ) . into ( ) ;
272281
273282 let mut sender = self . report . sender ( ) ;
274283
275- let operation_name = self . operation_name . read ( ) . await . clone ( ) ;
284+ let operation_name = self . operation_name . read ( ) . unwrap ( ) . clone ( ) ;
276285
277286 let _handle = spawn ( async move {
278287 if let Err ( e) = sender. send ( ( operation_name, trace) ) . await {
@@ -295,7 +304,7 @@ impl Extension for ApolloTracingExtension {
295304 let path = info. path_node . to_string_vec ( ) . join ( "." ) ;
296305 let field_name = info. path_node . field_name ( ) . to_string ( ) ;
297306 let parent_type = info. parent_type . to_string ( ) ;
298- let return_type = info. return_type . to_string ( ) ;
307+ let _return_type = info. return_type . to_string ( ) ;
299308 let start_time = Utc :: now ( ) - self . inner . lock ( ) . await . start_time ;
300309 let path_node = info. path_node ;
301310
@@ -320,12 +329,11 @@ impl Extension for ApolloTracingExtension {
320329 } ,
321330 parent_type : parent_type. to_string ( ) ,
322331 original_field_name : field_name,
323- r#type : return_type,
324332 ..Default :: default ( )
325333 } ;
326334
327335 let node = Arc :: new ( RwLock :: new ( node) ) ;
328- self . nodes . write ( ) . await . insert ( path, node. clone ( ) ) ;
336+ self . nodes . write ( ) . unwrap ( ) . insert ( path, node. clone ( ) ) ;
329337 let parent_node = path_node. parent . map ( |x| x. to_string_vec ( ) . join ( "." ) ) ;
330338 // Use the path to create a new node
331339 // https://github.com/apollographql/apollo-server/blob/291c17e255122d4733b23177500188d68fac55ce/packages/apollo-server-core/src/plugin/traceTreeBuilder.ts
@@ -334,7 +342,7 @@ impl Extension for ApolloTracingExtension {
334342 Err ( e) => {
335343 let json = match serde_json:: to_string ( & e) {
336344 Ok ( content) => content,
337- Err ( e) => serde_json :: json! ( { "error" : format! ( "{ :?}" , e ) } ) . to_string ( ) ,
345+ Err ( e) => format ! ( "{{ \ " error\ " : \" {e :?}\" }}" ) ,
338346 } ;
339347 let error = trace:: Error {
340348 message : e. message . clone ( ) ,
@@ -345,19 +353,20 @@ impl Extension for ApolloTracingExtension {
345353 . map ( |x| trace:: Location {
346354 line : x. line as u32 ,
347355 column : x. column as u32 ,
356+ special_fields : protobuf:: SpecialFields :: default ( ) ,
348357 } )
349358 . collect ( ) ,
350359 json,
351360 ..Default :: default ( )
352361 } ;
353362
354- node. write ( ) . await . error = vec ! [ error] ;
363+ node. write ( ) . unwrap ( ) . error = vec ! [ error] ;
355364 Err ( e)
356365 }
357366 } ;
358367 let end_time = Utc :: now ( ) - self . inner . lock ( ) . await . start_time ;
359368
360- node. write ( ) . await . end_time = match end_time
369+ node. write ( ) . unwrap ( ) . end_time = match end_time
361370 . num_nanoseconds ( )
362371 . and_then ( |x| u64:: try_from ( x) . ok ( ) )
363372 {
@@ -371,19 +380,19 @@ impl Extension for ApolloTracingExtension {
371380
372381 match parent_node {
373382 None => {
374- let mut root_node = self . root_node . write ( ) . await ;
383+ let mut root_node = self . root_node . write ( ) . unwrap ( ) ;
375384 let child = & mut root_node. child ;
376- let node = node. read ( ) . await ;
385+ let node = node. read ( ) . unwrap ( ) ;
377386 // Can't copy or pass a ref to Protobuf
378387 // So we clone
379388 child. push ( node. clone ( ) ) ;
380389 }
381390 Some ( parent) => {
382- let nodes = self . nodes . read ( ) . await ;
391+ let nodes = self . nodes . read ( ) . unwrap ( ) ;
383392 let node_read = nodes. get ( & parent) . unwrap ( ) ;
384- let mut parent = node_read. write ( ) . await ;
393+ let mut parent = node_read. write ( ) . unwrap ( ) ;
385394 let child = & mut parent. child ;
386- let node = node. read ( ) . await ;
395+ let node = node. read ( ) . unwrap ( ) ;
387396 // Can't copy or pass a ref to Protobuf
388397 // So we clone
389398 child. push ( node. clone ( ) ) ;
0 commit comments