-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Export tracing from @sentry/node
#7503
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2679f6c
Tracing from `@sentry/node`
timfish ac7e61c
Merge remote-tracking branch 'upstream/develop' into feat/node/tracing
timfish a056ddd
Use new API in tracing-new tests
timfish b36a357
Merge branch 'develop' into feat/node/tracing
timfish ffff5d9
couple of fixes
timfish ba72a44
Merge branch 'develop' into feat/node/tracing
timfish e8c976c
Always enable tracing for Node client
timfish 514940e
Merge branch 'feat/node/tracing' of https://github.com/timfish/sentry…
timfish d5bbfd4
lint
timfish ac21cb9
Merge branch 'develop' into feat/node/tracing
timfish 3a60e3d
no need to export addTracingExtensions from node package
timfish 8157330
Merge branch 'feat/node/tracing' of https://github.com/timfish/sentry…
timfish 80fce83
Fix prisma test
timfish 5ab0afa
Merge branch 'develop' into feat/node/tracing
timfish c0b1f1b
Merge branch 'develop' into feat/node/tracing
timfish 642ddf8
Merge branch 'develop' into feat/node/tracing
timfish c474b96
Move tracing integrations to Sentry.Integrations
timfish 6a120a8
Merge branch 'develop' into feat/node/tracing
timfish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
|
@@ -8,7 +7,7 @@ const app = express(); | |
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Sentry.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
|
43 changes: 43 additions & 0 deletions
43
packages/node-integration-tests/suites/tracing-new/apollo-graphql/scenario.ts
This file contains hidden or 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 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import { ApolloServer, gql } from 'apollo-server'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [new Sentry.Integrations.GraphQL(), new Sentry.Integrations.Apollo()], | ||
}); | ||
|
||
const typeDefs = gql` | ||
type Query { | ||
hello: String | ||
} | ||
`; | ||
|
||
const resolvers = { | ||
Query: { | ||
hello: () => { | ||
return 'Hello world!'; | ||
}, | ||
}, | ||
}; | ||
|
||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}); | ||
|
||
const transaction = Sentry.startTransaction({ name: 'test_transaction', op: 'transaction' }); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
void (async () => { | ||
// Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation | ||
await server.executeOperation({ | ||
query: '{hello}', | ||
}); | ||
|
||
transaction.finish(); | ||
})(); |
35 changes: 35 additions & 0 deletions
35
packages/node-integration-tests/suites/tracing-new/apollo-graphql/test.ts
This file contains hidden or 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,35 @@ | ||
import { assertSentryTransaction, conditionalTest, TestEnv } from '../../../utils'; | ||
|
||
// Node 10 is not supported by `graphql-js` | ||
// Ref: https://github.com/graphql/graphql-js/blob/main/package.json | ||
conditionalTest({ min: 12 })('GraphQL/Apollo Tests', () => { | ||
test('should instrument GraphQL and Apollo Server.', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
const transaction = envelope[2]; | ||
const parentSpanId = (transaction as any)?.contexts?.trace?.span_id; | ||
const graphqlSpanId = (transaction as any)?.spans?.[0].span_id; | ||
|
||
expect(parentSpanId).toBeDefined(); | ||
expect(graphqlSpanId).toBeDefined(); | ||
|
||
assertSentryTransaction(transaction, { | ||
transaction: 'test_transaction', | ||
spans: [ | ||
{ | ||
description: 'execute', | ||
op: 'graphql.execute', | ||
parent_span_id: parentSpanId, | ||
}, | ||
{ | ||
description: 'Query.hello', | ||
op: 'graphql.resolve', | ||
parent_span_id: graphqlSpanId, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/node-integration-tests/suites/tracing-new/auto-instrument/mongodb/scenario.ts
This file contains hidden or 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,46 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import { MongoClient } from 'mongodb'; | ||
|
||
// suppress logging of the mongo download | ||
global.console.log = () => null; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()], | ||
}); | ||
|
||
const client = new MongoClient(process.env.MONGO_URL || '', { | ||
useUnifiedTopology: true, | ||
}); | ||
|
||
async function run(): Promise<void> { | ||
const transaction = Sentry.startTransaction({ | ||
name: 'Test Transaction', | ||
op: 'transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
try { | ||
await client.connect(); | ||
|
||
const database = client.db('admin'); | ||
const collection = database.collection('movies'); | ||
|
||
await collection.insertOne({ title: 'Rick and Morty' }); | ||
await collection.findOne({ title: 'Back to the Future' }); | ||
await collection.updateOne({ title: 'Back to the Future' }, { $set: { title: 'South Park' } }); | ||
await collection.findOne({ title: 'South Park' }); | ||
|
||
await collection.find({ title: 'South Park' }).toArray(); | ||
} finally { | ||
if (transaction) transaction.finish(); | ||
await client.close(); | ||
} | ||
} | ||
|
||
void run(); |
85 changes: 85 additions & 0 deletions
85
packages/node-integration-tests/suites/tracing-new/auto-instrument/mongodb/test.ts
This file contains hidden or 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,85 @@ | ||
import { MongoMemoryServer } from 'mongodb-memory-server-global'; | ||
|
||
import { assertSentryTransaction, conditionalTest, TestEnv } from '../../../../utils'; | ||
|
||
// This test can take longer. | ||
jest.setTimeout(15000); | ||
|
||
conditionalTest({ min: 12 })('MongoDB Test', () => { | ||
let mongoServer: MongoMemoryServer; | ||
|
||
beforeAll(async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
process.env.MONGO_URL = mongoServer.getUri(); | ||
}, 10000); | ||
|
||
afterAll(async () => { | ||
if (mongoServer) { | ||
await mongoServer.stop(); | ||
} | ||
}); | ||
|
||
test('should auto-instrument `mongodb` package.', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ | ||
data: { | ||
collectionName: 'movies', | ||
dbName: 'admin', | ||
namespace: 'admin.movies', | ||
doc: '{"title":"Rick and Morty"}', | ||
}, | ||
description: 'insertOne', | ||
op: 'db', | ||
}, | ||
{ | ||
data: { | ||
collectionName: 'movies', | ||
dbName: 'admin', | ||
namespace: 'admin.movies', | ||
query: '{"title":"Back to the Future"}', | ||
}, | ||
description: 'findOne', | ||
op: 'db', | ||
}, | ||
{ | ||
data: { | ||
collectionName: 'movies', | ||
dbName: 'admin', | ||
namespace: 'admin.movies', | ||
filter: '{"title":"Back to the Future"}', | ||
update: '{"$set":{"title":"South Park"}}', | ||
}, | ||
description: 'updateOne', | ||
op: 'db', | ||
}, | ||
{ | ||
data: { | ||
collectionName: 'movies', | ||
dbName: 'admin', | ||
namespace: 'admin.movies', | ||
query: '{"title":"South Park"}', | ||
}, | ||
description: 'findOne', | ||
op: 'db', | ||
}, | ||
{ | ||
data: { | ||
collectionName: 'movies', | ||
dbName: 'admin', | ||
namespace: 'admin.movies', | ||
query: '{"title":"South Park"}', | ||
}, | ||
description: 'find', | ||
op: 'db', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/scenario.ts
This file contains hidden or 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,36 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import mysql from 'mysql'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()], | ||
}); | ||
|
||
const connection = mysql.createConnection({ | ||
user: 'root', | ||
password: 'docker', | ||
Check failureCode scanning / CodeQL Hard-coded credentials
The hard-coded value "docker" is used as [password](1).
|
||
}); | ||
|
||
connection.connect(function (err: unknown) { | ||
if (err) { | ||
return; | ||
} | ||
}); | ||
|
||
const transaction = Sentry.startTransaction({ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
connection.query('SELECT 1 + 1 AS solution', function () { | ||
connection.query('SELECT NOW()', ['1', '2'], () => { | ||
if (transaction) transaction.finish(); | ||
connection.end(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/test.ts
This file contains hidden or 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,23 @@ | ||
import { assertSentryTransaction, TestEnv } from '../../../../utils'; | ||
|
||
test('should auto-instrument `mysql` package.', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ | ||
description: 'SELECT 1 + 1 AS solution', | ||
op: 'db', | ||
}, | ||
|
||
{ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
}, | ||
], | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/node-integration-tests/suites/tracing-new/auto-instrument/pg/scenario.ts
This file contains hidden or 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,25 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import pg from 'pg'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()], | ||
}); | ||
|
||
const transaction = Sentry.startTransaction({ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
const client = new pg.Client(); | ||
client.query('SELECT * FROM foo where bar ilike "baz%"', ['a', 'b'], () => | ||
client.query('SELECT * FROM bazz', () => { | ||
client.query('SELECT NOW()', () => transaction.finish()); | ||
}), | ||
); |
54 changes: 54 additions & 0 deletions
54
packages/node-integration-tests/suites/tracing-new/auto-instrument/pg/test.ts
This file contains hidden or 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,54 @@ | ||
import { assertSentryTransaction, TestEnv } from '../../../../utils'; | ||
|
||
class PgClient { | ||
// https://node-postgres.com/api/client#clientquery | ||
public query(_text: unknown, values: unknown, callback?: () => void) { | ||
if (typeof callback === 'function') { | ||
callback(); | ||
return; | ||
} | ||
|
||
if (typeof values === 'function') { | ||
values(); | ||
return; | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
beforeAll(() => { | ||
jest.mock('pg', () => { | ||
return { | ||
Client: PgClient, | ||
native: { | ||
Client: PgClient, | ||
}, | ||
}; | ||
}); | ||
}); | ||
|
||
test('should auto-instrument `pg` package.', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const envelope = await env.getEnvelopeRequest({ envelopeType: 'transaction' }); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ | ||
description: 'SELECT * FROM foo where bar ilike "baz%"', | ||
op: 'db', | ||
}, | ||
{ | ||
description: 'SELECT * FROM bazz', | ||
op: 'db', | ||
}, | ||
{ | ||
description: 'SELECT NOW()', | ||
op: 'db', | ||
}, | ||
], | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Hard-coded credentials