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 tedious integration #13486

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"redis-4": "npm:redis@^4.6.14",
"reflect-metadata": "0.2.1",
"rxjs": "^7.8.1",
"tedious": "^18.6.1",
Zen-cronic marked this conversation as resolved.
Show resolved Hide resolved
"yargs": "^16.2.0"
},
"devDependencies": {
Expand Down
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'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Password must pass this criteria.

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);
},
);
});
50 changes: 50 additions & 0 deletions dev-packages/node-integration-tests/suites/tracing/tedious/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

jest.setTimeout(75000);

describe('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);
});
});
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export {
startSession,
startSpan,
startSpanManual,
tediousIntegration,
trpcMiddleware,
withActiveSpan,
withIsolationScope,
Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export {
mysqlIntegration,
mysql2Integration,
redisIntegration,
tediousIntegration,
nestIntegration,
setupNestErrorHandler,
postgresIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export {
mysqlIntegration,
mysql2Integration,
redisIntegration,
tediousIntegration,
nestIntegration,
setupNestErrorHandler,
postgresIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export {
mysqlIntegration,
mysql2Integration,
redisIntegration,
tediousIntegration,
nestIntegration,
setupNestErrorHandler,
postgresIntegration,
Expand Down
1 change: 1 addition & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@opentelemetry/instrumentation-nestjs-core": "0.39.0",
"@opentelemetry/instrumentation-pg": "0.43.0",
"@opentelemetry/instrumentation-redis-4": "0.41.0",
"@opentelemetry/instrumentation-tedious": "0.13.0",
"@opentelemetry/resources": "^1.25.1",
"@opentelemetry/sdk-trace-base": "^1.25.1",
"@opentelemetry/semantic-conventions": "^1.25.1",
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export { hapiIntegration, setupHapiErrorHandler } from './integrations/tracing/h
export { koaIntegration, setupKoaErrorHandler } from './integrations/tracing/koa';
export { connectIntegration, setupConnectErrorHandler } from './integrations/tracing/connect';
export { spotlightIntegration } from './integrations/spotlight';
export { tediousIntegration } from './integrations/tracing/tedious';

export { SentryContextManager } from './otel/contextManager';
export { generateInstrumentOnce } from './otel/instrument';
Expand Down
3 changes: 3 additions & 0 deletions packages/node/src/integrations/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { instrumentMysql2, mysql2Integration } from './mysql2';
import { instrumentNest, nestIntegration } from './nest/nest';
import { instrumentPostgres, postgresIntegration } from './postgres';
import { instrumentRedis, redisIntegration } from './redis';
import { instrumentTedious, tediousIntegration } from './tedious';

/**
* With OTEL, all performance integrations will be added, as OTEL only initializes them when the patched package is actually required.
Expand All @@ -37,6 +38,7 @@ export function getAutoPerformanceIntegrations(): Integration[] {
hapiIntegration(),
koaIntegration(),
connectIntegration(),
tediousIntegration(),
];
}

Expand All @@ -61,5 +63,6 @@ export function getOpenTelemetryInstrumentationToPreload(): (((options?: any) =>
instrumentHapi,
instrumentGraphql,
instrumentRedis,
instrumentTedious,
];
}
38 changes: 38 additions & 0 deletions packages/node/src/integrations/tracing/tedious.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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 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 spanJSON = spanToJSON(span);

const spanMethods = ['callProcedure', 'execSql', 'execSqlBatch', 'execBulkLoad', 'prepare', 'execute'];

const spanDescription = spanJSON?.description;

if (spanMethods.some(method => spanDescription?.startsWith(method))) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.tedious');
}
});
},
};
}) satisfies IntegrationFn;

/**
* Tedious integration
*
* Capture tracing data for tedious.
*/
export const tediousIntegration = defineIntegration(_tediousIntegration);
1 change: 1 addition & 0 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export {
startSession,
startSpan,
startSpanManual,
tediousIntegration,
trpcMiddleware,
withActiveSpan,
withIsolationScope,
Expand Down
1 change: 1 addition & 0 deletions packages/solidstart/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export {
startSession,
startSpan,
startSpanManual,
tediousIntegration,
trpcMiddleware,
withActiveSpan,
withIsolationScope,
Expand Down
1 change: 1 addition & 0 deletions packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export {
startSession,
startSpan,
startSpanManual,
tediousIntegration,
trpcMiddleware,
withActiveSpan,
withIsolationScope,
Expand Down
Loading