Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/plugins/sentry/__tests__/sentry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,41 @@ describe('sentry', () => {
});
});
});

test('sets the span in the query context', async () => {
const { testkit: sentryTestkit, sentryTransport } = createSentryTestkit();
Sentry.init({
dsn: 'https://[email protected]/2',
transport: sentryTransport,
});

// The test verifies that the span is set in the context, which would be
// available as the third argument
const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
hasSentryInContext: String!
}
`,
resolvers: {
Query: {
hasSentryInContext: async (args, info, ctx) => {
return !!ctx.sentry;
},
},
},
});

const envelopTestkit = createTestkit([useSentry()], schema);
const result = await envelopTestkit.execute('{ hasSentryInContext }');
expect(result).toMatchInlineSnapshot(`
Object {
"data": Object {
"hasSentryInContext": "true",
},
}
`);

// run sentry flush
await new Promise(res => setTimeout(res, 10));
});
4 changes: 3 additions & 1 deletion packages/plugins/sentry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const useSentry = (options: SentryPluginOptions = {}): Plugin => {
}

return {
onExecute({ args }) {
onExecute({ args, extendContext }) {
if (skipOperation(args)) {
return;
}
Expand Down Expand Up @@ -179,6 +179,8 @@ export const useSentry = (options: SentryPluginOptions = {}): Plugin => {
Sentry.configureScope(scope => options.configureScope!(args, scope));
}

extendContext({ sentry: { span: rootSpan } });

return {
onExecuteDone(payload) {
const handleResult: OnExecuteDoneHookResultOnNextHook<{}> = ({ result, setResult }) => {
Expand Down