Skip to content

Commit bcf73bf

Browse files
authored
Merge branch 'develop' into onur/postgres.js-instrumentation
2 parents 5cae445 + d8f12c2 commit bcf73bf

File tree

14 files changed

+165
-42
lines changed

14 files changed

+165
-42
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const Sentry = require('@sentry/node');
2+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
});
10+
11+
// Stop the process from exiting before the transaction is sent
12+
setInterval(() => {}, 1000);
13+
14+
async function run() {
15+
const { gql } = require('apollo-server');
16+
const server = require('./apollo-server')();
17+
18+
await Sentry.startSpan(
19+
{
20+
name: 'Test Transaction',
21+
op: 'transaction',
22+
},
23+
async span => {
24+
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
25+
await server.executeOperation({
26+
query: gql`
27+
mutation Mutation($email: String) {
28+
login(email: $email)
29+
}
30+
`,
31+
// We want to trigger an error by passing an invalid variable type
32+
variables: { email: 123 },
33+
});
34+
35+
setTimeout(() => {
36+
span.end();
37+
server.stop();
38+
}, 500);
39+
},
40+
);
41+
}
42+
43+
run();

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,29 @@ describe('GraphQL/Apollo Tests', () => {
5555
.start()
5656
.completed();
5757
});
58+
59+
test('should handle GraphQL errors.', async () => {
60+
const EXPECTED_TRANSACTION = {
61+
transaction: 'Test Transaction (mutation Mutation)',
62+
spans: expect.arrayContaining([
63+
expect.objectContaining({
64+
data: {
65+
'graphql.operation.name': 'Mutation',
66+
'graphql.operation.type': 'mutation',
67+
'graphql.source': 'mutation Mutation($email: String) {\n login(email: $email)\n}',
68+
'sentry.origin': 'auto.graphql.otel.graphql',
69+
},
70+
description: 'mutation Mutation',
71+
status: 'unknown_error',
72+
origin: 'auto.graphql.otel.graphql',
73+
}),
74+
]),
75+
};
76+
77+
await createRunner(__dirname, 'scenario-error.js')
78+
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
79+
.expect({ transaction: EXPECTED_TRANSACTION })
80+
.start()
81+
.completed();
82+
});
5883
});

packages/bun/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
},
4141
"dependencies": {
4242
"@sentry/core": "9.30.0",
43-
"@sentry/node": "9.30.0",
44-
"@sentry/opentelemetry": "9.30.0"
43+
"@sentry/node": "9.30.0"
4544
},
4645
"devDependencies": {
4746
"bun-types": "^1.2.9"

packages/gatsby/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"dependencies": {
4848
"@sentry/core": "9.30.0",
4949
"@sentry/react": "9.30.0",
50-
"@sentry/webpack-plugin": "3.5.0"
50+
"@sentry/webpack-plugin": "^3.5.0"
5151
},
5252
"peerDependencies": {
5353
"gatsby": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0",

packages/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"@sentry/opentelemetry": "9.30.0",
8686
"@sentry/react": "9.30.0",
8787
"@sentry/vercel-edge": "9.30.0",
88-
"@sentry/webpack-plugin": "3.5.0",
88+
"@sentry/webpack-plugin": "^3.5.0",
8989
"chalk": "3.0.0",
9090
"resolve": "1.22.8",
9191
"rollup": "4.35.0",

packages/node/src/integrations/tracing/graphql.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AttributeValue } from '@opentelemetry/api';
2+
import { SpanStatusCode } from '@opentelemetry/api';
23
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
34
import type { IntegrationFn } from '@sentry/core';
45
import { defineIntegration, getRootSpan, spanToJSON } from '@sentry/core';
@@ -45,9 +46,16 @@ export const instrumentGraphql = generateInstrumentOnce(
4546

4647
return {
4748
...options,
48-
responseHook(span) {
49+
responseHook(span, result) {
4950
addOriginToSpan(span, 'auto.graphql.otel.graphql');
5051

52+
// We want to ensure spans are marked as errored if there are errors in the result
53+
// We only do that if the span is not already marked with a status
54+
const resultWithMaybeError = result as { errors?: { message: string }[] };
55+
if (resultWithMaybeError.errors?.length && !spanToJSON(span).status) {
56+
span.setStatus({ code: SpanStatusCode.ERROR });
57+
}
58+
5159
const attributes = spanToJSON(span).data;
5260

5361
// If operation.name is not set, we fall back to use operation.type only

packages/nuxt/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@
4646
"@sentry/browser": "9.30.0",
4747
"@sentry/core": "9.30.0",
4848
"@sentry/node": "9.30.0",
49-
"@sentry/opentelemetry": "9.30.0",
50-
"@sentry/rollup-plugin": "3.5.0",
51-
"@sentry/vite-plugin": "3.2.4",
49+
"@sentry/rollup-plugin": "^3.5.0",
50+
"@sentry/vite-plugin": "^3.5.0",
5251
"@sentry/vue": "9.30.0"
5352
},
5453
"devDependencies": {

packages/react-router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@sentry/core": "9.30.0",
4444
"@sentry/node": "9.30.0",
4545
"@sentry/react": "9.30.0",
46-
"@sentry/vite-plugin": "^3.2.4",
46+
"@sentry/vite-plugin": "^3.5.0",
4747
"glob": "11.0.1"
4848
},
4949
"devDependencies": {

packages/remix/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"@sentry/cli": "^2.46.0",
7272
"@sentry/core": "9.30.0",
7373
"@sentry/node": "9.30.0",
74-
"@sentry/opentelemetry": "9.30.0",
7574
"@sentry/react": "9.30.0",
7675
"glob": "^10.3.4",
7776
"yargs": "^17.6.0"

packages/remix/test/integration/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"@sentry/browser": "file:../../../browser",
2828
"@sentry/core": "file:../../../core",
2929
"@sentry/node": "file:../../../node",
30-
"@sentry/opentelemetry": "file:../../../opentelemetry",
3130
"@sentry/react": "file:../../../react",
3231
"@sentry-internal/browser-utils": "file:../../../browser-utils",
3332
"@sentry-internal/replay": "file:../../../replay-internal",

0 commit comments

Comments
 (0)