diff --git a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/scenario.js b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/scenario.js new file mode 100644 index 000000000000..42bb8edacb8f --- /dev/null +++ b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/scenario.js @@ -0,0 +1,52 @@ +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 typeDefs = gql`type Query { hello: String }`; + + const resolvers = { + Query: { + hello: () => { + return 'Hello world!'; + }, + }, + }; + + const server = new ApolloServer({ + typeDefs, + resolvers, + }); + + // Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation + await server.executeOperation({ + query: '{hello}', + }); + + setTimeout(() => { + span.end(); + server.stop(); + }, 500); + }, + ); +} + +// eslint-disable-next-line @typescript-eslint/no-floating-promises +run(); diff --git a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts new file mode 100644 index 000000000000..dc7c304484f9 --- /dev/null +++ b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts @@ -0,0 +1,38 @@ +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); + }); +});