@@ -29,6 +29,7 @@ mod compression;
2929mod packages;
3030mod proto;
3131pub mod register;
32+ mod runtime;
3233
3334#[ macro_use]
3435extern crate tracing;
@@ -53,9 +54,8 @@ use proto::{
5354 Report , ReportHeader , Trace , Trace_Details , Trace_Error , Trace_HTTP , Trace_HTTP_Method ,
5455 Trace_Location , Trace_Node , Trace_Node_oneof_id , TracesAndStats ,
5556} ;
57+ use runtime:: { channel, Runtime , RwLock , Sender } ;
5658use std:: convert:: TryInto ;
57- use tokio:: sync:: mpsc:: { channel, Sender } ;
58- use tokio:: sync:: RwLock ;
5959
6060/// Apollo Tracing Extension to send traces to Apollo Studio
6161/// The extension to include to your `async_graphql` instance to connect with Apollo Studio.
@@ -199,11 +199,16 @@ impl ApolloTracing {
199199
200200 let header_tokio = Arc :: clone ( & header) ;
201201
202- tokio :: spawn ( async move {
202+ Runtime :: locate ( ) . spawn ( async move {
203203 let mut hashmap: HashMap < String , TracesAndStats > =
204204 HashMap :: with_capacity ( batch_target + 1 ) ;
205205 let mut count = 0 ;
206- while let Some ( ( name, trace) ) = receiver. recv ( ) . await {
206+ while let Some ( ( name, trace) ) = match Runtime :: locate ( ) {
207+ #[ cfg( feature = "tokio-comp" ) ]
208+ Runtime :: Tokio => receiver. recv ( ) . await ,
209+ #[ cfg( feature = "async-std-comp" ) ]
210+ Runtime :: AsyncStd => receiver. recv ( ) . await . ok ( ) ,
211+ } {
207212 trace ! ( target: TARGET_LOG , message = "Trace registered" , trace = ?trace, name = ?name) ;
208213
209214 // We bufferize traces and create a Full Report every X
@@ -450,7 +455,7 @@ impl Extension for ApolloTracingExtension {
450455 let sender = self . sender . clone ( ) ;
451456
452457 let operation_name = self . operation_name . read ( ) . await . clone ( ) ;
453- tokio :: spawn ( async move {
458+ Runtime :: locate ( ) . spawn ( async move {
454459 if let Err ( e) = sender. send ( ( operation_name, trace) ) . await {
455460 error ! ( error = ?e) ;
456461 }
0 commit comments