Replies: 3 comments 3 replies
-
In your example above you should keep the Here is a small example of what you could have: fn router_service(
&mut self,
service: BoxService<
RouterRequest,
RouterResponse<BoxStream<'static, ResponseBody>>,
BoxError,
>,
) -> BoxService<RouterRequest, RouterResponse<BoxStream<'static, ResponseBody>>, BoxError> {
service
.map_request(|req: RouterRequest| {
req.context
.insert(
"kind",
req.originating_request.body().operation_name.clone(),
)
.unwrap();
// insert other elements you need from the request in the context here
req
})
.map_response(|res: RouterResponse<BoxStream<'static, ResponseBody>>| {
// Get all the element you put in the context, specify the type to deserialize
let kind: Option<Option<String>> = res.context.get("kind").unwrap();
res.map(move |resp| {
resp.map(|response_body| match response_body {
ResponseBody::GraphQL(response) => {
for err in &response.errors {
sentry::with_scope(
|scope| scope.set_tag(kind.unwrap()),
|| sentry::capture_error(err),
);
}
}
_ => response_body,
})
})
.boxed()
})
.boxed()
} Let me know if it helps |
Beta Was this translation helpful? Give feedback.
-
@bnjjj thanks for responding. I'm currently trying to test out this solution, but I'm new to rust and having issues compiling the code.
This is the error:
|
Beta Was this translation helpful? Give feedback.
-
When using apollo getaway I normally integrate the apollo-server with Sentry using this plugin:
import { ApolloError } from 'apollo-server-express'
import * as Sentry from '@sentry/node'
I'm migrating to the apollo router and I want to do the same thing. I'm trying to build a new plugin but I can't figure out how to translate the previous apollo server lifecycle hooks to the router hooks. can someone please help me out?
Beta Was this translation helpful? Give feedback.
All reactions