Skip to content

Instantly share code, notes, and snippets.

@efueyo
Last active April 26, 2021 21:31
Show Gist options
  • Save efueyo/eec3aa5115ea63005e92337f3205ccdb to your computer and use it in GitHub Desktop.
Save efueyo/eec3aa5115ea63005e92337f3205ccdb to your computer and use it in GitHub Desktop.
Apollo-Sentry-Plugin
import { ApolloServerPlugin } from "apollo-server-plugin-base"
import { Context } from "./context"
const plugin: ApolloServerPlugin<Context> = {
requestDidStart({ request, context }) {
if (!!request.operationName) { // set the transaction Name if we have named queries
context.transaction.setName(request.operationName!)
}
return {
willSendResponse({ context }) { // hook for transaction finished
context.transaction.finish()
},
executionDidStart() {
return {
willResolveField({ context, info }) { // hook for each new resolver
const span = context.transaction.startChild({
op: "resolver",
description: `${info.parentType.name}.${info.fieldName}`,
})
return () => { // this will execute once the resolver is finished
span.finish()
}
},
}
},
}
},
}
export default plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment