-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Add tedious
integration
#13486
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
AbhiPrasad
merged 12 commits into
getsentry:develop
from
Zen-cronic:feat/tediousIntegration-node
Nov 7, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
56f6756
feat(node): Add tedious instrumentation as a node integration
Zen-cronic b57701f
test(node): Update test for tedious integration
Zen-cronic fdf570c
chore(node): Update tedious package to latest
Zen-cronic f5ea992
fix(node): Change dependencies versions for compatibility
Zen-cronic 5e5fddc
fix(node): Fix formatting
Zen-cronic 8322347
fix(e2e): Update exports for node-exports-test-app
Zen-cronic cd5a664
chore(node): Add exports in more sdk packages
Zen-cronic 6ed801c
chore(e2e): Bump `tedious` version to support latest node versions
Zen-cronic a1ef4a2
Merge branch 'develop' into feat/tediousIntegration-node
AbhiPrasad 40ea319
ref: Re-organize span-start hook
AbhiPrasad 0e7eb18
only run in Node 18+
AbhiPrasad 084a1b7
Merge branch 'develop' into feat/tediousIntegration-node
AbhiPrasad 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
12 changes: 12 additions & 0 deletions
12
dev-packages/node-integration-tests/suites/tracing/tedious/docker-compose.yml
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,12 @@ | ||
version: '3.9' | ||
|
||
services: | ||
db: | ||
image: mcr.microsoft.com/mssql/server:2022-latest | ||
restart: always | ||
container_name: integration-tests-tedious | ||
ports: | ||
- '1433:1433' | ||
environment: | ||
ACCEPT_EULA: 'Y' | ||
MSSQL_SA_PASSWORD: 'TESTing123' | ||
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. Password must pass this criteria. |
65 changes: 65 additions & 0 deletions
65
dev-packages/node-integration-tests/suites/tracing/tedious/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,65 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
const { Connection, Request } = require('tedious'); | ||
|
||
const config = { | ||
server: '127.0.0.1', | ||
authentication: { | ||
type: 'default', | ||
options: { | ||
userName: 'sa', | ||
password: 'TESTing123', | ||
}, | ||
}, | ||
options: { | ||
port: 1433, | ||
encrypt: false, | ||
}, | ||
}; | ||
|
||
const connection = new Connection(config); | ||
|
||
function executeAllStatements(span) { | ||
executeStatement('SELECT 1 + 1 AS solution', () => { | ||
executeStatement('SELECT GETDATE()', () => { | ||
span.end(); | ||
connection.close(); | ||
}); | ||
}); | ||
} | ||
|
||
function executeStatement(query, callback) { | ||
const request = new Request(query, err => { | ||
if (err) { | ||
throw err; | ||
} | ||
callback(); | ||
}); | ||
|
||
connection.execSql(request); | ||
} | ||
|
||
connection.connect(err => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
Sentry.startSpanManual( | ||
{ | ||
op: 'transaction', | ||
name: 'Test Transaction', | ||
}, | ||
span => { | ||
// span must be ended manually after all queries | ||
executeAllStatements(span); | ||
}, | ||
); | ||
}); |
53 changes: 53 additions & 0 deletions
53
dev-packages/node-integration-tests/suites/tracing/tedious/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,53 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
jest.setTimeout(75000); | ||
|
||
// Tedious version we are testing against only supports Node 18+ | ||
// https://github.com/tediousjs/tedious/blob/8310c455a2cc1cba83c1ca3c16677da4f83e12a9/package.json#L38 | ||
conditionalTest({ min: 18 })('tedious auto instrumentation', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should auto-instrument `tedious` package', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Transaction', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
description: 'SELECT GETDATE()', | ||
data: expect.objectContaining({ | ||
'sentry.origin': 'auto.db.otel.tedious', | ||
'sentry.op': 'db', | ||
'db.name': 'master', | ||
'db.statement': 'SELECT GETDATE()', | ||
'db.system': 'mssql', | ||
'db.user': 'sa', | ||
'net.peer.name': '127.0.0.1', | ||
'net.peer.port': 1433, | ||
}), | ||
status: 'ok', | ||
}), | ||
expect.objectContaining({ | ||
description: 'SELECT 1 + 1 AS solution', | ||
data: expect.objectContaining({ | ||
'sentry.origin': 'auto.db.otel.tedious', | ||
'sentry.op': 'db', | ||
'db.name': 'master', | ||
'db.statement': 'SELECT 1 + 1 AS solution', | ||
'db.system': 'mssql', | ||
'db.user': 'sa', | ||
'net.peer.name': '127.0.0.1', | ||
'net.peer.port': 1433, | ||
}), | ||
status: 'ok', | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario.js') | ||
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['1433'] }) | ||
.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
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,48 @@ | ||
import { TediousInstrumentation } from '@opentelemetry/instrumentation-tedious'; | ||
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core'; | ||
import type { IntegrationFn } from '@sentry/types'; | ||
import { generateInstrumentOnce } from '../../otel/instrument'; | ||
|
||
const TEDIUS_INSTRUMENTED_METHODS = new Set([ | ||
'callProcedure', | ||
'execSql', | ||
'execSqlBatch', | ||
'execBulkLoad', | ||
'prepare', | ||
'execute', | ||
]); | ||
|
||
const INTEGRATION_NAME = 'Tedious'; | ||
|
||
export const instrumentTedious = generateInstrumentOnce(INTEGRATION_NAME, () => new TediousInstrumentation({})); | ||
|
||
const _tediousIntegration = (() => { | ||
return { | ||
name: INTEGRATION_NAME, | ||
setupOnce() { | ||
instrumentTedious(); | ||
}, | ||
|
||
setup(client) { | ||
client.on('spanStart', span => { | ||
const { description, data } = spanToJSON(span); | ||
// Tedius integration always set a span name and `db.system` attribute to `mssql`. | ||
if (!description || data?.['db.system'] !== 'mssql') { | ||
return; | ||
} | ||
|
||
const operation = description?.split(' ')[0] || ''; | ||
if (TEDIUS_INSTRUMENTED_METHODS.has(operation)) { | ||
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious'); | ||
} | ||
}); | ||
}, | ||
}; | ||
}) satisfies IntegrationFn; | ||
|
||
/** | ||
* Tedious integration | ||
* | ||
* Capture tracing data for tedious. | ||
*/ | ||
export const tediousIntegration = defineIntegration(_tediousIntegration); |
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
Oops, something went wrong.
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.