-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…13248) This introduces a new option for the `graphqlIntegration`, `useOperationNameForRootSpan`, which is by default `true` but can be disabled in integration settings like this: `Sentry.graphqlIntegration({ useOperationNameForRootSpan: true })`. With this setting enabled, the graphql instrumentation will update the `http.server` root span it is in (if there is one) will be appended to the span name. So instead of having all root spans be `POST /graphql`, the names will now be e.g. `POST /graphql (query MyQuery)`. If there are multiple operations in a single http request, they will be appended like `POST /graphql (query Query1, query Query2)`, up to a limit of 5, at which point they will be appended as `+2` or similar. Closes #13238
- Loading branch information
Showing
17 changed files
with
536 additions
and
51 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
dev-packages/node-integration-tests/suites/tracing/apollo-graphql/apollo-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...s/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-invalid-root-span.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://[email protected]/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(); |
43 changes: 43 additions & 0 deletions
43
...s/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-multiple-operations-many.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://[email protected]/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(); |
45 changes: 45 additions & 0 deletions
45
...suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-multiple-operations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://[email protected]/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(); |
45 changes: 45 additions & 0 deletions
45
...tion-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-mutation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://[email protected]/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: '[email protected]' }, | ||
}); | ||
|
||
setTimeout(() => { | ||
span.end(); | ||
server.stop(); | ||
}, 500); | ||
}, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
run(); |
41 changes: 41 additions & 0 deletions
41
...s/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-no-operation-name.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://[email protected]/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(); |
Oops, something went wrong.