Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): Add useOperationNameForRootSpan tographqlIntegration #13248

Merged
merged 9 commits into from
Aug 8, 2024
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,33 @@
const { ApolloServer, gql } = require('apollo-server');
const Sentry = require('@sentry/node');

module.exports = () => {
return Sentry.startSpan({ name: 'Test Server Start' }, () => {
return new ApolloServer({
typeDefs: gql`type Query {
hello: String
world: String
}
type Mutation {
login(email: String): String
}`,
resolvers: {
Query: {
hello: () => {
return 'Hello!';
},
world: () => {
return 'World!';
},
},
Mutation: {
login: async (_, { email }) => {
return `${email}--token`;
},
},
},
introspection: false,
debug: false,
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,15 @@ Sentry.init({
setInterval(() => {}, 1000);

async function run() {
const { ApolloServer, gql } = require('apollo-server');
const { gql } = require('apollo-server');
const server = 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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,14 @@ Sentry.init({
setInterval(() => {}, 1000);

async function run() {
const { ApolloServer, gql } = require('apollo-server');
const server = 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}',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createRunner } from '../../../utils/runner';

// Graphql Instrumentation emits some spans by default on server start
const EXPECTED_START_SERVER_TRANSACTION = {
transaction: 'Test Server Start',
};

describe('GraphQL/Apollo Tests', () => {
test('CJS - should instrument GraphQL queries used from Apollo Server.', done => {
test('should instrument GraphQL queries used from Apollo Server.', done => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
Expand All @@ -18,10 +23,13 @@ describe('GraphQL/Apollo Tests', () => {
]),
};

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

test('CJS - should instrument GraphQL mutations used from Apollo Server.', done => {
test('should instrument GraphQL mutations used from Apollo Server.', done => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
Expand All @@ -39,6 +47,9 @@ describe('GraphQL/Apollo Tests', () => {
]),
};

createRunner(__dirname, 'scenario-mutation.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done);
createRunner(__dirname, 'scenario-mutation.js')
.expect({ transaction: EXPECTED_START_SERVER_TRANSACTION })
.expect({ transaction: EXPECTED_TRANSACTION })
.start(done);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

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;

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

async function run() {
const server = require('../apollo-server')();

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);
});
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

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;

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

async function run() {
const server = require('../apollo-server')();

await tracer.startActiveSpan(
'test span name',
{
kind: 1,
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
},
async span => {
for (let i = 1; i < 10; i++) {
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
await server.executeOperation({
query: `query GetHello${i} {hello}`,
});
}

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
@@ -0,0 +1,45 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

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;

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

async function run() {
const server = require('../apollo-server')();

await tracer.startActiveSpan(
'test span name',
{
kind: 1,
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
},
async span => {
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
await server.executeOperation({
query: 'query GetWorld {world}',
});

await server.executeOperation({
query: 'query GetHello {hello}',
});

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
@@ -0,0 +1,45 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

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;

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

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

await tracer.startActiveSpan(
'test span name',
{
kind: 1,
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
},
async span => {
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
await server.executeOperation({
query: gql`mutation TestMutation($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
@@ -0,0 +1,41 @@
const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

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;

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

async function run() {
const server = require('../apollo-server')();

await tracer.startActiveSpan(
'test span name',
{
kind: 1,
attributes: { 'http.method': 'GET', 'http.route': '/test-graphql' },
},
async span => {
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
await server.executeOperation({
query: 'query {hello}',
});

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

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run();
Loading
Loading