-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Add generic-pool
integration
#13465
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
lforst
merged 7 commits into
getsentry:develop
from
Zen-cronic:feat/genericPoolIntegration
Sep 3, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aaae010
feat(node): Add genericPool integration using opentelemetry instrumen…
Zen-cronic 4d7ddbf
test(node): Add tests for genericPoolIntegration
Zen-cronic 017c7d2
chore(node): Update dependencies version
Zen-cronic c7aac54
Update span description after fixing typo for backwards compatibility
Zen-cronic 17dc1ad
fix(node): Fix formatting
Zen-cronic 66ae4b8
fix(e2e): Update exports for node-exports-test-app
Zen-cronic 1450f3c
chore(node): Add exports in more sdk packages
Zen-cronic 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
71 changes: 71 additions & 0 deletions
71
dev-packages/node-integration-tests/suites/tracing/genericPool/scenario.js
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,71 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const mysql = require('mysql'); | ||
const genericPool = require('generic-pool'); | ||
|
||
const factory = { | ||
create: function () { | ||
return mysql.createConnection({ | ||
user: 'root', | ||
|
||
password: 'docker', | ||
|
||
}); | ||
}, | ||
destroy: function (client) { | ||
client.end(err => { | ||
if (err) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error while disconnecting MySQL:', err); | ||
} | ||
}); | ||
}, | ||
}; | ||
|
||
const opts = { | ||
max: 10, | ||
min: 2, | ||
}; | ||
|
||
const myPool = genericPool.createPool(factory, opts); | ||
|
||
async function run() { | ||
await Sentry.startSpan( | ||
{ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}, | ||
async () => { | ||
try { | ||
const client1 = await myPool.acquire(); | ||
const client2 = await myPool.acquire(); | ||
|
||
client1.query('SELECT NOW()', function () { | ||
myPool.release(client1); | ||
}); | ||
|
||
client2.query('SELECT 1 + 1 AS solution', function () { | ||
myPool.release(client2); | ||
}); | ||
} catch (err) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error while pooling MySQL:', err); | ||
} finally { | ||
await myPool.drain(); | ||
await myPool.clear(); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
run(); |
34 changes: 34 additions & 0 deletions
34
dev-packages/node-integration-tests/suites/tracing/genericPool/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,34 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('genericPool auto instrumentation', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should auto-instrument `genericPool` package when calling pool.require()', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Transaction', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
description: expect.stringMatching(/^generic-pool\.ac?quire/), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lowkey lol @ the |
||
origin: 'auto.db.otel.generic-pool', | ||
data: { | ||
'sentry.origin': 'auto.db.otel.generic-pool', | ||
}, | ||
status: 'ok', | ||
}), | ||
|
||
expect.objectContaining({ | ||
description: expect.stringMatching(/^generic-pool\.ac?quire/), | ||
origin: 'auto.db.otel.generic-pool', | ||
data: { | ||
'sentry.origin': 'auto.db.otel.generic-pool', | ||
}, | ||
status: 'ok', | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario.js').expect({ transaction: EXPECTED_TRANSACTION }).start(done); | ||
}); | ||
}); |
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
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
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
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,40 @@ | ||
import { GenericPoolInstrumentation } from '@opentelemetry/instrumentation-generic-pool'; | ||
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core'; | ||
import type { IntegrationFn } from '@sentry/types'; | ||
import { generateInstrumentOnce } from '../../otel/instrument'; | ||
|
||
const INTEGRATION_NAME = 'GenericPool'; | ||
|
||
export const instrumentGenericPool = generateInstrumentOnce(INTEGRATION_NAME, () => new GenericPoolInstrumentation({})); | ||
|
||
const _genericPoolIntegration = (() => { | ||
return { | ||
name: INTEGRATION_NAME, | ||
setupOnce() { | ||
instrumentGenericPool(); | ||
}, | ||
|
||
setup(client) { | ||
client.on('spanStart', span => { | ||
const spanJSON = spanToJSON(span); | ||
|
||
const spanDescription = spanJSON.description; | ||
|
||
// typo in emitted span for version <= 0.38.0 of @opentelemetry/instrumentation-generic-pool | ||
const isGenericPoolSpan = | ||
spanDescription === 'generic-pool.aquire' || spanDescription === 'generic-pool.acquire'; | ||
|
||
if (isGenericPoolSpan) { | ||
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.generic-pool'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs, trace origin name cannot contain "-". |
||
} | ||
}); | ||
}, | ||
}; | ||
}) satisfies IntegrationFn; | ||
|
||
/** | ||
* GenericPool integration | ||
* | ||
* Capture tracing data for GenericPool. | ||
*/ | ||
export const genericPoolIntegration = defineIntegration(_genericPoolIntegration); |
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
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
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 |
---|---|---|
|
@@ -7113,6 +7113,13 @@ | |
"@opentelemetry/core" "^1.8.0" | ||
"@opentelemetry/instrumentation" "^0.52.0" | ||
|
||
"@opentelemetry/[email protected]": | ||
version "0.38.0" | ||
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation-generic-pool/-/instrumentation-generic-pool-0.38.0.tgz#9ea4d82da23541cda613d553bd405b2cbc0da184" | ||
integrity sha512-0/ULi6pIco1fEnDPmmAul8ZoudFL7St0hjgBbWZlZPBCSyslDll1J7DFeEbjiRSSyUd+0tu73ae0DOKVKNd7VA== | ||
dependencies: | ||
"@opentelemetry/instrumentation" "^0.52.0" | ||
|
||
"@opentelemetry/[email protected]": | ||
version "0.42.0" | ||
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation-graphql/-/instrumentation-graphql-0.42.0.tgz#588a18c39e3b3f655bc09243566172ab0b638d35" | ||
|
@@ -19166,7 +19173,7 @@ generate-function@^2.3.1: | |
dependencies: | ||
is-property "^1.0.2" | ||
|
||
[email protected]: | ||
[email protected], generic-pool@^3.9.0: | ||
version "3.9.0" | ||
resolved "https://registry.yarnpkg.com/generic-pool/-/generic-pool-3.9.0.tgz#36f4a678e963f4fdb8707eab050823abc4e8f5e4" | ||
integrity sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g== | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.