Last active
April 26, 2021 21:31
-
-
Save efueyo/eec3aa5115ea63005e92337f3205ccdb to your computer and use it in GitHub Desktop.
Apollo-Sentry-Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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