Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const Sentry = require('@sentry/node-experimental');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

async function run() {
const { ApolloServer, gql } = require('apollo-server');

await Sentry.startSpan(
{
name: 'Test Transaction',
op: 'transaction',
},
async span => {
const server = new ApolloServer({
typeDefs: gql`
type Query {
hello: String
}
type Mutation {
login(email: String): String
}
`,
resolvers: {
Query: {
hello: () => {
return 'Hello world!';
},
},
Mutation: {
login: async (_, { email }) => {
return `${email}--token`;
},
},
},
});

// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
await server.executeOperation({
query: gql`mutation Mutation($email: String){
login(email: $email)
}`,
variables: { email: 'test@email.com' },
});

setTimeout(() => {
span.end();
server.stop();
}, 500);
},
);
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,61 @@ import { conditionalTest } from '../../../utils';
import { createRunner } from '../../../utils/runner';

conditionalTest({ min: 14 })('GraphQL/Apollo Tests', () => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
expect.objectContaining({
data: {
'graphql.operation.type': 'query',
'graphql.source': '{hello}',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.graphql.otel.graphql',
},
description: 'query',
status: 'ok',
origin: 'auto.graphql.otel.graphql',
}),
expect.objectContaining({
data: {
'graphql.field.name': 'hello',
'graphql.field.path': 'hello',
'graphql.field.type': 'String',
'graphql.source': 'hello',
'otel.kind': 'INTERNAL',
'sentry.origin': 'manual',
},
description: 'graphql.resolve',
status: 'ok',
origin: 'manual',
}),
]),
};

test('CJS - should instrument GraphQL queries used from Apollo Server.', done => {
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
expect.objectContaining({
data: {
'graphql.operation.type': 'query',
'graphql.source': '{hello}',
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.graphql.otel.graphql',
},
description: 'query',
status: 'ok',
origin: 'auto.graphql.otel.graphql',
}),
expect.objectContaining({
data: {
'graphql.field.name': 'hello',
'graphql.field.path': 'hello',
'graphql.field.type': 'String',
'graphql.source': 'hello',
'otel.kind': 'INTERNAL',
'sentry.origin': 'manual',
},
description: 'graphql.resolve',
status: 'ok',
origin: 'manual',
}),
]),
};

createRunner(__dirname, 'scenario-query.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
});

test('CJS - should instrument GraphQL mutations used from Apollo Server.', done => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
expect.objectContaining({
data: {
'graphql.operation.name': 'Mutation',
'graphql.operation.type': 'mutation',
'graphql.source': `mutation Mutation($email: String) {
login(email: $email)
}`,
'otel.kind': 'INTERNAL',
'sentry.origin': 'auto.graphql.otel.graphql',
},
description: 'mutation Mutation',
status: 'ok',
origin: 'auto.graphql.otel.graphql',
}),
]),
};

createRunner(__dirname, 'scenario-mutation.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
});
});