async-graphql-extension-apollo-tracing is an open-source extension for the crates async_graphql. The purpose of this extension is to provide a simple way to create & send your graphql metrics to Apollo Studio.
Tested at Rust version: rustc 1.53.0 (53cb7b09b 2021-06-17)
🇫🇷 Crafted in Nantes, France.
A litle example to how to use it. If there is something unclear, please write an issue on the repo. Some examples are going to be written soon.
```rust use asyncgraphqlextensionapollotracing::{ApolloTracing, ApolloTracingDataExt, HTTPMethod, register::register};
async fn main() -> anyhow::Result<()> { ...
let schema = Schema::build(Query::default(), Mutation::default(), EmptySubscription) .data(somedataneededforyou) .extension(ApolloTracing::new( "authorizationtoken".into(), "https://yourdomain.ltd".into(), "yourgraph@variant".into(), "v1.0.0".into(), 10, )) .finish();
register("authorization_token", &schema, "my-allocation-id", "variant", "1.0.0", "staging").await?;
...
let clientname = warp::header::optional("apollographql-client-name"); let clientversion = warp::header::optional("apollographql-client-version"); let env = myenvfilter();
let graphqlpost = warp::post()
.and(warp::path("graphql"))
.and(asyncgraphqlwarp::graphql(schema))
.and(env)
.and(clientname)
.and(clientversion)
.andthen(
|(schema, request): (
Schema
Ok::<_, std::convert::Infallible>(async_graphql_warp::Response::from(
schema
.execute(
request.data(ApolloTracingDataExt {
userid,
path: Some("/graphql".to_string()),
host: Some("https://yourdomain.ltd".to_string()),
method: Some(HTTPMethod::POST),
secure: Some(true),
protocol: Some("HTTP/1.1".to_string()),
status_code: Some(200),
client_name,
client_version,
})
.data(env),
)
.await,
))
},
);
} ```