Skip to content

Commit ec3c86c

Browse files
committed
fixes
1 parent c9c0835 commit ec3c86c

File tree

14 files changed

+175
-57
lines changed

14 files changed

+175
-57
lines changed
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
const { ApolloServer, gql } = require('apollo-server');
2+
const Sentry = require('@sentry/node');
23

3-
module.exports = () =>
4-
new ApolloServer({
5-
typeDefs: gql`type Query {
4+
module.exports = () => {
5+
return Sentry.startSpan({ name: 'Test Server Start' }, () => {
6+
return new ApolloServer({
7+
typeDefs: gql`type Query {
68
hello: String
79
world: String
810
}
911
type Mutation {
1012
login(email: String): String
1113
}`,
12-
resolvers: {
13-
Query: {
14-
hello: () => {
15-
return 'Hello!';
14+
resolvers: {
15+
Query: {
16+
hello: () => {
17+
return 'Hello!';
18+
},
19+
world: () => {
20+
return 'World!';
21+
},
1622
},
17-
world: () => {
18-
return 'World!';
23+
Mutation: {
24+
login: async (_, { email }) => {
25+
return `${email}--token`;
26+
},
1927
},
2028
},
21-
Mutation: {
22-
login: async (_, { email }) => {
23-
return `${email}--token`;
24-
},
25-
},
26-
},
27-
introspection: false,
28-
debug: false,
29+
introspection: false,
30+
debug: false,
31+
});
2932
});
33+
};

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-mutation.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ setInterval(() => {}, 1000);
1313

1414
async function run() {
1515
const { gql } = require('apollo-server');
16+
const server = require('./apollo-server')();
1617

1718
await Sentry.startSpan(
1819
{
1920
name: 'Test Transaction',
2021
op: 'transaction',
2122
},
2223
async span => {
23-
const server = require('./apollo-server')();
24-
2524
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
2625
await server.executeOperation({
2726
query: gql`mutation Mutation($email: String){

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Sentry.init({
1212
setInterval(() => {}, 1000);
1313

1414
async function run() {
15+
const server = require('./apollo-server')();
16+
1517
await Sentry.startSpan(
1618
{
1719
name: 'Test Transaction',
1820
op: 'transaction',
1921
},
2022
async span => {
21-
const server = require('./apollo-server')();
22-
2323
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
2424
await server.executeOperation({
2525
query: '{hello}',

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { createRunner } from '../../../utils/runner';
22

3+
// Graphql Instrumentation emits some spans by default on server start
4+
const EXPECTED_START_SERVER_TRANSACTION = {
5+
transaction: 'Test Server Start',
6+
};
7+
38
describe('GraphQL/Apollo Tests', () => {
49
test('should instrument GraphQL queries used from Apollo Server.', done => {
510
const EXPECTED_TRANSACTION = {
@@ -18,7 +23,10 @@ describe('GraphQL/Apollo Tests', () => {
1823
]),
1924
};
2025

21-
createRunner(__dirname, 'scenario-query.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
26+
createRunner(__dirname, 'scenario-query.js')
27+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
28+
.expect({ transaction: EXPECTED_TRANSACTION })
29+
.start(done);
2230
});
2331

2432
test('should instrument GraphQL mutations used from Apollo Server.', done => {
@@ -39,6 +47,9 @@ describe('GraphQL/Apollo Tests', () => {
3947
]),
4048
};
4149

42-
createRunner(__dirname, 'scenario-mutation.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
50+
createRunner(__dirname, 'scenario-mutation.js')
51+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
52+
.expect({ transaction: EXPECTED_TRANSACTION })
53+
.start(done);
4354
});
4455
});

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-invalid-root-span.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const tracer = client.tracer;
1515
setInterval(() => {}, 1000);
1616

1717
async function run() {
18-
await tracer.startActiveSpan('test span name', async span => {
19-
const server = require('../apollo-server')();
18+
const server = require('../apollo-server')();
2019

20+
await tracer.startActiveSpan('test span name', async span => {
2121
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
2222
await server.executeOperation({
2323
query: 'query GetHello {hello}',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const Sentry = require('@sentry/node');
2+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3+
4+
const client = Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
integrations: [Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })],
9+
transport: loggingTransport,
10+
});
11+
12+
const tracer = client.tracer;
13+
14+
// Stop the process from exiting before the transaction is sent
15+
setInterval(() => {}, 1000);
16+
17+
async function run() {
18+
const server = require('../apollo-server')();
19+
20+
await tracer.startActiveSpan(
21+
'test span name',
22+
{
23+
kind: 1,
24+
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
25+
},
26+
async span => {
27+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
28+
await server.executeOperation({
29+
query: 'query GetHello {hello}',
30+
});
31+
32+
await server.executeOperation({
33+
query: 'query GetWorld {world}',
34+
});
35+
36+
setTimeout(() => {
37+
span.end();
38+
server.stop();
39+
}, 500);
40+
},
41+
);
42+
}
43+
44+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
45+
run();

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-mutation.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ setInterval(() => {}, 1000);
1616

1717
async function run() {
1818
const { gql } = require('apollo-server');
19+
const server = require('../apollo-server')();
1920

2021
await tracer.startActiveSpan(
2122
'test span name',
2223
{
2324
kind: 1,
24-
attributes: { 'http.method': 'GET' },
25+
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
2526
},
2627
async span => {
27-
const server = require('../apollo-server')();
28-
2928
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
3029
await server.executeOperation({
3130
query: gql`mutation TestMutation($email: String){

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-no-operation-name.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const tracer = client.tracer;
1515
setInterval(() => {}, 1000);
1616

1717
async function run() {
18+
const server = require('../apollo-server')();
19+
1820
await tracer.startActiveSpan(
1921
'test span name',
2022
{
2123
kind: 1,
22-
attributes: { 'http.method': 'GET' },
24+
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
2325
},
2426
async span => {
25-
const server = require('../apollo-server')();
26-
2727
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
2828
await server.executeOperation({
2929
query: 'query {hello}',

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-query.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const tracer = client.tracer;
1515
setInterval(() => {}, 1000);
1616

1717
async function run() {
18+
const server = require('../apollo-server')();
19+
1820
await tracer.startActiveSpan(
1921
'test span name',
2022
{
2123
kind: 1,
22-
attributes: { 'http.method': 'GET' },
24+
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
2325
},
2426
async span => {
25-
const server = require('../apollo-server')();
26-
2727
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
2828
await server.executeOperation({
2929
query: 'query GetHello {hello}',

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/test.ts

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { createRunner } from '../../../../utils/runner';
22

3+
// Graphql Instrumentation emits some spans by default on server start
4+
const EXPECTED_START_SERVER_TRANSACTION = {
5+
transaction: 'Test Server Start',
6+
};
7+
38
describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
49
test('useOperationNameForRootSpan works with single query operation', done => {
510
const EXPECTED_TRANSACTION = {
6-
transaction: 'query GetHello',
11+
transaction: 'GET /test-graphql (query GetHello)',
712
spans: expect.arrayContaining([
813
expect.objectContaining({
914
data: {
@@ -19,12 +24,15 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
1924
]),
2025
};
2126

22-
createRunner(__dirname, 'scenario-query.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
27+
createRunner(__dirname, 'scenario-query.js')
28+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
29+
.expect({ transaction: EXPECTED_TRANSACTION })
30+
.start(done);
2331
});
2432

2533
test('useOperationNameForRootSpan works with single mutation operation', done => {
2634
const EXPECTED_TRANSACTION = {
27-
transaction: 'mutation TestMutation',
35+
transaction: 'GET /test-graphql (mutation TestMutation)',
2836
spans: expect.arrayContaining([
2937
expect.objectContaining({
3038
data: {
@@ -42,7 +50,10 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
4250
]),
4351
};
4452

45-
createRunner(__dirname, 'scenario-mutation.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
53+
createRunner(__dirname, 'scenario-mutation.js')
54+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
55+
.expect({ transaction: EXPECTED_TRANSACTION })
56+
.start(done);
4657
});
4758

4859
test('useOperationNameForRootSpan ignores an invalid root span', done => {
@@ -63,12 +74,15 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
6374
]),
6475
};
6576

66-
createRunner(__dirname, 'scenario-invalid-root-span.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
77+
createRunner(__dirname, 'scenario-invalid-root-span.js')
78+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
79+
.expect({ transaction: EXPECTED_TRANSACTION })
80+
.start(done);
6781
});
6882

6983
test('useOperationNameForRootSpan works with single query operation without name', done => {
7084
const EXPECTED_TRANSACTION = {
71-
transaction: 'query',
85+
transaction: 'GET /test-graphql (query)',
7286
spans: expect.arrayContaining([
7387
expect.objectContaining({
7488
data: {
@@ -83,6 +97,44 @@ describe('GraphQL/Apollo Tests > useOperationNameForRootSpan', () => {
8397
]),
8498
};
8599

86-
createRunner(__dirname, 'scenario-no-operation-name.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
100+
createRunner(__dirname, 'scenario-no-operation-name.js')
101+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
102+
.expect({ transaction: EXPECTED_TRANSACTION })
103+
.start(done);
104+
});
105+
106+
test('useOperationNameForRootSpan works with multiple query operations', done => {
107+
const EXPECTED_TRANSACTION = {
108+
transaction: 'GET /test-graphql (query GetHello)',
109+
spans: expect.arrayContaining([
110+
expect.objectContaining({
111+
data: {
112+
'graphql.operation.name': 'GetHello',
113+
'graphql.operation.type': 'query',
114+
'graphql.source': 'query GetHello {hello}',
115+
'sentry.origin': 'auto.graphql.otel.graphql',
116+
},
117+
description: 'query GetHello',
118+
status: 'ok',
119+
origin: 'auto.graphql.otel.graphql',
120+
}),
121+
expect.objectContaining({
122+
data: {
123+
'graphql.operation.name': 'GetWorld',
124+
'graphql.operation.type': 'query',
125+
'graphql.source': 'query GetWorld {world}',
126+
'sentry.origin': 'auto.graphql.otel.graphql',
127+
},
128+
description: 'query GetWorld',
129+
status: 'ok',
130+
origin: 'auto.graphql.otel.graphql',
131+
}),
132+
]),
133+
};
134+
135+
createRunner(__dirname, 'scenario-multiple-operations.js')
136+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
137+
.expect({ transaction: EXPECTED_TRANSACTION })
138+
.start(done);
87139
});
88140
});

0 commit comments

Comments
 (0)