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
@@ -1,8 +1,8 @@
const { ApolloServer } = require('@apollo/server');
const gql = require('graphql-tag');
const Sentry = require('@sentry/node');
import { ApolloServer } from '@apollo/server';
import * as Sentry from '@sentry/node';
import gql from 'graphql-tag';

module.exports = () => {
export function createApolloServer() {
return Sentry.startSpan({ name: 'Test Server Start' }, () => {
return new ApolloServer({
typeDefs: gql`
Expand Down Expand Up @@ -32,4 +32,4 @@ module.exports = () => {
introspection: false,
});
});
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
const Sentry = require('@sentry/node');
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,
});
import * as Sentry from '@sentry/node';
import gql from 'graphql-tag';

async function run() {
const gql = require('graphql-tag');
const server = require('./apollo-server')();
const { createApolloServer } = await import('./apollo-server.mjs');
const server = createApolloServer();

await Sentry.startSpan(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
const Sentry = require('@sentry/node');
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,
});
import * as Sentry from '@sentry/node';
import gql from 'graphql-tag';

async function run() {
const gql = require('graphql-tag');
const server = require('./apollo-server')();
const { createApolloServer } = await import('./apollo-server.mjs');
const server = createApolloServer();

await Sentry.startSpan(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
const Sentry = require('@sentry/node');
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,
});
import * as Sentry from '@sentry/node';

async function run() {
const server = require('./apollo-server')();
const { createApolloServer } = await import('./apollo-server.mjs');
const server = createApolloServer();

await Sentry.startSpan(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { describe, expect, test } from 'vitest';
import { createRunner } from '../../../utils/runner';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

// Server start transaction (Apollo Server v5 no longer runs introspection query on start)
const EXPECTED_START_SERVER_TRANSACTION = {
transaction: 'Test Server Start',
};

describe('GraphQL/Apollo Tests', () => {
test('should instrument GraphQL queries used from Apollo Server.', async () => {
afterAll(() => {
cleanupChildProcesses();
});

describe('query', () => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction (query)',
spans: expect.arrayContaining([
Expand All @@ -24,14 +28,24 @@ describe('GraphQL/Apollo Tests', () => {
]),
};

await createRunner(__dirname, 'scenario-query.js')
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
createEsmAndCjsTests(
__dirname,
'scenario-query.mjs',
'instrument.mjs',
(createTestRunner, test) => {
test('should instrument GraphQL queries used from Apollo Server.', async () => {
await createTestRunner()
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
});
},
{ copyPaths: ['apollo-server.mjs'] },
);
});

test('should instrument GraphQL mutations used from Apollo Server.', async () => {
describe('mutation', () => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction (mutation Mutation)',
spans: expect.arrayContaining([
Expand All @@ -49,14 +63,24 @@ describe('GraphQL/Apollo Tests', () => {
]),
};

await createRunner(__dirname, 'scenario-mutation.js')
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
createEsmAndCjsTests(
__dirname,
'scenario-mutation.mjs',
'instrument.mjs',
(createTestRunner, test) => {
test('should instrument GraphQL mutations used from Apollo Server.', async () => {
await createTestRunner()
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
});
},
{ copyPaths: ['apollo-server.mjs'] },
);
});

test('should handle GraphQL errors.', async () => {
describe('error', () => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction (mutation Mutation)',
spans: expect.arrayContaining([
Expand All @@ -74,10 +98,20 @@ describe('GraphQL/Apollo Tests', () => {
]),
};

await createRunner(__dirname, 'scenario-error.js')
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
createEsmAndCjsTests(
__dirname,
'scenario-error.mjs',
'instrument.mjs',
(createTestRunner, test) => {
test('should handle GraphQL errors.', async () => {
await createTestRunner()
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start()
.completed();
});
},
{ copyPaths: ['apollo-server.mjs'] },
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as Sentry from '@sentry/node';

const tracer = Sentry.getClient().tracer;

async function run() {
const { createApolloServer } = await import('../../apollo-server.mjs');
const server = createApolloServer();

await tracer.startActiveSpan('test span name', async span => {
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
await server.executeOperation({
query: 'query GetHello {hello}',
});

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

run();
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
import * as Sentry from '@sentry/node';

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
transport: loggingTransport,
});

const tracer = client.tracer;
const tracer = Sentry.getClient().tracer;

async function run() {
const server = require('../apollo-server')();
const { createApolloServer } = await import('../../apollo-server.mjs');
const server = createApolloServer();

await tracer.startActiveSpan(
'test span name',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
import * as Sentry from '@sentry/node';

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
transport: loggingTransport,
});

const tracer = client.tracer;
const tracer = Sentry.getClient().tracer;

async function run() {
const server = require('../apollo-server')();
const { createApolloServer } = await import('../../apollo-server.mjs');
const server = createApolloServer();

await tracer.startActiveSpan(
'test span name',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
import * as Sentry from '@sentry/node';
import gql from 'graphql-tag';

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
transport: loggingTransport,
});

const tracer = client.tracer;
const tracer = Sentry.getClient().tracer;

async function run() {
const gql = require('graphql-tag');
const server = require('../apollo-server')();
const { createApolloServer } = await import('../../apollo-server.mjs');
const server = createApolloServer();

await tracer.startActiveSpan(
'test span name',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
import * as Sentry from '@sentry/node';

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
transport: loggingTransport,
});

const tracer = client.tracer;
const tracer = Sentry.getClient().tracer;

async function run() {
const server = require('../apollo-server')();
const { createApolloServer } = await import('../../apollo-server.mjs');
const server = createApolloServer();

await tracer.startActiveSpan(
'test span name',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
import * as Sentry from '@sentry/node';

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
transport: loggingTransport,
});

const tracer = client.tracer;
const tracer = Sentry.getClient().tracer;

async function run() {
const server = require('../apollo-server')();
const { createApolloServer } = await import('../../apollo-server.mjs');
const server = createApolloServer();

await tracer.startActiveSpan(
'test span name',
Expand Down
Loading
Loading